.
This commit is contained in:
@@ -7,10 +7,9 @@ Progress of the Lua port:
|
|||||||
- [ ] Local variables
|
- [ ] Local variables
|
||||||
- [ ] Calling functions
|
- [ ] Calling functions
|
||||||
- [ ] Globals
|
- [ ] Globals
|
||||||
- [ ] Recursion
|
|
||||||
- [ ] Stack traces in case of errors
|
|
||||||
- [ ] Control flow
|
- [ ] Control flow
|
||||||
- [ ] Lablels in Assembly
|
- [ ] Lablels in Assembly
|
||||||
|
- [ ] Recursion
|
||||||
- [ ] Strings
|
- [ ] Strings
|
||||||
- [ ] From constants
|
- [ ] From constants
|
||||||
- [ ] Garbage collection
|
- [ ] Garbage collection
|
||||||
@@ -21,8 +20,9 @@ Progress of the Lua port:
|
|||||||
- [ ] Metatables
|
- [ ] Metatables
|
||||||
- [ ] Real
|
- [ ] Real
|
||||||
- [ ] Error handling
|
- [ ] Error handling
|
||||||
|
- [ ] Stack traces in case of errors
|
||||||
- [ ] Closures/upvalues
|
- [ ] Closures/upvalues
|
||||||
|
|
||||||
|
|
||||||
- [ ] Assembler generate bytecode
|
- [ ] Assembler generate bytecode
|
||||||
- [ ] VM interepret it
|
- [ ] VM interpret it
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ local VM = require('tyche-vm')
|
|||||||
-- --
|
-- --
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
function TEST(name)
|
||||||
|
print("### " .. name)
|
||||||
|
end
|
||||||
|
|
||||||
function assert_eq(found, expected, key)
|
function assert_eq(found, expected, key)
|
||||||
assert(type(found) == type(expected), 'Types not matching , expected "' .. pprint.pformat(expected) .. '", found "' .. pprint.pformat(found) .. '".' .. ((key ~= nil) and ('(key: ' .. key .. ')') or ''))
|
assert(type(found) == type(expected), 'Types not matching , expected "' .. pprint.pformat(expected) .. '", found "' .. pprint.pformat(found) .. '".' .. ((key ~= nil) and ('(key: ' .. key .. ')') or ''))
|
||||||
@@ -30,7 +33,8 @@ end
|
|||||||
-- --
|
-- --
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
do
|
do TEST "Parser"
|
||||||
|
|
||||||
local source = [[
|
local source = [[
|
||||||
.const
|
.const
|
||||||
0: 3.14
|
0: 3.14
|
||||||
@@ -73,7 +77,7 @@ end
|
|||||||
-- --
|
-- --
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
do
|
do TEST "Stack"
|
||||||
local stack = VM.new().stack
|
local stack = VM.new().stack
|
||||||
stack:push({ type='integer', value=10 })
|
stack:push({ type='integer', value=10 })
|
||||||
stack:push({ type='integer', value=20 })
|
stack:push({ type='integer', value=20 })
|
||||||
@@ -92,7 +96,7 @@ do
|
|||||||
assert_eq(#stack, 0)
|
assert_eq(#stack, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do TEST "Stack with frame pointer"
|
||||||
local stack = VM.new().stack
|
local stack = VM.new().stack
|
||||||
stack:push({ type='integer', value=10 })
|
stack:push({ type='integer', value=10 })
|
||||||
stack:push({ type='integer', value=20 })
|
stack:push({ type='integer', value=20 })
|
||||||
@@ -133,7 +137,7 @@ local function arith(a, b, op)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
do
|
do TEST("VM: basic")
|
||||||
local vm = VM:new()
|
local vm = VM:new()
|
||||||
-- vm.debug = true
|
-- vm.debug = true
|
||||||
local bytecode = assemble [[
|
local bytecode = assemble [[
|
||||||
@@ -155,7 +159,7 @@ do
|
|||||||
assert_eq(vm:to_integer(-1), 5)
|
assert_eq(vm:to_integer(-1), 5)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do TEST("VM: logic/arithmetic")
|
||||||
assert_eq(arith(2, 5, 'sum'):to_integer(-1), 7)
|
assert_eq(arith(2, 5, 'sum'):to_integer(-1), 7)
|
||||||
assert_eq(arith(2, 5, 'sub'):to_integer(-1), -3)
|
assert_eq(arith(2, 5, 'sub'):to_integer(-1), -3)
|
||||||
assert_eq(arith(2, 5, 'mul'):to_integer(-1), 10)
|
assert_eq(arith(2, 5, 'mul'):to_integer(-1), 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user