From 83ffc82f7982e462804f02958b1b5448a0c386fb Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 28 Sep 2022 14:09:20 +0200 Subject: [PATCH] Automatic closing of examples, revise drawing example --- core_compiler.cpp | 2 +- core_typechecking.cpp | 12 ++++---- .../drawing_to_screen_using_windows_api.kl | 28 +++++-------------- examples/raymarcher.kl | 5 ++-- modules/base.kl | 10 +++++++ modules/kernel32.kl | 1 + 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/core_compiler.cpp b/core_compiler.cpp index 2c76c08..8a83e88 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -264,7 +264,7 @@ compile_file(String filename, U32 compile_flags = COMPILE_NULL){ } if(is_flag_set(compile_flags, COMPILE_AND_RUN)){ - int result = system("a.exe"); + int result = system("a.exe testing"); assert(result != -1); if(result == 0){ log_info(PRINTF_GREEN "OK!" PRINTF_RESET); diff --git a/core_typechecking.cpp b/core_typechecking.cpp index f7a62d3..c417bec 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1076,13 +1076,11 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){ node->index_original_type = left.type; node->resolved_type = left.type->arr.base; - if(is_string(left.type)){ - if(left.type == type_pointer_to_char){ - node->resolved_type = type_char; - } - else { - node->resolved_type = type_u8; - } + if(left.type == type_pointer_to_char){ + node->resolved_type = type_char; + } + else if(is_string(left.type)) { + node->resolved_type = type_u8; } // @todo: type_architecture? diff --git a/examples/drawing_to_screen_using_windows_api.kl b/examples/drawing_to_screen_using_windows_api.kl index 5a86440..f4ef3b5 100644 --- a/examples/drawing_to_screen_using_windows_api.kl +++ b/examples/drawing_to_screen_using_windows_api.kl @@ -1,5 +1,5 @@ #import "base.kl" -Arena :: #import "arena.kl" +#import "arena.kl" #import "os_windows.kl" #import "kernel32.kl" #import "gdi32.kl" @@ -9,6 +9,8 @@ Arena :: #import "arena.kl" Vec2I :: struct;; x: S64; y: S64 Vec2 :: struct;; x: F32; y: F32 +AppIsRunning := true + Windows_Bitmap :: struct size: Vec2I data: *U32 @@ -44,8 +46,6 @@ CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap result.hdc = CreateCompatibleDC(hdc) return result - -AppIsRunning := true WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT if msg == WM_DESTROY PostQuitMessage(0) @@ -57,7 +57,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR good_scheduling = true - arena: Arena.Arena + arena: Arena window_name := StringToString16(&arena, "Have a wonderful day! 你好世界 ") w := WNDCLASSW{ @@ -98,21 +98,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS SelectObject(bitmap.hdc, bitmap.dib) BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY) + Sleep(100) - - frame_time := Time() - frame_start_time - if frame_time < requested_time_per_frame - if good_scheduling - time_to_sleep := (requested_time_per_frame - frame_time) * 1000 - if time_to_sleep > 0 - time_to_sleep_dword := time_to_sleep->DWORD - // @check if time_to_sleep_dword truncates down - Sleep(time_to_sleep_dword) - - new_frame_time := Time() - for new_frame_time < requested_time_per_frame - new_frame_time = Time() - frame_start_time - - frame_time = new_frame_time - frame_number += 1 - total_time += frame_time \ No newline at end of file + if CStringCompare(lpCmdLine, "testing") + ExitProcess(0) diff --git a/examples/raymarcher.kl b/examples/raymarcher.kl index 1fbea64..399cb70 100644 --- a/examples/raymarcher.kl +++ b/examples/raymarcher.kl @@ -182,11 +182,9 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS Screen = bitmap.data; X = bitmap.size.x; Y = bitmap.size.y Raymarcher_Update() - SelectObject(bitmap.hdc, bitmap.dib) BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY) - frame_time := Time() - frame_start_time frame_number += 1 TotalTime += frame_time @@ -203,3 +201,6 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS new_frame_time = Time() - frame_start_time frame_time = new_frame_time + + if CStringCompare(lpCmdLine, "testing") + ExitProcess(0) \ No newline at end of file diff --git a/modules/base.kl b/modules/base.kl index 0bd9942..a4d2d93 100644 --- a/modules/base.kl +++ b/modules/base.kl @@ -94,6 +94,16 @@ StringToString16 :: (arena: *Arena, in: String): String16 result.str[result.len] = 0 return result +CStringCompare :: (a: *char, b: *char): Bool + i := 0 + for , a[i] != 0, i+=1 + if a[i] != b[i] + return false + if a[i] != b[i] + return false + return true + + TestUnicode :: (arena: *Arena) string := " 豈 更 車 賈 滑 串 句 龜 龜 契 金 喇 奈 懶 癩 羅 蘿 螺 裸 邏 樂 洛 烙 珞 落 酪 駱 亂 卵 欄 爛 蘭 鸞 嵐 濫 藍 襤 拉 臘 蠟 廊 朗 浪 狼 郎 來 冷 勞 擄 櫓 爐 盧 老 蘆 虜 路 露 魯 鷺 碌 祿 綠 菉 錄 鹿 論 壟 弄 籠 聾 牢 磊 賂 雷 壘 屢 樓 淚 漏 累 縷 陋 勒 肋 凜 凌 稜 綾 菱 陵 讀 拏 樂 諾 丹 寧 怒 率 異 北 磻 便 復 不 泌 數 索 參 塞 省 葉 說 殺 辰 沈 拾 若 掠 略 亮 兩 凉 梁 糧 良 諒 量 勵 ..." string_result := StringToString16(arena, string) diff --git a/modules/kernel32.kl b/modules/kernel32.kl index c5d7dc9..89e752a 100644 --- a/modules/kernel32.kl +++ b/modules/kernel32.kl @@ -54,6 +54,7 @@ WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfChars WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL __debugbreak :: #foreign () +ExitProcess :: #foreign (uExitCode: UINT) GetLastError :: #foreign (): DWORD QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL QueryPerformanceCounter :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL