Fix error when using default argument

This commit is contained in:
Krzosa Karol
2022-06-14 21:16:17 +02:00
parent a4513fcdfa
commit 44ee0f4351
3 changed files with 26 additions and 14 deletions

View File

@@ -44,18 +44,17 @@ BI_PNG :: 0x0005
BI_CMYK :: 0x000B BI_CMYK :: 0x000B
BI_CMYKRLE8 :: 0x000C BI_CMYKRLE8 :: 0x000C
BI_CMYKRLE4 :: 0x000 BI_CMYKRLE4 :: 0x000
DIB_RGB_COLORS :: 0x00
BITMAPINFO :: struct BITMAPINFO :: struct
bmiHeader :: BITMAPINFOHEADER bmiHeader :: BITMAPINFOHEADER
bmiColors :: [1]RBGQUAD bmiColors :: [1]RBGQUAD
// #import #foreign "gdi32.lib" @todo // #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 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 GetDC :: #foreign (hWnd: HWND): HDC
CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP
CreateCompatibleDC :: (hdc: HDC): HDC CreateCompatibleDC :: #foreign (hdc: HDC): HDC
MEM_COMMIT :: 0x00001000 MEM_COMMIT :: 0x00001000
MEM_RESERVE :: 0x00002000 MEM_RESERVE :: 0x00002000

View File

@@ -6,17 +6,17 @@ Vec2 :: struct;; x: F32; y: F32
Windows_Bitmap :: struct Windows_Bitmap :: struct
size: Vec2I size: Vec2I
data: *U32
hdc: HDC hdc: HDC
dib: HBITMAP dib: HBITMAP
create_bitmap :: (size: Vec2I, bottom_up: Bool) create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
bitmap: Windows_Bitmap = {size = size} result: Windows_Bitmap = {size = size}
if bottom_up == false if bottom_up == false
bitmap.size.y = -bitmap.size.y result.size.y = -result.size.y
hdc := GetDC(0)
bminfo := BITMAPINFO{ bminfo := BITMAPINFO{
bmiHeader = BITMAPINFOHEADER{ BITMAPINFOHEADER{
biSize = size_of(BITMAPINFOHEADER), biSize = size_of(BITMAPINFOHEADER),
biWidth = size.x->LONG, biWidth = size.x->LONG,
biHeight = size.y->LONG, biHeight = size.y->LONG,
@@ -28,10 +28,14 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool)
} }
} }
hdc := GetDC(0)
result.dib = CreateDIBSection(hdc, &bminfo, DIB_RGB_COLORS, &result.data->**void, 0, 0)
result.hdc = CreateCompatibleDC(hdc)
return result
main :: (argc: int, argv: **char): int main :: (argc: int, argv: **char): int
pass bitmap := create_bitmap({1280, 720})
// memory := os.reserve(size = 10000) // memory := os.reserve(size = 10000)
// os.commit(&memory, 1000) // os.commit(&memory, 1000)
// os.release(&memory) // os.release(&memory)

View File

@@ -605,9 +605,12 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){
if(it->name){ if(it->name){
For_Named(type->agg.members, m){ For_Named(type->agg.members, m){
if(it->name->intern_val == m.name){ if(it->name->intern_val == m.name){
// @copy_paste
if(m.type == type_type) if(m.type == type_type)
item_type = m.type_val; item_type = m.type_val;
else item_type = m.type; else item_type = m.type;
if(m.visited){ if(m.visited){
compiler_error(it->pos, "Field already initialized"); compiler_error(it->pos, "Field already initialized");
} else m.visited = true; } else m.visited = true;
@@ -622,7 +625,13 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){
compiler_error(it->pos, "Cant mix named fields and normal fields"); compiler_error(it->pos, "Cant mix named fields and normal fields");
if(default_counter >= type->agg.members.len) if(default_counter >= type->agg.members.len)
compiler_error(it->pos, "Too many struct initializers"); compiler_error(it->pos, "Too many struct initializers");
item_type = type->agg.members[default_counter++].type;
// @copy_paste
item_type = type->agg.members[default_counter].type;
if(item_type == type_type)
item_type = type->agg.members[default_counter].type_val;
default_counter+=1;
} }
assert(item_type); assert(item_type);
@@ -919,13 +928,11 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
S64 default_iter = 0; S64 default_iter = 0;
Ast_Lambda *lambda = (Ast_Lambda *)name.type->ast; Ast_Lambda *lambda = (Ast_Lambda *)name.type->ast;
for(S64 i = 0; i < lambda->args.len; i++){ For_Named(lambda->args, lambda_arg){
Ast_Decl *lambda_arg = lambda->args[i];
assert(lambda_arg->type); assert(lambda_arg->type);
Ast_Call_Item *item = 0; Ast_Call_Item *item = 0;
For(node->exprs){ For(node->exprs){
if(it->name){ if(it->name){
Ast_Atom *name = it->name; Ast_Atom *name = it->name;
assert(name->kind == AST_IDENT); assert(name->kind == AST_IDENT);
@@ -953,7 +960,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
else{ else{
// @note: default values are typechecked when they get resolved // @note: default values are typechecked when they get resolved
if(lambda_arg->expr){ if(lambda_arg->expr){
items.add(ast_call_item(lambda_arg->expr->pos, 0, 0, lambda_arg->expr)); Ast_Call_Item *call_item = ast_call_item(lambda_arg->expr->pos, 0, 0, lambda_arg->expr);
set_flag(call_item->flags, AST_ITEM_INCLUDED);
items.add(call_item);
} }
else compiler_error(lambda_arg->pos, "Required value in lambda call was not passed"); else compiler_error(lambda_arg->pos, "Required value in lambda call was not passed");
} }