From a4513fcdfadf8983132848f8b0ac7d59f62577a0 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 14 Jun 2022 20:42:32 +0200 Subject: [PATCH] Fix issue where compounds had not enough type information to typecheck --- ast.cpp | 12 ------------ programs/Windows.kl | 12 ++++++++++++ programs/main.kl | 30 +++++++++++++++++++++++++++--- typechecking.cpp | 4 +++- typechecking.h | 5 ++++- types.h | 14 +++++++++++++- 6 files changed, 59 insertions(+), 18 deletions(-) diff --git a/ast.cpp b/ast.cpp index f510586..3352196 100644 --- a/ast.cpp +++ b/ast.cpp @@ -77,18 +77,6 @@ struct Ast_Expr:Ast{ }; }; -#define VALUE_FIELDS \ -Ast_Type *type; \ -union{ \ - bool bool_val; \ - F64 f64_val; \ - Intern_String intern_val; \ - BigInt big_int_val;\ - Ast_Type *type_val; \ -}; -#define INLINE_VALUE_FIELDS union{Value value; struct{VALUE_FIELDS};} -struct Value{VALUE_FIELDS}; - struct Ast_Atom: Ast_Expr{ Ast_Decl *resolved_decl; INLINE_VALUE_FIELDS; diff --git a/programs/Windows.kl b/programs/Windows.kl index e8b2478..655948e 100644 --- a/programs/Windows.kl +++ b/programs/Windows.kl @@ -35,10 +35,22 @@ BITMAPINFOHEADER :: struct 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 + 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 diff --git a/programs/main.kl b/programs/main.kl index d67cc84..a122f9b 100644 --- a/programs/main.kl +++ b/programs/main.kl @@ -1,10 +1,34 @@ // #import "base.kl" #load "Windows.kl" -Vec2I :: struct ;; x: S32; y: S32 +Vec2I :: struct;; x: S32; y: S32 +Vec2 :: struct;; x: F32; y: F32 + +Windows_Bitmap :: struct + size: Vec2I + hdc: HDC + dib: HBITMAP + +create_bitmap :: (size: Vec2I, bottom_up: Bool) + bitmap: Windows_Bitmap = {size = size} + if bottom_up == false + bitmap.size.y = -bitmap.size.y + + hdc := GetDC(0) + bminfo := BITMAPINFO{ + bmiHeader = BITMAPINFOHEADER{ + biSize = size_of(BITMAPINFOHEADER), + biWidth = size.x->LONG, + biHeight = size.y->LONG, + biPlanes = 1, + biBitCount = 32, + biCompression = BI_RGB, + biXPelsPerMeter = 1, + biYPelsPerMeter = 1, + } + } + -create_bitmap :: (size: Vec2I) - pass main :: (argc: int, argv: **char): int pass diff --git a/typechecking.cpp b/typechecking.cpp index e6c3527..c26a485 100644 --- a/typechecking.cpp +++ b/typechecking.cpp @@ -605,7 +605,9 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){ if(it->name){ For_Named(type->agg.members, m){ if(it->name->intern_val == m.name){ - item_type = m.type; + if(m.type == type_type) + item_type = m.type_val; + else item_type = m.type; if(m.visited){ compiler_error(it->pos, "Field already initialized"); } else m.visited = true; diff --git a/typechecking.h b/typechecking.h index 9424952..3b86f50 100644 --- a/typechecking.h +++ b/typechecking.h @@ -224,7 +224,10 @@ type_struct_complete(Ast_Type *type, Ast_Decl *node){ Array members = {scratch}; For(node->scope->decls){ resolve_decl(it); - members.add({it->type, it->name}); + Ast_Resolved_Member m = {}; + m.name = it->name; + m.value = it->value; + members.add(m); } type->agg.members = members.tight_copy(pctx->perm); type->kind = TYPE_STRUCT; diff --git a/types.h b/types.h index 5461847..c65cd6e 100644 --- a/types.h +++ b/types.h @@ -51,13 +51,25 @@ enum Ast_Type_Kind{ #define CASE_STRING case TYPE_UNTYPED_STRING: case TYPE_STRING: case TYPE_POINTER #define CASE_UNTYPED case TYPE_UNTYPED_INT: case TYPE_UNTYPED_BOOL: case TYPE_UNTYPED_FLOAT: case TYPE_UNTYPED_STRING +#define VALUE_FIELDS \ +Ast_Type *type; \ +union{ \ + bool bool_val; \ + F64 f64_val; \ + Intern_String intern_val; \ + BigInt big_int_val;\ + Ast_Type *type_val; \ +}; +#define INLINE_VALUE_FIELDS union{Value value; struct{VALUE_FIELDS};} +struct Value{VALUE_FIELDS}; + struct Ast; struct Ast_Type; struct Ast_Resolved_Member{ - Ast_Type *type; Intern_String name; U64 offset; B32 visited; + INLINE_VALUE_FIELDS; }; #define ARRAY_SIZE_SLICE (-1)