From 21be45a904a0afc767214298721bd2bbce19a054 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 8 Sep 2026 11:26:42 +0200 Subject: feat: add signed memory loads --- tests/parser_test.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/parser_test.c') diff --git a/tests/parser_test.c b/tests/parser_test.c index 32ea422..e1199eb 100644 --- a/tests/parser_test.c +++ b/tests/parser_test.c @@ -46,6 +46,25 @@ static void test_parse_const_expr(struct TestContext* context) free_program(&program); } +static void test_parse_unary(struct TestContext* context) +{ + struct Lexer lexer = create_lexer("const N = -8\nproc main\n{\nrax = -5\n}\n"); + struct Program program; + + check(context, parse_program(&lexer, &program)); + + const struct Expr* konst = program.consts[0].value; + check(context, konst->kind == EXPR_UNARY); + check(context, text_is(konst->unary.op, "-")); + check(context, primary_is(konst->unary.operand, "8")); + + const struct Expr* value = program.procs[0].body[0].assign.value; + check(context, value->kind == EXPR_UNARY); + check(context, primary_is(value->unary.operand, "5")); + + free_program(&program); +} + static void test_parse_data(struct TestContext* context) { struct Lexer lexer = create_lexer("data msg = \"hi\"\n"); @@ -264,6 +283,25 @@ static void test_parse_sized_deref(struct TestContext* context) free_program(&program); } +static void test_parse_signed_deref(struct TestContext* context) +{ + struct Lexer lexer = create_lexer("proc main\n{\nrax = ^signed byte rsi\nrbx = ^byte rsi\n}\n"); + struct Program program; + + check(context, parse_program(&lexer, &program)); + + const struct Expr* signed_load = program.procs[0].body[0].assign.value; + check(context, signed_load->kind == EXPR_DEREF); + check(context, signed_load->deref.is_signed); + check(context, signed_load->deref.size == STORE_SIZE_BYTE); + + const struct Expr* plain_load = program.procs[0].body[1].assign.value; + check(context, plain_load->kind == EXPR_DEREF); + check(context, !plain_load->deref.is_signed); + + free_program(&program); +} + static void test_parse_directives(struct TestContext* context) { struct Lexer lexer = create_lexer("[bits: 32]\n[entry: kmain]\n[enable: logical_registers]\nproc kmain\n{\nsyscall\n}\n"); @@ -349,6 +387,7 @@ void run_parser_tests(struct TestContext* context) { test_parse_consts(context); test_parse_const_expr(context); + test_parse_unary(context); test_parse_data(context); test_parse_proc_params(context); test_parse_proc_body(context); @@ -360,6 +399,7 @@ void run_parser_tests(struct TestContext* context) test_parse_call(context); test_parse_stack(context); test_parse_sized_deref(context); + test_parse_signed_deref(context); test_parse_directives(context); test_parse_bad_directive(context); test_parse_register_size_suffix(context); -- cgit v1.3