summaryrefslogtreecommitdiff
path: root/base/BubbleSort.vaporm
blob: f64e2b3c0405e8ddb7e1543589fa8a8b43f5cb1c (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
const vmt_BBS
  :BBS.Start
  :BBS.Sort
  :BBS.Print
  :BBS.Init

func Main [in 0, out 0, local 0]
  $t0 = HeapAllocZ(12)
  [$t0] = :vmt_BBS
  if $t0 goto :null1
  Error("null pointer")
null1:
  $t1 = [$t0]
  $t1 = [$t1]
  $a0 = $t0
  $a1 = 10
  call $t1
  $t1 = $v0
  PrintIntS($t1)
  ret

func BBS.Start [in 0, out 0, local 1]
  local[0] = $s0
  $s0 = $a0
  $t0 = $a1
  $t1 = [$s0]
  $t1 = [$t1+12]
  $a0 = $s0
  $a1 = $t0
  call $t1
  $t1 = [$s0]
  $t1 = [$t1+8]
  $a0 = $s0
  call $t1
  PrintIntS(99999)
  $t1 = [$s0]
  $t1 = [$t1+4]
  $a0 = $s0
  call $t1
  $t1 = [$s0]
  $t1 = [$t1+8]
  $a0 = $s0
  call $t1
  $v0 = 0
  $s0 = local[0]
  ret

func BBS.Sort [in 0, out 0, local 0]
  $t0 = $a0
  $t1 = [$t0+8]
  $t1 = Sub($t1 1)
  $t2 = Sub(0 1)
while1_top:
  $t3 = LtS($t2 $t1)
  if0 $t3 goto :while1_end
  $t3 = 1
while2_top:
  $t4 = Add($t1 1)
  $t4 = LtS($t3 $t4)
  if0 $t4 goto :while2_end
  $t4 = Sub($t3 1)
  $t5 = [$t0+4]
  if $t5 goto :null2
  Error("null pointer")
null2:
  $t6 = [$t5]
  $t6 = Lt($t4 $t6)
  if $t6 goto :bounds1
  Error("array index out of bounds")
bounds1:
  $t6 = MulS($t4 4)
  $t6 = Add($t6 $t5)
  $t6 = [$t6+4]
  $t5 = [$t0+4]
  if $t5 goto :null3
  Error("null pointer")
null3:
  $t4 = [$t5]
  $t4 = Lt($t3 $t4)
  if $t4 goto :bounds2
  Error("array index out of bounds")
bounds2:
  $t4 = MulS($t3 4)
  $t4 = Add($t4 $t5)
  $t4 = [$t4+4]
  $t4 = LtS($t4 $t6)
  if0 $t4 goto :if1_else
  $t4 = Sub($t3 1)
  $t6 = [$t0+4]
  if $t6 goto :null4
  Error("null pointer")
null4:
  $t5 = [$t6]
  $t5 = Lt($t4 $t5)
  if $t5 goto :bounds3
  Error("array index out of bounds")
bounds3:
  $t5 = MulS($t4 4)
  $t5 = Add($t5 $t6)
  $t5 = [$t5+4]
  $t6 = [$t0+4]
  if $t6 goto :null5
  Error("null pointer")
null5:
  $t7 = [$t6]
  $t7 = Lt($t4 $t7)
  if $t7 goto :bounds4
  Error("array index out of bounds")
bounds4:
  $t7 = MulS($t4 4)
  $t7 = Add($t7 $t6)
  $t6 = [$t0+4]
  if $t6 goto :null6
  Error("null pointer")
null6:
  $t4 = [$t6]
  $t4 = Lt($t3 $t4)
  if $t4 goto :bounds5
  Error("array index out of bounds")
bounds5:
  $t4 = MulS($t3 4)
  $t4 = Add($t4 $t6)
  $t4 = [$t4+4]
  [$t7+4] = $t4
  $t4 = [$t0+4]
  if $t4 goto :null7
  Error("null pointer")
null7:
  $t7 = [$t4]
  $t7 = Lt($t3 $t7)
  if $t7 goto :bounds6
  Error("array index out of bounds")
bounds6:
  $t7 = MulS($t3 4)
  $t7 = Add($t7 $t4)
  [$t7+4] = $t5
  goto :if1_end
if1_else:
if1_end:
  $t3 = Add($t3 1)
  goto :while2_top
while2_end:
  $t1 = Sub($t1 1)
  goto :while1_top
while1_end:
  $v0 = 0
  ret

func BBS.Print [in 0, out 0, local 0]
  $t0 = $a0
  $t1 = 0
while3_top:
  $t2 = [$t0+8]
  $t2 = LtS($t1 $t2)
  if0 $t2 goto :while3_end
  $t2 = [$t0+4]
  if $t2 goto :null8
  Error("null pointer")
null8:
  $t3 = [$t2]
  $t3 = Lt($t1 $t3)
  if $t3 goto :bounds7
  Error("array index out of bounds")
bounds7:
  $t3 = MulS($t1 4)
  $t3 = Add($t3 $t2)
  $t3 = [$t3+4]
  PrintIntS($t3)
  $t1 = Add($t1 1)
  goto :while3_top
while3_end:
  $v0 = 0
  ret

func BBS.Init [in 0, out 0, local 1]
  local[0] = $s0
  $s0 = $a0
  $t0 = $a1
  [$s0+8] = $t0
  $a0 = $t0
  call :AllocArray
  $t0 = $v0
  [$s0+4] = $t0
  $t0 = [$s0+4]
  if $t0 goto :null9
  Error("null pointer")
null9:
  $t1 = [$t0]
  $t1 = Lt(0 $t1)
  if $t1 goto :bounds8
  Error("array index out of bounds")
bounds8:
  $t1 = MulS(0 4)
  $t1 = Add($t1 $t0)
  [$t1+4] = 20
  $t1 = [$s0+4]
  if $t1 goto :null10
  Error("null pointer")
null10:
  $t0 = [$t1]
  $t0 = Lt(1 $t0)
  if $t0 goto :bounds9
  Error("array index out of bounds")
bounds9:
  $t0 = MulS(1 4)
  $t0 = Add($t0 $t1)
  [$t0+4] = 7
  $t0 = [$s0+4]
  if $t0 goto :null11
  Error("null pointer")
null11:
  $t1 = [$t0]
  $t1 = Lt(2 $t1)
  if $t1 goto :bounds10
  Error("array index out of bounds")
bounds10:
  $t1 = MulS(2 4)
  $t1 = Add($t1 $t0)
  [$t1+4] = 12
  $t1 = [$s0+4]
  if $t1 goto :null12
  Error("null pointer")
null12:
  $t0 = [$t1]
  $t0 = Lt(3 $t0)
  if $t0 goto :bounds11
  Error("array index out of bounds")
bounds11:
  $t0 = MulS(3 4)
  $t0 = Add($t0 $t1)
  [$t0+4] = 18
  $t0 = [$s0+4]
  if $t0 goto :null13
  Error("null pointer")
null13:
  $t1 = [$t0]
  $t1 = Lt(4 $t1)
  if $t1 goto :bounds12
  Error("array index out of bounds")
bounds12:
  $t1 = MulS(4 4)
  $t1 = Add($t1 $t0)
  [$t1+4] = 2
  $t1 = [$s0+4]
  if $t1 goto :null14
  Error("null pointer")
null14:
  $t0 = [$t1]
  $t0 = Lt(5 $t0)
  if $t0 goto :bounds13
  Error("array index out of bounds")
bounds13:
  $t0 = MulS(5 4)
  $t0 = Add($t0 $t1)
  [$t0+4] = 11
  $t0 = [$s0+4]
  if $t0 goto :null15
  Error("null pointer")
null15:
  $t1 = [$t0]
  $t1 = Lt(6 $t1)
  if $t1 goto :bounds14
  Error("array index out of bounds")
bounds14:
  $t1 = MulS(6 4)
  $t1 = Add($t1 $t0)
  [$t1+4] = 6
  $t1 = [$s0+4]
  if $t1 goto :null16
  Error("null pointer")
null16:
  $t0 = [$t1]
  $t0 = Lt(7 $t0)
  if $t0 goto :bounds15
  Error("array index out of bounds")
bounds15:
  $t0 = MulS(7 4)
  $t0 = Add($t0 $t1)
  [$t0+4] = 9
  $t0 = [$s0+4]
  if $t0 goto :null17
  Error("null pointer")
null17:
  $t1 = [$t0]
  $t1 = Lt(8 $t1)
  if $t1 goto :bounds16
  Error("array index out of bounds")
bounds16:
  $t1 = MulS(8 4)
  $t1 = Add($t1 $t0)
  [$t1+4] = 19
  $t1 = [$s0+4]
  if $t1 goto :null18
  Error("null pointer")
null18:
  $t0 = [$t1]
  $t0 = Lt(9 $t0)
  if $t0 goto :bounds17
  Error("array index out of bounds")
bounds17:
  $t0 = MulS(9 4)
  $t0 = Add($t0 $t1)
  [$t0+4] = 5
  $v0 = 0
  $s0 = local[0]
  ret

func AllocArray [in 0, out 0, local 0]
  $t0 = $a0
  $t1 = MulS($t0 4)
  $t1 = Add($t1 4)
  $t1 = HeapAllocZ($t1)
  [$t1] = $t0
  $v0 = $t1
  ret