From a372c4420ac476476296a145ebf3895cb1649b19 Mon Sep 17 00:00:00 2001 From: Slendi Date: Tue, 9 Apr 2024 02:22:09 +0300 Subject: [PATCH] Fix bug with finding function calls Signed-off-by: Slendi --- src/type.odin | 18 +++++++++++------- src/type_checker.odin | 20 +++++++++++++++++--- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/type.odin b/src/type.odin index bac4256..e53c9a5 100644 --- a/src/type.odin +++ b/src/type.odin @@ -15,16 +15,20 @@ StructType :: struct { } Type :: struct { - kind: TypeKind, - bit_size: u8, - is_signed: bool, - pointer_to: ^Type, - array_of: ^Type, - array_size: u64, - struct_type: ^StructType, + kind: TypeKind, + bit_size: u8, + is_signed: bool, + pointer_to: ^Type, + array_of: ^Type, + array_size: u64, + struct_index: u64, + struct_type: ^StructType, } type_to_string :: proc(type: ^Type) -> string { + if type == nil { + return "nil (shouldnt happen lol)" + } if type.kind == .Integer { if type.is_signed { return fmt.aprintf("i{}", type.bit_size) diff --git a/src/type_checker.odin b/src/type_checker.odin index cd9d187..213dafb 100644 --- a/src/type_checker.odin +++ b/src/type_checker.odin @@ -278,10 +278,12 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) { } found_field := false - for &field in struct_.fields { + struct_index: u64 = 0 + for &field, i in struct_.fields { if compare_dyn_arrs(&field.name, &rhs.value.([dynamic]u8)) { ast.return_type = field.type found_field = true + struct_index = u64(i) break } } @@ -298,6 +300,8 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) { break } + ast.return_type.struct_index = struct_index + case .FunctionCall: if ast.children[0].kind == .FieldAccess { // FIXME: This is some temporary shitfuckery, check if a function is part @@ -389,11 +393,12 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) { } else { ast.kind = .FunctionCall append(&ast.children, node_create_value(.Identifier, ast.range, ast.value)) - ast.value = nil ast.return_type = fn.return_type + ast.value = nil } + } else { + ast.return_type = type } - ast.return_type = type case .BinaryExpression: type_check(ast.children[0], ast) type_check(ast.children[1], ast) @@ -446,6 +451,15 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) { case .UnaryExpression: // FIXME: Verify that the operation is possible type_check(ast.children[0], ast) + append( + &g_message_list, + message_create( + .FIXME, + fmt.aprintf("Check type before setting return type in unary expression"), + ast.range, + ), + ) + ast.return_type = ast.children[0].return_type case .Ret: function_return_type := scope_function_return_type_lookup() if function_return_type == nil {