summaryrefslogtreecommitdiff
path: root/base/LinkedList.vapor
blob: bebdf94aea48bc88f91cf6a2950d022bf98318a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505

const vmt_Element
  :Element.Init
  :Element.GetAge
  :Element.GetSalary
  :Element.GetMarried
  :Element.Equal
  :Element.Compare

const vmt_List
  :List.Init
  :List.InitNew
  :List.Insert
  :List.SetNext
  :List.Delete
  :List.Search
  :List.GetEnd
  :List.GetElem
  :List.GetNext
  :List.Print

const vmt_LL
  :LL.Start


func Main()
  t.0 = HeapAllocZ(4)
  [t.0] = :vmt_LL
  if t.0 goto :null1
    Error("null pointer")
  null1:
  t.1 = [t.0]
  t.1 = [t.1+0]
  t.2 = call t.1(t.0)
  PrintIntS(t.2)
  ret

func Element.Init(this v_Age v_Salary v_Married)
  [this+4] = v_Age
  [this+8] = v_Salary
  [this+12] = v_Married
  ret 1

func Element.GetAge(this)
  t.0 = [this+4]
  ret t.0

func Element.GetSalary(this)
  t.0 = [this+8]
  ret t.0

func Element.GetMarried(this)
  t.0 = [this+12]
  ret t.0

func Element.Equal(this other)
  ret_val = 1
  if other goto :null2
    Error("null pointer")
  null2:
  t.0 = [other]
  t.0 = [t.0+4]
  aux01 = call t.0(other)
  t.1 = [this]
  t.1 = [t.1+20]
  t.2 = [this+4]
  t.3 = call t.1(this aux01 t.2)
  t.4 = Sub(1 t.3)
  if0 t.4 goto :if1_else
    ret_val = 0
    goto :if1_end
  if1_else:
    if other goto :null3
      Error("null pointer")
    null3:
    t.5 = [other]
    t.5 = [t.5+8]
    aux02 = call t.5(other)
    t.6 = [this]
    t.6 = [t.6+20]
    t.7 = [this+8]
    t.8 = call t.6(this aux02 t.7)
    t.9 = Sub(1 t.8)
    if0 t.9 goto :if2_else
      ret_val = 0
      goto :if2_end
    if2_else:
      t.10 = [this+12]
      if0 t.10 goto :if3_else
        if other goto :null4
          Error("null pointer")
        null4:
        t.11 = [other]
        t.11 = [t.11+12]
        t.12 = call t.11(other)
        t.13 = Sub(1 t.12)
        if0 t.13 goto :if4_else
          ret_val = 0
          goto :if4_end
        if4_else:
          nt = 0
        if4_end:
        goto :if3_end
      if3_else:
        if other goto :null5
          Error("null pointer")
        null5:
        t.14 = [other]
        t.14 = [t.14+12]
        t.15 = call t.14(other)
        if0 t.15 goto :if5_else
          ret_val = 0
          goto :if5_end
        if5_else:
          nt = 0
        if5_end:
      if3_end:
    if2_end:
  if1_end:
  ret ret_val

func Element.Compare(this num1 num2)
  retval = 0
  aux02 = Add(num2 1)
  t.0 = LtS(num1 num2)
  if0 t.0 goto :if6_else
    retval = 0
    goto :if6_end
  if6_else:
    t.1 = LtS(num1 aux02)
    t.2 = Sub(1 t.1)
    if0 t.2 goto :if7_else
      retval = 0
      goto :if7_end
    if7_else:
      retval = 1
    if7_end:
  if6_end:
  ret retval

func List.Init(this)
  [this+12] = 1
  ret 1

func List.InitNew(this v_elem v_next v_end)
  [this+12] = v_end
  [this+4] = v_elem
  [this+8] = v_next
  ret 1

func List.Insert(this new_elem)
  aux03 = this
  t.0 = HeapAllocZ(16)
  [t.0] = :vmt_List
  aux02 = t.0
  if aux02 goto :null6
    Error("null pointer")
  null6:
  t.1 = [aux02]
  t.1 = [t.1+4]
  ret_val = call t.1(aux02 new_elem aux03 0)
  ret aux02

func List.SetNext(this v_next)
  [this+8] = v_next
  ret 1

