From 57d80cda62507467eb1b1c05481e84ed82909662 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 5 Aug 2024 21:21:25 +0200 Subject: [PATCH] fixed failing tests --- src/ast/ast.c | 2 +- src/set/types.c | 4 ++- tests/ast/test_ast.py | 44 ++++++++++++++++------------- tests/driver/clang/main.gsc | 17 ++++++----- tests/driver/gcc/main.gsc | 17 ++++++----- tests/hello_world/main.gsc | 18 ++++++------ tests/input_file/test.gsc | 4 +-- tests/input_file/test_input_file.py | 2 +- 8 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/ast/ast.c b/src/ast/ast.c index d11b9c3..aa88e1d 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -89,7 +89,7 @@ void AST_init() { lookup_table[AST_AddressOf] = "address of"; lookup_table[AST_Dereference] = "deref"; lookup_table[AST_Reference] = "ref"; - lookup_table[AST_Reference] = "ret"; + lookup_table[AST_Return] = "ret"; } const char* AST_node_to_string(const struct AST_Node_t* node) { diff --git a/src/set/types.c b/src/set/types.c index 8b07cec..50dbe3e 100644 --- a/src/set/types.c +++ b/src/set/types.c @@ -9,7 +9,7 @@ Type* SET_function_get_return_type(Function* function) { assert(NULL != function); - const Type* return_type = NULL; + Type* return_type = NULL; switch (function->kind) { case FunctionDeclarationKind: @@ -25,4 +25,6 @@ Type* SET_function_get_return_type(Function* function) { if (NULL == return_type) { ERROR("Function return type is nullptr"); } + + return return_type; } diff --git a/tests/ast/test_ast.py b/tests/ast/test_ast.py index 7dc0e4d..38f1327 100644 --- a/tests/ast/test_ast.py +++ b/tests/ast/test_ast.py @@ -65,27 +65,31 @@ def run_check_print_node(): 34 typedef 35 box 36 fun -37 value -38 list -39 expr list -40 arg list -41 param list -42 stmt list -43 ident list -44 value -45 type -46 value +37 fun +38 fun +39 fun +40 value +41 list +42 expr list +43 arg list +44 param list +45 stmt list +46 ident list 47 value -48 value -49 - -50 parameter +48 type +49 value +50 value 51 value -52 parameter-declaration -53 address of -54 deref -55 ref -56 value -57 value +52 - +53 parameter +54 value +55 parameter-declaration +56 address of +57 deref +58 ref +59 value +60 value +61 ret """ == p.stdout @@ -95,7 +99,7 @@ def run_check_print_graphviz(): info("creating temporary folder...") if not os.path.exists("tmp"): - os.mkdir("tmp") + os.makedirs("tmp", exist_ok=True) info("cleaning temporary folder...") diff --git a/tests/driver/clang/main.gsc b/tests/driver/clang/main.gsc index aeaf8f7..5d776cf 100644 --- a/tests/driver/clang/main.gsc +++ b/tests/driver/clang/main.gsc @@ -1,28 +1,27 @@ import "std" -fun cstrlen(in cstr: str)(out u32: len) { +fun u32:cstrlen(in cstr: str) { u32: idx = 0 as u32 while !(str[idx] == 0) { idx = idx + 1 as u32 } - len = idx + ret idx } fun printcstr(in cstr: msg) { - u32: len = 0 as u32 - cstrlen(msg)(len) + u32: len = cstrlen(msg) - handle: stdout = 0 as u32 - getStdoutHandle()(stdout) + handle: stdout = getStdoutHandle() - u32: written = 0 as u32 - writeBytes(stdout, msg, len)(written) + writeBytes(stdout, msg, len) } -fun main() { +fun int:main() { cstr: msg = "Hello, world!\n" printcstr(msg) + + ret 0 } diff --git a/tests/driver/gcc/main.gsc b/tests/driver/gcc/main.gsc index aeaf8f7..5d776cf 100644 --- a/tests/driver/gcc/main.gsc +++ b/tests/driver/gcc/main.gsc @@ -1,28 +1,27 @@ import "std" -fun cstrlen(in cstr: str)(out u32: len) { +fun u32:cstrlen(in cstr: str) { u32: idx = 0 as u32 while !(str[idx] == 0) { idx = idx + 1 as u32 } - len = idx + ret idx } fun printcstr(in cstr: msg) { - u32: len = 0 as u32 - cstrlen(msg)(len) + u32: len = cstrlen(msg) - handle: stdout = 0 as u32 - getStdoutHandle()(stdout) + handle: stdout = getStdoutHandle() - u32: written = 0 as u32 - writeBytes(stdout, msg, len)(written) + writeBytes(stdout, msg, len) } -fun main() { +fun int:main() { cstr: msg = "Hello, world!\n" printcstr(msg) + + ret 0 } diff --git a/tests/hello_world/main.gsc b/tests/hello_world/main.gsc index 843f6e4..e3dc0df 100644 --- a/tests/hello_world/main.gsc +++ b/tests/hello_world/main.gsc @@ -1,27 +1,25 @@ import "std" -fun cstrlen(in cstr: str)(out u32: len) { +fun u32:cstrlen(in cstr: str) { u32: idx = 0 as u32 while !(str[idx] == 0) { - idx = idx + 1 + idx = idx + 1 as u32 } - len = idx + ret idx } fun printcstr(in cstr: msg) { - u32: len = 0 - cstrlen(msg)(len) + u32: len = cstrlen(msg) - handle: stdout = 0 - getStdoutHandle()(stdout) + handle: stdout = getStdoutHandle() - u32: written = 0 - writeBytes(stdout, msg, len)(written) + writeBytes(stdout, msg, len) } -fun main() { +fun int:main() { printcstr("Hello, world!\n") + ret 0 } diff --git a/tests/input_file/test.gsc b/tests/input_file/test.gsc index 3479ad3..c47d447 100644 --- a/tests/input_file/test.gsc +++ b/tests/input_file/test.gsc @@ -1,4 +1,4 @@ -fun main(out int: ret) { - ret = 56 as int +fun int:main() { + ret 56 as int } diff --git a/tests/input_file/test_input_file.py b/tests/input_file/test_input_file.py index 550f3f4..6804bf2 100644 --- a/tests/input_file/test_input_file.py +++ b/tests/input_file/test_input_file.py @@ -22,7 +22,7 @@ def check_abort(): logging.basicConfig(level=logging.INFO) - p = subprocess.run(["./gsc", "compile"], capture_output=True, text=True) + p = subprocess.run(["./gsc", "compile", "foo.gsc"], capture_output=True, text=True) assert p.returncode == 1