Fix issue where compounds had not enough type information to typecheck

This commit is contained in:
Krzosa Karol
2022-06-14 20:42:32 +02:00
parent 107c8435b7
commit a4513fcdfa
6 changed files with 59 additions and 18 deletions

12
ast.cpp
View File

@@ -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;

View File

@@ -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

View File

@@ -2,9 +2,33 @@
#load "Windows.kl"
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

View File

@@ -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;

View File

@@ -224,7 +224,10 @@ type_struct_complete(Ast_Type *type, Ast_Decl *node){
Array<Ast_Resolved_Member> 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;

14
types.h
View File

@@ -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)