func List.Delete(this e)
  my_head = this
  ret_val = 0
  aux04 = Sub(0 1)
  aux01 = this
  prev = this
  var_end = [this+12]
  var_elem = [this+4]
  while1_top:
  t.1 = Sub(1 var_end)
  if0 t.1 goto :ss1_else
    t.0 = Sub(1 ret_val)
    goto :ss1_end
  ss1_else:
    t.0 = 0
  ss1_end:
  if0 t.0 goto :while1_end
    if e goto :null7
      Error("null pointer")
    null7:
    t.2 = [e]
    t.2 = [t.2+16]
    t.3 = call t.2(e var_elem)
    if0 t.3 goto :if8_else
      ret_val = 1
      t.4 = LtS(aux04 0)
      if0 t.4 goto :if9_else
        if aux01 goto :null8
          Error("null pointer")
        null8:
        t.5 = [aux01]
        t.5 = [t.5+32]
        my_head = call t.5(aux01)
        goto :if9_end
      if9_else:
        t.6 = Sub(0 555)
        PrintIntS(t.6)
        if prev goto :null9
          Error("null pointer")
        null9:
        t.7 = [prev]
        t.7 = [t.7+12]
        if aux01 goto :null10
          Error("null pointer")
        null10:
        t.8 = [aux01]
        t.8 = [t.8+32]
        t.9 = call t.8(aux01)
        aux05 = call t.7(prev t.9)
        t.10 = Sub(0 555)
        PrintIntS(t.10)
      if9_end:
      goto :if8_end
    if8_else:
      nt = 0
    if8_end:
    t.11 = Sub(1 ret_val)
    if0 t.11 goto :if10_else
      prev = aux01
      if aux01 goto :null11
        Error("null pointer")
      null11:
      t.12 = [aux01]
      t.12 = [t.12+32]
      aux01 = call t.12(aux01)
      if aux01 goto :null12
        Error("null pointer")
      null12:
      t.13 = [aux01]
      t.13 = [t.13+24]
      var_end = call t.13(aux01)
      if aux01 goto :null13
        Error("null pointer")
      null13:
      t.14 = [aux01]
      t.14 = [t.14+28]
      var_elem = call t.14(aux01)
      aux04 = 1
      goto :if10_end
    if10_else:
      nt = 0
    if10_end:
    goto :while1_top
  while1_end:
  ret my_head

func List.Search(this e)
  int_ret_val = 0
  aux01 = this
  var_end = [this+12]
  var_elem = [this+4]
  while2_top:
  t.0 = Sub(1 var_end)
  if0 t.0 goto :while2_end
    if e goto :null14
      Error("null pointer")
    null14:
    t.1 = [e]
    t.1 = [t.1+16]
    t.2 = call t.1(e var_elem)
    if0 t.2 goto :if11_else
      int_ret_val = 1
      goto :if11_end
    if11_else:
      nt = 0
    if11_end:
    if aux01 goto :null15
      Error("null pointer")
    null15:
    t.3 = [aux01]
    t.3 = [t.3+32]
    aux01 = call t.3(aux01)
    if aux01 goto :null16
      Error("null pointer")
    null16:
    t.4 = [aux01]
    t.4 = [t.4+24]
    var_end = call t.4(aux01)
    if aux01 goto :null17
      Error("null pointer")
    null17:
    t.5 = [aux01]
    t.5 = [t.5+28]
    var_elem = call t.5(aux01)
    goto :while2_top
  while2_end:
  ret int_ret_val

func List.GetEnd(this)
  t.0 = [this+12]
  ret t.0

func List.GetElem(this)
  t.0 = [this+4]
  ret t.0

func List.GetNext(this)
  t.0 = [this+8]
  ret t.0

func List.Print(this)
  aux01 = this
  var_end = [this+12]
  var_elem = [this+4]
  while3_top:
  t.0 = Sub(1 var_end)
  if0 t.0 goto :while3_end
    if var_elem goto :null18
      Error("null pointer")
    null18:
    t.1 = [var_elem]
    t.1 = [t.1+4]
    t.2 = call t.1(var_elem)
    PrintIntS(t.2)
    if aux01 goto :null19
      Error("null pointer")
    null19:
    t.3 = [aux01]
    t.3 = [t.3+32]
    aux01 = call t.3(aux01)
    if aux01 goto :null20
      Error("null pointer")
    null20:
    t.4 = [aux01]
    t.4 = [t.4+24]
    var_end = call t.4(aux01)
    if aux01 goto :null21
      Error("null pointer")
    null21:
    t.5 = [aux01]
    t.5 = [t.5+28]
    var_elem = call t.5(aux01)
    goto :while3_top
  while3_end:
  ret 1

