fixed failing tests

This commit is contained in:
Sven Vogel 2024-08-05 21:21:25 +02:00
parent 5fa5345dea
commit 57d80cda62
8 changed files with 55 additions and 53 deletions

View File

@ -89,7 +89,7 @@ void AST_init() {
lookup_table[AST_AddressOf] = "address of"; lookup_table[AST_AddressOf] = "address of";
lookup_table[AST_Dereference] = "deref"; lookup_table[AST_Dereference] = "deref";
lookup_table[AST_Reference] = "ref"; 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) { const char* AST_node_to_string(const struct AST_Node_t* node) {

View File

@ -9,7 +9,7 @@
Type* SET_function_get_return_type(Function* function) { Type* SET_function_get_return_type(Function* function) {
assert(NULL != function); assert(NULL != function);
const Type* return_type = NULL; Type* return_type = NULL;
switch (function->kind) { switch (function->kind) {
case FunctionDeclarationKind: case FunctionDeclarationKind:
@ -25,4 +25,6 @@ Type* SET_function_get_return_type(Function* function) {
if (NULL == return_type) { if (NULL == return_type) {
ERROR("Function return type is nullptr"); ERROR("Function return type is nullptr");
} }
return return_type;
} }

View File

@ -65,27 +65,31 @@ def run_check_print_node():
34 typedef 34 typedef
35 box 35 box
36 fun 36 fun
37 value 37 fun
38 list 38 fun
39 expr list 39 fun
40 arg list 40 value
41 param list 41 list
42 stmt list 42 expr list
43 ident list 43 arg list
44 value 44 param list
45 type 45 stmt list
46 value 46 ident list
47 value 47 value
48 value 48 type
49 - 49 value
50 parameter 50 value
51 value 51 value
52 parameter-declaration 52 -
53 address of 53 parameter
54 deref 54 value
55 ref 55 parameter-declaration
56 value 56 address of
57 value 57 deref
58 ref
59 value
60 value
61 ret
""" == p.stdout """ == p.stdout
@ -95,7 +99,7 @@ def run_check_print_graphviz():
info("creating temporary folder...") info("creating temporary folder...")
if not os.path.exists("tmp"): if not os.path.exists("tmp"):
os.mkdir("tmp") os.makedirs("tmp", exist_ok=True)
info("cleaning temporary folder...") info("cleaning temporary folder...")

View File

@ -1,28 +1,27 @@
import "std" import "std"
fun cstrlen(in cstr: str)(out u32: len) { fun u32:cstrlen(in cstr: str) {
u32: idx = 0 as u32 u32: idx = 0 as u32
while !(str[idx] == 0) { while !(str[idx] == 0) {
idx = idx + 1 as u32 idx = idx + 1 as u32
} }
len = idx ret idx
} }
fun printcstr(in cstr: msg) { fun printcstr(in cstr: msg) {
u32: len = 0 as u32 u32: len = cstrlen(msg)
cstrlen(msg)(len)
handle: stdout = 0 as u32 handle: stdout = getStdoutHandle()
getStdoutHandle()(stdout)
u32: written = 0 as u32 writeBytes(stdout, msg, len)
writeBytes(stdout, msg, len)(written)
} }
fun main() { fun int:main() {
cstr: msg = "Hello, world!\n" cstr: msg = "Hello, world!\n"
printcstr(msg) printcstr(msg)
ret 0
} }

View File

@ -1,28 +1,27 @@
import "std" import "std"
fun cstrlen(in cstr: str)(out u32: len) { fun u32:cstrlen(in cstr: str) {
u32: idx = 0 as u32 u32: idx = 0 as u32
while !(str[idx] == 0) { while !(str[idx] == 0) {
idx = idx + 1 as u32 idx = idx + 1 as u32
} }
len = idx ret idx
} }
fun printcstr(in cstr: msg) { fun printcstr(in cstr: msg) {
u32: len = 0 as u32 u32: len = cstrlen(msg)
cstrlen(msg)(len)
handle: stdout = 0 as u32 handle: stdout = getStdoutHandle()
getStdoutHandle()(stdout)
u32: written = 0 as u32 writeBytes(stdout, msg, len)
writeBytes(stdout, msg, len)(written)
} }
fun main() { fun int:main() {
cstr: msg = "Hello, world!\n" cstr: msg = "Hello, world!\n"
printcstr(msg) printcstr(msg)
ret 0
} }

View File

@ -1,27 +1,25 @@
import "std" import "std"
fun cstrlen(in cstr: str)(out u32: len) { fun u32:cstrlen(in cstr: str) {
u32: idx = 0 as u32 u32: idx = 0 as u32
while !(str[idx] == 0) { while !(str[idx] == 0) {
idx = idx + 1 idx = idx + 1 as u32
} }
len = idx ret idx
} }
fun printcstr(in cstr: msg) { fun printcstr(in cstr: msg) {
u32: len = 0 u32: len = cstrlen(msg)
cstrlen(msg)(len)
handle: stdout = 0 handle: stdout = getStdoutHandle()
getStdoutHandle()(stdout)
u32: written = 0 writeBytes(stdout, msg, len)
writeBytes(stdout, msg, len)(written)
} }
fun main() { fun int:main() {
printcstr("Hello, world!\n") printcstr("Hello, world!\n")
ret 0
} }

View File

@ -1,4 +1,4 @@
fun main(out int: ret) { fun int:main() {
ret = 56 as int ret 56 as int
} }

View File

@ -22,7 +22,7 @@ def check_abort():
logging.basicConfig(level=logging.INFO) 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 assert p.returncode == 1