This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathbytecode.lcb
More file actions
308 lines (263 loc) · 7.69 KB
/
bytecode.lcb
File metadata and controls
308 lines (263 loc) · 7.69 KB
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
/*
Copyright (C) 2016 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
module com.livecode.compiler.bytecode.tests
public unsafe handler TestJump()
variable tTest as Boolean
put false into tTest
bytecode
jump lAfterAssign
assign_constant tTest, true
lAfterAssign:
end bytecode
test "jump forward label" when tTest is false
end handler
public unsafe handler TestJumpIfFalse()
variable tTest as Boolean
put false into tTest
bytecode
register regTemp
assign_constant regTemp, false
jump_if_false regTemp, lAfterAssign
assign_constant tTest, true
lAfterAssign:
end bytecode
test "jumpiffalse forward label" when tTest is false
end handler
public unsafe handler TestJumpIfTrue()
variable tTest as Boolean
put false into tTest
bytecode
register regTemp
assign_constant regTemp, true
jump_if_true regTemp, lAfterAssign
assign_constant tTest, true
lAfterAssign:
end bytecode
test "jumpiffalse forward label" when tTest is false
end handler
public unsafe handler TestAssignConstant()
variable tTest
put "Hello World!" into tTest
bytecode
assign_constant tTest, nothing
end bytecode
test "assignconstant nothing literal" when tTest is nothing
bytecode
assign_constant tTest, false
end bytecode
test "assignconstant boolean literal" when tTest is false
bytecode
assign_constant tTest, 0
end bytecode
test "assignconstant int literal" when tTest is 0
bytecode
assign_constant tTest, 0.125
end bytecode
test "assignconstant float literal" when tTest is 0.125
bytecode
assign_constant tTest, "Foo"
end bytecode
test "assignconstant string literal" when tTest is "Foo"
end handler
private unsafe handler DoTestAssignParameter(in pSource)
bytecode
register regTemp
assign_constant regTemp, true
assign pSource, regTemp
end bytecode
test "assign temp to param" when pSource is true
variable tTarget
put true into tTarget
put false into pSource
bytecode
register regTemp
assign regTemp, pSource
assign tTarget, regTemp
end bytecode
test "assign param to temp" when tTarget is false
end handler
public unsafe handler TestAssign()
variable tTarget
put false into tTarget
bytecode
register regTemp
assign_constant regTemp, true
assign tTarget, regTemp
end bytecode
test "assign temp to local" when tTarget is true
variable tSource
put true into tSource
put false into tTarget
bytecode
register regTemp
assign regTemp, tSource
assign tTarget, regTemp
end bytecode
test "assign local to temp" when tTarget is true
DoTestAssignParameter(false)
end handler
private unsafe handler DoTestReturnNothing()
bytecode
return
end bytecode
return true
end handler
private unsafe handler DoTestReturnValue(in pValue)
bytecode
return pValue
end bytecode
return true
end handler
public unsafe handler TestReturn()
DoTestReturnNothing()
test "return nothing" when the result is nothing
DoTestReturnValue(100)
test "return value" when the result is 100
end handler
private handler DoTestInvoke(in pInput, out rOutput)
put pInput into rOutput
return true
end handler
public unsafe handler TestInvoke()
variable tOutput
variable tResult
put nothing into tOutput
put nothing into tResult
bytecode
register regTemp
assign_constant regTemp, 100
invoke DoTestInvoke, tResult, regTemp, tOutput
end bytecode
test "invoke in and out params" when tOutput is 100
test "invoke result" when tResult is true
end handler
public unsafe handler TestInvokeIndirect()
variable tOutput
variable tResult
put nothing into tOutput
put nothing into tResult
bytecode
register regTemp
register regHandler
fetch regHandler, DoTestInvoke
assign_constant regTemp, 100
invoke_indirect regHandler, tResult, regTemp, tOutput
end bytecode
test "invokeindirect in and out params" when tOutput is 100
test "invokeindirect result" when tResult is true
end handler
constant kConstantNothing is nothing
constant kConstantBoolean is false
constant kConstantInteger is 0
constant kConstantFloat is 0.125
constant kConstantString is "Foo"
variable sModuleVariable
handler type Return100Type()
private handler Return100()
return 100
end handler
public unsafe handler TestFetch()
variable tTest
put "Hello World!" into tTest
bytecode
fetch tTest, kConstantNothing
end bytecode
test "fetch nothing literal" when tTest is kConstantNothing
put "Hello World!" into tTest
bytecode
fetch tTest, kConstantBoolean
end bytecode
test "fetch boolean literal" when tTest is kConstantBoolean
put "Hello World!" into tTest
bytecode
fetch tTest, kConstantInteger
end bytecode
test "fetch int literal" when tTest is kConstantInteger
put "Hello World!" into tTest
bytecode
fetch tTest, kConstantFloat
end bytecode
test "fetch float literal" when tTest is kConstantFloat
put "Hello World!" into tTest
bytecode
fetch tTest, kConstantString
end bytecode
test "fetch string literal" when tTest is kConstantString
put "Hello World!" into tTest
put 100 into sModuleVariable
bytecode
fetch tTest, sModuleVariable
end bytecode
test "fetch variable" when tTest is 100
put "Hello World!" into tTest
bytecode
fetch tTest, Return100
end bytecode
variable tTestHandler as Return100Type
put tTest into tTestHandler
test "fetch handler" when tTestHandler() is 100
end handler
public unsafe handler TestStore()
put nothing into sModuleVariable
bytecode
register regTemp
assign_constant regTemp, 100
store regTemp, sModuleVariable
end bytecode
test "store variable" when sModuleVariable is 100
end handler
public unsafe handler TestAssignList()
variable tTest
variable tElement1
variable tElement2
put 1 into tElement1
put 2 into tElement2
put nothing into tTest
bytecode
assign_list tTest, tElement1, tElement2
end bytecode
test "assignlist" when tTest is [1, 2]
end handler
public unsafe handler TestAssignArray()
variable tTest
variable tElement1
variable tElement2
variable tKey1
variable tKey2
put 1 into tElement1
put 2 into tElement2
put "foo" into tKey1
put "bar" into tKey2
put nothing into tTest
bytecode
assign_array tTest, tKey1, tElement1, tKey2, tElement2
end bytecode
test "assignarray" when the number of elements in tTest is 2 and \
tTest["foo"] is 1 and tTest["bar"] is 2
end handler
public unsafe handler TestReset()
variable tTest as Boolean
put true into tTest
bytecode
reset tTest
end bytecode
test "reset handler variable" when tTest is false
put true into tTest
bytecode
register regTemp as Boolean
reset regTemp
assign tTest, regTemp
end bytecode
test "reset register variable" when tTest is false
end handler
end module