func LL.Start(this)
  t.0 = HeapAllocZ(16)
  [t.0] = :vmt_List
  last_elem = t.0
  if last_elem goto :null22
    Error("null pointer")
  null22:
  t.1 = [last_elem]
  t.1 = [t.1+0]
  aux01 = call t.1(last_elem)
  head = last_elem
  if head goto :null23
    Error("null pointer")
  null23:
  t.2 = [head]
  t.2 = [t.2+0]
  aux01 = call t.2(head)
  if head goto :null24
    Error("null pointer")
  null24:
  t.3 = [head]
  t.3 = [t.3+36]
  aux01 = call t.3(head)
  t.4 = HeapAllocZ(16)
  [t.4] = :vmt_Element
  el01 = t.4
  if el01 goto :null25
    Error("null pointer")
  null25:
  t.5 = [el01]
  t.5 = [t.5+0]
  aux01 = call t.5(el01 25 37000 0)
  if head goto :null26
    Error("null pointer")
  null26:
  t.6 = [head]
  t.6 = [t.6+8]
  head = call t.6(head el01)
  if head goto :null27
    Error("null pointer")
  null27:
  t.7 = [head]
  t.7 = [t.7+36]
  aux01 = call t.7(head)
  PrintIntS(10000000)
  t.8 = HeapAllocZ(16)
  [t.8] = :vmt_Element
  el01 = t.8
  if el01 goto :null28
    Error("null pointer")
  null28:
  t.9 = [el01]
  t.9 = [t.9+0]
  aux01 = call t.9(el01 39 42000 1)
  el02 = el01
  if head goto :null29
    Error("null pointer")
  null29:
  t.10 = [head]
  t.10 = [t.10+8]
  head = call t.10(head el01)
  if head goto :null30
    Error("null pointer")
  null30:
  t.11 = [head]
  t.11 = [t.11+36]
  aux01 = call t.11(head)
  PrintIntS(10000000)
  t.12 = HeapAllocZ(16)
  [t.12] = :vmt_Element
  el01 = t.12
  if el01 goto :null31
    Error("null pointer")
  null31:
  t.13 = [el01]
  t.13 = [t.13+0]
  aux01 = call t.13(el01 22 34000 0)
  if head goto :null32
    Error("null pointer")
  null32:
  t.14 = [head]
  t.14 = [t.14+8]
  head = call t.14(head el01)
  if head goto :null33
    Error("null pointer")
  null33:
  t.15 = [head]
  t.15 = [t.15+36]
  aux01 = call t.15(head)
  t.16 = HeapAllocZ(16)
  [t.16] = :vmt_Element
  el03 = t.16
  if el03 goto :null34
    Error("null pointer")
  null34:
  t.17 = [el03]
  t.17 = [t.17+0]
  aux01 = call t.17(el03 27 34000 0)
  if head goto :null35
    Error("null pointer")
  null35:
  t.18 = [head]
  t.18 = [t.18+20]
  t.19 = call t.18(head el02)
  PrintIntS(t.19)
  if head goto :null36
    Error("null pointer")
  null36:
  t.20 = [head]
  t.20 = [t.20+20]
  t.21 = call t.20(head el03)
  PrintIntS(t.21)
  PrintIntS(10000000)
  t.22 = HeapAllocZ(16)
  [t.22] = :vmt_Element
  el01 = t.22
  if el01 goto :null37
    Error("null pointer")
  null37:
  t.23 = [el01]
  t.23 = [t.23+0]
  aux01 = call t.23(el01 28 35000 0)
  if head goto :null38
    Error("null pointer")
  null38:
  t.24 = [head]
  t.24 = [t.24+8]
  head = call t.24(head el01)
  if head goto :null39
    Error("null pointer")
  null39:
  t.25 = [head]
  t.25 = [t.25+36]
  aux01 = call t.25(head)
  PrintIntS(2220000)
  if head goto :null40
    Error("null pointer")
  null40:
  t.26 = [head]
  t.26 = [t.26+16]
  head = call t.26(head el02)
  if head goto :null41
    Error("null pointer")
  null41:
  t.27 = [head]
  t.27 = [t.27+36]
  aux01 = call t.27(head)
  PrintIntS(33300000)
  if head goto :null42
    Error("null pointer")
  null42:
  t.28 = [head]
  t.28 = [t.28+16]
  head = call t.28(head el01)
  if head goto :null43
    Error("null pointer")
  null43:
  t.29 = [head]
  t.29 = [t.29+36]
  aux01 = call t.29(head)
  PrintIntS(44440000)
  ret 0