.
This commit is contained in:
@@ -118,10 +118,21 @@ end
|
||||
|
||||
----------------------
|
||||
-- --
|
||||
-- VM STACK --
|
||||
-- VM ARITH --
|
||||
-- --
|
||||
----------------------
|
||||
|
||||
local function arith(a, b, op)
|
||||
return VM:new():load(assemble(string.format([[
|
||||
.func 0
|
||||
pushi %d
|
||||
pushi %d
|
||||
%s
|
||||
ret
|
||||
]], a, b, op))):call(0)
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
local vm = VM:new()
|
||||
-- vm.debug = true
|
||||
@@ -144,4 +155,9 @@ do
|
||||
assert_eq(vm:to_integer(-1), 5)
|
||||
end
|
||||
|
||||
do
|
||||
assert_eq(arith(2, 5, 'sum'):to_integer(-1), 7)
|
||||
assert_eq(arith(2, 5, 'sub'):to_integer(-1), -3)
|
||||
end
|
||||
|
||||
print('End.')
|
||||
Reference in New Issue
Block a user