.
This commit is contained in:
@@ -11,4 +11,17 @@ return {
|
|||||||
expected_stack_size = 1,
|
expected_stack_size = 1,
|
||||||
expected_stack_top = 5,
|
expected_stack_top = 5,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name = "VM: integer expressions",
|
||||||
|
template = [[
|
||||||
|
.func 0
|
||||||
|
pushi %d
|
||||||
|
pushi %d
|
||||||
|
%s
|
||||||
|
ret
|
||||||
|
]],
|
||||||
|
replacements = {
|
||||||
|
{ 2, 3, 'sum', expected_stack_top = 5 },
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
32
test/tests.c
32
test/tests.c
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
static void run_assembly_tests(void);
|
static void run_assembly_tests(void);
|
||||||
static void run_assembly_test(lua_State* L);
|
static void run_assembly_test(lua_State* L);
|
||||||
|
static void run_assembly_test_code(lua_State* L);
|
||||||
|
static void run_assembly_test_template(lua_State* L);
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -343,13 +345,35 @@ static void run_assembly_tests(void)
|
|||||||
|
|
||||||
static void run_assembly_test(lua_State* L)
|
static void run_assembly_test(lua_State* L)
|
||||||
{
|
{
|
||||||
TycheVM* T = tyc_new();
|
|
||||||
|
|
||||||
// print test name
|
// print test name
|
||||||
lua_getfield(L, -1, "name");
|
lua_getfield(L, -1, "name");
|
||||||
printf(" - %s\n", lua_tostring(L, -1));
|
printf(" - %s\n", lua_tostring(L, -1));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// has code?
|
||||||
|
lua_getfield(L, -1, "code");
|
||||||
|
if (!lua_isnil(L, -1)) {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
run_assembly_test_code(L);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// has template
|
||||||
|
lua_getfield(L, -1, "template");
|
||||||
|
if (!lua_isnil(L, -1)) {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
run_assembly_test_template(L);
|
||||||
|
} else {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_assembly_test_code(lua_State* L)
|
||||||
|
{
|
||||||
|
TycheVM* T = tyc_new();
|
||||||
|
|
||||||
// load code
|
// load code
|
||||||
uint8_t* bytecode; size_t bytecode_sz;
|
uint8_t* bytecode; size_t bytecode_sz;
|
||||||
lua_getfield(L, -1, "code");
|
lua_getfield(L, -1, "code");
|
||||||
@@ -379,4 +403,8 @@ static void run_assembly_test(lua_State* L)
|
|||||||
// cleanup
|
// cleanup
|
||||||
free(bytecode);
|
free(bytecode);
|
||||||
tyc_destroy(T);
|
tyc_destroy(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_assembly_test_template(lua_State* L)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user