diff --git a/build_test.sh b/build_test.sh index a89dd53..ca7a35d 100755 --- a/build_test.sh +++ b/build_test.sh @@ -1,4 +1,9 @@ #!/bin/sh -odin run src -o:none -debug -out:speedcat '-extra-linker-flags:-L/opt/homebrew/opt/llvm/lib' -- test_type_checker.cat +set -xe + +LLVMC=llvm-config +LLVM_LINKER="-lc++ $($LLVMC --libs core --cxxflags --ldflags --system-libs|tr '\n' ' ')" + +odin run src -o:none -debug -out:speedcat -extra-linker-flags:"$LLVM_LINKER" -- test_type_checker.cat clang -I/opt/homebrew/include /opt/homebrew/lib/libraylib.a -lm -framework Cocoa -framework OpenGL -framework IOKit test_type_checker.ll test.c -o raylib diff --git a/llvm-project b/llvm-project new file mode 160000 index 0000000..a612524 --- /dev/null +++ b/llvm-project @@ -0,0 +1 @@ +Subproject commit a61252419779a6d4a5ebf71e7e2fc4adc75cfddd diff --git a/src/llvmc.odin b/src/llvmc.odin index 85045b6..9685e19 100644 --- a/src/llvmc.odin +++ b/src/llvmc.odin @@ -3,7 +3,7 @@ package main when ODIN_OS == .Windows { foreign import llvmc "llvm/win64/LLVM-C.lib" } else when ODIN_OS == .Linux || ODIN_OS == .Darwin { - foreign import llvmc "system:LLVM-C" + foreign import llvmc "system:LLVMCore" } LLVMBool :: distinct int diff --git a/src/type_checker.odin b/src/type_checker.odin index c595d05..97a0644 100644 --- a/src/type_checker.odin +++ b/src/type_checker.odin @@ -233,6 +233,21 @@ type_check :: proc(ast: ^Node, parent_ast: ^Node) { } scope_leave() case .FunctionCall: + if ast.children[0].kind == .FieldAccess { + type_check(ast.children[0], ast) + if ast.children[0].return_type == nil { + append( + &g_message_list, + message_create(.Error, fmt.aprintf("Field access return type is nil"), ast.children[0].range), + ) + break + } + + lhs := ast.children[0].children[0] + rhs := ast.children[0].children[1] + + } + type := scope_variable_lookup(ast.children[0].value.([dynamic]u8)) if type != nil { name := ast.children[0].value.([dynamic]u8) diff --git a/test_type_checker.cat b/test_type_checker.cat index 76fe55a..7bb9f6e 100644 --- a/test_type_checker.cat +++ b/test_type_checker.cat @@ -44,26 +44,51 @@ struct Color { a b g r: u8, } +fn ClearBackground(c: u32) +fn DrawRectangle(x y w h: i32, c: u32) +fn DrawCircle(x y: i32, r: f32, c: u32) + fn InitWindow(w h: i32, title: i32) fn CloseWindow -fn ClearBackgroundWrap(c: Color) fn BeginDrawing +fn SetTargetFPS(fps: i32) fn EndDrawing fn DrawFPS(x y: i32) -fn DrawRectangleWrap(x y w h: i32, c: Color) -fn DrawCircleWrap(x y: i32, r: f32, c: Color) fn WindowShouldClose i32 +1 << 3 | 2 + +fn ColorToRaylib(c: Color) u32 { + ret c.a as u32 << 24 | c.b as u32 << 16 | c.g as u32 << 8 | c.r +} + +fn ClearBackgroundWrap(c: Color) { + ClearBackground (ColorToRaylib c) +} + +fn DrawRectangleWrap(x y w h: i32, c: Color) { + DrawRectangle x y w h (ColorToRaylib c) +} + +fn DrawCircleWrap(x y: i32, r: f32, c: Color) { + DrawCircle x y r (ColorToRaylib c) +} + let white :: .Color{255 69 69 69} let red :: .Color{255 0 0 255} let blue :: .Color{255 0 255 255} +let x := 0 + InitWindow 640 480 0 +SetTargetFPS 30 for WindowShouldClose == 0 { + x = x + 1 + BeginDrawing ClearBackgroundWrap white DrawFPS 20 20 - DrawRectangleWrap 80 80 100 200 red + DrawRectangleWrap 80 x 100 200 red DrawCircleWrap 200 200 100.0 blue EndDrawing }