diff --git a/build.bat b/build.bat index f9c8aed..3a54032 100644 --- a/build.bat +++ b/build.bat @@ -2,7 +2,7 @@ pushd %~dp0 rem cl main.cpp -I.. user32.lib -rem clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib +clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib rem ubuntu run clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core.out main examples/arms_race/arms_race.core diff --git a/core_typechecking.cpp b/core_typechecking.cpp index bc5796f..b091490 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1263,7 +1263,13 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str if(is_pointer(type)) type = type->base; type_complete(type); + if(!type->ast){ + compiler_error(node->pos, "Builtin type %Q doesn't have anything to access using '.' operator", typestring(type)); + } scope = ((Ast_Decl *)type->ast)->scope; + if(!scope){ + compiler_error(node->pos, "Internal compiler error? Type %Q doesn't have scope, you cannot use '.' on this variable", typestring(type)); + } } Operand right = resolve_expr(node->right, AST_CANT_BE_NULL, 0, scope); diff --git a/modules/Math.core b/modules/Math.core index 85a07ee..45704ce 100644 --- a/modules/Math.core +++ b/modules/Math.core @@ -1,8 +1,11 @@ - sqrtf :: #foreign (value: F32): F32 cosf :: #foreign (value: F32): F32 sinf :: #foreign (value: F32): F32 +floorf :: #foreign (value: F32): F32 +roundf :: #foreign (value: F32): F32 +ceilf :: #foreign (value: F32): F32 + Vec2I :: struct;; x: S64; y: S64 Vec2 :: struct;; x: F32; y: F32 @@ -19,6 +22,22 @@ Vec2 :: struct;; x: F32; y: F32 "/" :: (a: Vec2, b: F32) : Vec2 ;; return {a.x/b, a.y/b} "/" :: (a: F32, b: Vec2) : Vec2 ;; return {a/b.x, a/b.y} +"*" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x*b.x, a.y*b.y} +"*" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x*b, a.y*b} +"*" :: (a: S64, b: Vec2I) : Vec2I ;; return {a*b.x, a*b.y} +"-" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x-b.x, a.y-b.y} +"-" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x-b, a.y-b} +"-" :: (a: S64, b: Vec2I) : Vec2I ;; return {a-b.x, a-b.y} +"+" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x+b.x, a.y+b.y} +"+" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x+b, a.y+b} +"+" :: (a: S64, b: Vec2I) : Vec2I ;; return {a+b.x, a+b.y} +"/" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x/b.x, a.y/b.y} +"/" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x/b, a.y/b} +"/" :: (a: S64, b: Vec2I) : Vec2I ;; return {a/b.x, a/b.y} + +FloorVec2ToVec2I :: (a: Vec2): Vec2I ;; return {floorf(a.x)->S64, floorf(a.y)->S64} +CastVec2ToVec2I :: (a: Vec2): Vec2I ;; return {a.x->S64, a.y->S64} + F32_Clamp :: (min: F32, value: F32, max: F32): F32 if value > max;; return max if value < min;; return min @@ -31,3 +50,8 @@ F32_ClampBottom :: (min: F32, value: F32): F32 F32_Absolute :: (val: F32): F32 if val < 0;; return -val return val + +F32_Min :: (a: F32, b: F32): F32 + if a > b ;; return b ; return a +F32_Max :: (a: F32, b: F32): F32 + if a > b ;; return a ; return b diff --git a/modules/Multimedia.core b/modules/Multimedia.core index d8c3daa..c06e72c 100644 --- a/modules/Multimedia.core +++ b/modules/Multimedia.core @@ -29,6 +29,8 @@ MUWindow :: struct x: S64 y: S64 sizef: Vec2 + size: Vec2I + resizable: Bool MUTime :: struct total : F64 diff --git a/modules/win32_multimedia.core b/modules/win32_multimedia.core index 903e395..3fcc1a4 100644 --- a/modules/win32_multimedia.core +++ b/modules/win32_multimedia.core @@ -93,7 +93,12 @@ SetWindowPosition :: (window: HWND, style: DWORD, pos: Vec2I): void AdjustWindowRect(window, style, &rect) SetWindowPos(window, 0, rect.left, rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE) -StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!", target_ms: F64 = 0.0166666) +StartMultimedia :: ( + x: S64 = 1280, y: S64 = 720, + title: String = "Hello people!", + window_resizable: Bool = false, + target_ms: F64 = 0.0166666 +) Mu.time.delta = target_ms if timeBeginPeriod(1) == TIMERR_NOERROR Mu.os.good_scheduling = true @@ -113,7 +118,7 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!" } Assert(RegisterClassW(&w) != 0) - style: DWORD = GetWindowStyle(false) + style: DWORD = GetWindowStyle(window_resizable) Mu.os.window = CreateWindowExW( dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0, X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = x->int, nHeight = y->int, @@ -132,9 +137,11 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!" Mu.os.window_dc = GetDC(Mu.os.window) Mu.os.bitmap = CreateBitmap(Mu.os.window_dc, size) + Mu.window.resizable = window_resizable Mu.screen = Mu.os.bitmap.data Mu.window.x = size.x Mu.window.y = size.y + Mu.window.size = size Mu.window.sizef.x = Mu.window.x->F32 Mu.window.sizef.y = Mu.window.y->F32 @@ -149,7 +156,7 @@ UpdateMultimedia :: (): Bool size := GetWindowSize(Mu.os.window) if size.x != Mu.window.x || size.y != Mu.window.y DestroyBitmap(&Mu.os.bitmap) - CreateBitmap(Mu.os.window_dc, size) + Mu.os.bitmap = CreateBitmap(Mu.os.window_dc, size) Mu.screen = Mu.os.bitmap.data Mu.window.x = size.x