-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput
298 lines (226 loc) · 4.64 KB
/
output
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
#! /bin/vypint
# VYPcode: 1.0
# Generated by: xkozar02
ALIAS FP $0
# VMT of class Object
CREATE $6, 2
SET [$SP], $6
ADDI $SP, $SP, 1
SETWORD $6, 0, "Object:toString"
SETWORD $6, 1, "Object:getClass"
# VMT of class Shape
CREATE $6, 3
SET [$SP], $6
ADDI $SP, $SP, 1
SETWORD $6, 0, "Object:toString"
SETWORD $6, 1, "Object:getClass"
SETWORD $6, 2, "Shape:Shape"
# VMT of class Rectangle
CREATE $6, 5
SET [$SP], $6
ADDI $SP, $SP, 1
SETWORD $6, 0, "Object:toString"
SETWORD $6, 1, "Object:getClass"
SETWORD $6, 2, "Shape:Shape"
SETWORD $6, 3, "Rectangle:Rectangle"
SETWORD $6, 4, "Rectangle:getID"
JUMP main
LABEL Object:toString
INT2STRING $7, [$SP - 2]
SUBI $SP, $SP, 1
SET [$SP - 1], $7
RETURN [$SP + 1]
LABEL Object:getClass
GETWORD $7, [$SP - 2], 0
SUBI $SP, $SP, 1
SET [$SP - 1], $7
RETURN [$SP + 1]
LABEL concat
GETSIZE $4, [$SP - 3] # Left string
GETSIZE $5, [$SP - 2] # Right string
COPY $6, [$SP - 3]
ADDI $1, $4, $5 # Total length
RESIZE $6, $1
SET $2, 0
LABEL concat_start
LTI $1, $2, $5
JUMPZ concat_end, $1
GETWORD $1, [$SP-2], $2
ADDI $7, $2, $4
SETWORD $6, $7, $1
ADDI $2, $2, 1
JUMP concat_start
LABEL concat_end
SUBI $SP, $SP, 3
SET [$SP], $6
ADDI $SP, $SP, 1
RETURN [$SP + 2]
LABEL length
GETSIZE $7, [$SP - 2]
SUBI $SP, $SP, 1
SET [$SP - 1], $7
RETURN [$SP + 1]
LABEL readInt
READI $7
SET [$SP - 1], $7
RETURN [$SP]
LABEL readString
READS $7
SET [$SP - 1], $7
RETURN [$SP]
LABEL subStr
GETSIZE $7, [$SP - 4] # Original string size
GTI $4, [$SP - 3], $7
LTI $5, [$SP - 3], 0
OR $4, $4, $5
JUMPZ __subStrStart, $4
CREATE $6, 1
SETWORD $6, 0, ""
GETWORD $6, $6, 0
JUMP substr_end
LABEL __subStrStart
CREATE $6, [$SP - 2] # Chunk with size
SET $4, [$SP - 3] # BEGIN INDEX
SET $2, 0 #COUNTER
ADDI $1, $4, [$SP - 2]
LTI $1, $1, $7
JUMPNZ substr_start, $1
SUBI $1, $7, $4
RESIZE $6, $1
LABEL substr_start
LTI $1, $4, $7
JUMPZ substr_end, $1
LTI $1, $2, [$SP - 2]
JUMPZ substr_end, $1
GETWORD $1, [$SP-4], $4
SETWORD $6, $2, $1
ADDI $2, $2, 1
ADDI $4, $4, 1
JUMP substr_start
LABEL substr_end
SUBI $SP, $SP, 4
SET [$SP], $6
ADDI $SP, $SP, 1
RETURN [$SP + 3]
LABEL main
#Function start
ADDI $SP, $SP, 1
SET $FP, $SP
#Create variable 3:1:r
SET [$FP+ 0], 0
# Restore stack pointer
ADDI $SP, $FP, 1
# Creating new instance of object Rectangle
CREATE $6, 5
SETWORD $6, 0, "Rectangle"
SETWORD $6, 1, [2]
SETWORD $6, 2, [1]
SETWORD $6, 3, 0
SETWORD $6, 4, ""
SET [$SP], $6
ADDI $SP, $SP, 1
# Calling method Shape
GETWORD $7, [$SP-1], 1
GETWORD $7, $7, 2
SET [$SP], $FP
ADDI $SP, $SP, 1
CALL [$SP], $7
# Calling method Rectangle
GETWORD $7, [$SP-1], 1
GETWORD $7, $7, 3
SET [$SP], $FP
ADDI $SP, $SP, 1
CALL [$SP], $7
# Variable assignment 3:1:r
SUBI $SP, $SP, 1
SET [$FP+ 0], [$SP]
# Restore stack pointer
ADDI $SP, $FP, 1
#Create variable 6:1:res
CREATE $6, 1
SETWORD $6, 0, ""
GETWORD $6, $6, 0
SET [$FP+ 1], $6
# Restore stack pointer
ADDI $SP, $FP, 2
# Variable expression '3:1:r'
SET [$SP], [$FP+ 0]
ADDI $SP, $SP, 1
# Calling method getID
GETWORD $7, [$SP-1], 1
GETWORD $7, $7, 4
SET [$SP], $FP
ADDI $SP, $SP, 1
CALL [$SP], $7
# Variable assignment 6:1:res
SUBI $SP, $SP, 1
SET [$FP+ 1], [$SP]
# Restore stack pointer
ADDI $SP, $FP, 2
# Variable expression '6:1:res'
SET [$SP], [$FP+ 1]
ADDI $SP, $SP, 1
# Print variables
WRITES [$SP-1]
# Restore stack pointer
ADDI $SP, $FP, 2
JUMP __END
LABEL Shape:Shape
#Function start
ADDI $SP, $SP, 1
SET $FP, $SP
# Return value
SET $2, [$FP - 1]
SET $3, [$FP - 2]
SUBI $SP, $SP, 1
SUBI $SP, $FP, 1
SUBI $SP, $SP, 1
SET $FP, $3
RETURN $2
LABEL Rectangle:Rectangle
#Function start
ADDI $SP, $SP, 1
SET $FP, $SP
# Return value
SET $2, [$FP - 1]
SET $3, [$FP - 2]
SUBI $SP, $SP, 1
SUBI $SP, $FP, 1
SUBI $SP, $SP, 1
SET $FP, $3
RETURN $2
LABEL Rectangle:getID
#Function start
ADDI $SP, $SP, 1
SET $FP, $SP
# Variable expression 'this'
SET [$SP], [$FP-3]
ADDI $SP, $SP, 1
# Field expression 'textID'
GETWORD $7, [$SP - 1], 4
SET [$SP-1], $7
# Return value
SET $2, [$FP - 1]
SET $3, [$FP - 2]
SUBI $SP, $SP, 1
SET [$FP - 3], [$SP]
SUBI $SP, $FP, 2
SET $FP, $3
RETURN $2
# Restore stack pointer
ADDI $SP, $FP, 0
#String literal expression ""
CREATE $6, 1
SETWORD $6, 0, ""
GETWORD $6, $6, 0
SET [$SP], $6
ADDI $SP, $SP, 1
# Return value
SET $2, [$FP - 1]
SET $3, [$FP - 2]
SUBI $SP, $SP, 1
SET [$FP - 3], [$SP]
SUBI $SP, $FP, 2
SET $FP, $3
RETURN $2
LABEL __END