From 891d4304e0bef91add3a001c95234ff3b9d1df4d Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 15 Jun 2022 09:08:10 +0200 Subject: [PATCH] Fix ordering of structs when array type appears, add more windows stuff --- ccodegen.cpp | 2 +- programs/Windows.kl | 47 +++++++-------------------------------------- programs/gdi32.kl | 20 +++++++++++++++++++ programs/main.kl | 8 +++++++- programs/user32.kl | 13 +++++++++++++ typechecking.cpp | 2 ++ 6 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 programs/gdi32.kl create mode 100644 programs/user32.kl diff --git a/ccodegen.cpp b/ccodegen.cpp index 8665694..1d08ff1 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -344,7 +344,7 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){ For(node->exprs){ if(is_struct(node->resolved_type)) - gen("[%s] = ", it->resolved_name.str); + gen(".%s = ", it->resolved_name.str); else if(is_array(node->resolved_type)) gen("[%d] = ", (int)it->resolved_index); gen_expr(it->item); diff --git a/programs/Windows.kl b/programs/Windows.kl index 8c71b5a..9aeff6f 100644 --- a/programs/Windows.kl +++ b/programs/Windows.kl @@ -1,5 +1,6 @@ DWORD :: U32 LPCSTR :: *char +LPCWSTR :: *U16 HWND :: *void HMENU :: *void HINSTANCE :: *void @@ -10,52 +11,18 @@ SIZE_T :: U64 BOOL :: int HANDLE :: *void VOID :: void +HICON :: HANDLE +HCURSOR :: HANDLE +HBRUSH :: HANDLE LPDWORD :: *DWORD +LRESULT :: S64 +WPARAM :: U64 +LPARAM :: S64 BYTE :: U8 // @todo? unsigned char WORD :: S16 // short LONG :: S32 // @todo long UINT :: U32 // @todo uint -RBGQUAD :: struct - rgbBlue: BYTE - rgbGreen: BYTE - rgbRed: BYTE - rgbReserved: BYTE - -BITMAPINFOHEADER :: struct - biSize: DWORD - biWidth: LONG - biHeight: LONG - biPlanes: WORD - biBitCount: WORD - biCompression: DWORD - biSizeImage: DWORD - biXPelsPerMeter: LONG - biYPelsPerMeter: LONG - biClrUsed: DWORD - biClrImportant: DWORD - -BI_RGB :: 0x0000 -BI_RLE8 :: 0x0001 -BI_RLE4 :: 0x0002 -BI_BITFIELDS :: 0x0003 -BI_JPEG :: 0x0004 -BI_PNG :: 0x0005 -BI_CMYK :: 0x000B -BI_CMYKRLE8 :: 0x000C -BI_CMYKRLE4 :: 0x000 -DIB_RGB_COLORS :: 0x00 - -BITMAPINFO :: struct - bmiHeader :: BITMAPINFOHEADER - bmiColors :: [1]RBGQUAD - -// #import #foreign "gdi32.lib" @todo -CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND -GetDC :: #foreign (hWnd: HWND): HDC -CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP -CreateCompatibleDC :: #foreign (hdc: HDC): HDC - MEM_COMMIT :: 0x00001000 MEM_RESERVE :: 0x00002000 MEM_RESET :: 0x00080000 diff --git a/programs/gdi32.kl b/programs/gdi32.kl new file mode 100644 index 0000000..f4302a9 --- /dev/null +++ b/programs/gdi32.kl @@ -0,0 +1,20 @@ +#load "Windows.kl" +RBGQUAD :: struct;; rgbBlue: BYTE; rgbGreen: BYTE; rgbRed: BYTE; rgbReserved: BYTE +BITMAPINFOHEADER :: struct;; biSize: DWORD; biWidth: LONG; biHeight: LONG; biPlanes: WORD; biBitCount: WORD; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: LONG; biYPelsPerMeter: LONG; biClrUsed: DWORD; biClrImportant: DWORD +BITMAPINFO :: struct;; bmiHeader: BITMAPINFOHEADER; bmiColors: [1]RBGQUAD + +BI_RGB :: 0x0000 +BI_RLE8 :: 0x0001 +BI_RLE4 :: 0x0002 +BI_BITFIELDS :: 0x0003 +BI_JPEG :: 0x0004 +BI_PNG :: 0x0005 +BI_CMYK :: 0x000B +BI_CMYKRLE8 :: 0x000C +BI_CMYKRLE4 :: 0x000 +DIB_RGB_COLORS :: 0x00 + + +// #import #foreign "gdi32.lib" @todo +CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP +CreateCompatibleDC :: #foreign (hdc: HDC): HDC diff --git a/programs/main.kl b/programs/main.kl index eb9529f..d6c445f 100644 --- a/programs/main.kl +++ b/programs/main.kl @@ -1,5 +1,6 @@ // #import "base.kl" -#load "Windows.kl" +#load "gdi32.kl" +#load "user32.kl" Vec2I :: struct;; x: S32; y: S32 Vec2 :: struct;; x: F32; y: F32 @@ -34,8 +35,13 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap return result +window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT + if msg == WM_DESTROY + pass + main :: (argc: int, argv: **char): int bitmap := create_bitmap({1280, 720}) + WNDCLASS // memory := os.reserve(size = 10000) // os.commit(&memory, 1000) // os.release(&memory) diff --git a/programs/user32.kl b/programs/user32.kl new file mode 100644 index 0000000..1d78c24 --- /dev/null +++ b/programs/user32.kl @@ -0,0 +1,13 @@ +#load "Windows.kl" +WNDPROC :: (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT +WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int; cbWndExtra: int; hInstance: HINSTANCE; hIcon: HICON; hCursor: HCURSOR; hbrBackground: HBRUSH; lpszMenuName: LPCWSTR; lpszClassName: LPCWSTR + +PostQuitMessage :: #foreign(nExitCode: int) +DefWindowProc :: #foreign (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT +GetDC :: #foreign (hWnd: HWND): HDC +CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND +CreateWindowExW :: #foreign (dwExStyle: DWORD, lpClassName: LPCWSTR, lpWindowName: LPCWSTR, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpPara: LPVOID): HWND + +WM_NULL :: 0x0000;; WM_CREATE :: 0x0001; WM_DESTROY :: 0x0002; WM_MOVE :: 0x0003; WM_SIZE :: 0x0005 +WM_ACTIVATE :: 0x0006;; WA_INACTIVE :: 0; WA_ACTIVE :: 1; WA_CLICKACTIVE :: 2 +WM_SETFOCUS :: 0x0007;; WM_KILLFOCUS :: 0x0008; WM_ENABLE :: 0x000A; WM_SETREDRAW :: 0x000B; WM_SETTEXT :: 0x000C; WM_GETTEXT :: 0x000D; WM_GETTEXTLENGTH :: 0x000E; WM_PAINT :: 0x000F; WM_CLOSE :: 0x0010 \ No newline at end of file diff --git a/typechecking.cpp b/typechecking.cpp index 8f84d7c..d6989ff 100644 --- a/typechecking.cpp +++ b/typechecking.cpp @@ -728,6 +728,8 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){ Operand type = resolve_expr(node->base, AST_CANT_BE_NULL); Operand expr = require_const_int(node->expr, AST_CAN_BE_NULL); if(type.type != type_type) compiler_error(node->pos, "Prefix array operator is only allowed on types"); + + type_complete(type.type_val); if(node->expr){ node->resolved_type = type_array(type.type_val, bigint_as_unsigned(&expr.big_int_val)); } else{