fixing compiler bugs
This commit is contained in:
1
ast.cpp
1
ast.cpp
@@ -196,6 +196,7 @@ How does current declaration order resolver works:
|
||||
enum Ast_Decl_State{
|
||||
DECL_NOT_RESOLVED,
|
||||
DECL_RESOLVED,
|
||||
DECL_RESOLVED_TYPE,
|
||||
DECL_RESOLVING,
|
||||
};
|
||||
|
||||
|
||||
@@ -164,8 +164,11 @@ gen_string_simple_decl(Allocator *a, Ast_Type *ast, String name, Ast_Scope *scop
|
||||
function B32
|
||||
gen_value(Value a){
|
||||
B32 result = true;
|
||||
if(is_enum(a.type))
|
||||
goto integer;
|
||||
switch(a.type->kind){
|
||||
CASE_INT: {
|
||||
integer:
|
||||
Scratch scratch;
|
||||
const char *string = bigint_to_error_string(scratch, &a.big_int_val, 10);
|
||||
gen("%s", string);
|
||||
@@ -768,6 +771,11 @@ typedef struct String{
|
||||
if(it->kind == AST_STRUCT){
|
||||
genln("typedef struct %Q %Q;", it->name, it->name);
|
||||
}
|
||||
|
||||
else if(it->kind == AST_LAMBDA){
|
||||
genln("");
|
||||
gen_lambda(it->name, it->lambda, false);
|
||||
}
|
||||
}
|
||||
|
||||
Scratch scratch;
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
Os :: #import "os.kl"
|
||||
SizeU :: #strict U64
|
||||
|
||||
arena_di: U64
|
||||
|
||||
ALLOCATOR_ACTION :: enum
|
||||
ALLOCATE
|
||||
RESIZE
|
||||
FREE_ALL
|
||||
|
||||
Allocator :: struct
|
||||
proc: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
|
||||
|
||||
Arena :: struct
|
||||
allocator: Allocator
|
||||
di: U64 // @debug_id
|
||||
memory: Os.Memory
|
||||
alignment: U64
|
||||
@@ -33,6 +41,7 @@ arena_init :: (a: *Arena)
|
||||
a.memory = Os.reserve(a.DEFAULT_RESERVE_SIZE)
|
||||
a.alignment = a.DEFAULT_ALIGNMENT
|
||||
a.di = arena_di++
|
||||
a.allocator.proc = arena_allocator_proc
|
||||
|
||||
arena_push_size :: (a: *Arena, size: SizeU): *void
|
||||
generous_size := size + a.alignment
|
||||
@@ -47,3 +56,21 @@ arena_push_size :: (a: *Arena, size: SizeU): *void
|
||||
a.len += size
|
||||
return result
|
||||
|
||||
arena_release :: (a: *Arena)
|
||||
Os.release(&a.memory)
|
||||
|
||||
arena_allocator_proc :: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
|
||||
arena: *Arena = a->*Arena
|
||||
if action == ALLOCATOR_ACTION.ALLOCATE
|
||||
return arena_push_size(arena, size)
|
||||
elif action == ALLOCATOR_ACTION.RESIZE
|
||||
pass
|
||||
elif action == ALLOCATOR_ACTION.FREE_ALL
|
||||
pass
|
||||
else;; assert(false, "Invalid codepath")
|
||||
return 0
|
||||
|
||||
allocate :: (a: *Allocator, size: SizeU): *void
|
||||
return a.proc(a, ALLOCATOR_ACTION.ALLOCATE, size, 0)
|
||||
|
||||
|
||||
|
||||
@@ -4,3 +4,6 @@ main :: (argc: int, argv: **char): int
|
||||
arena: Arena
|
||||
arena_init(&arena)
|
||||
data: *S64 = arena_push_size(&arena, size_of(S64))
|
||||
*data = 10
|
||||
|
||||
arena_release(&arena)
|
||||
@@ -1,4 +1,4 @@
|
||||
#load "Windows.kl"
|
||||
#import "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
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// #import "base.kl"
|
||||
#load "gdi32.kl"
|
||||
#load "user32.kl"
|
||||
#load "os.kl"
|
||||
#import "base.kl"
|
||||
#import "gdi32.kl"
|
||||
#import "user32.kl"
|
||||
#import "os.kl"
|
||||
#import "Windows.kl"
|
||||
|
||||
question_mark16 :: 0x003f
|
||||
String32 :: struct;; str: *U32; len: S64
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#load "Windows.kl"
|
||||
#import "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
|
||||
MSG :: struct;; hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: POINT; lPrivate: DWORD
|
||||
|
||||
@@ -75,12 +75,14 @@ make_sure_types_are_compatible_for_constant_evaluation(Token *pos, Value *a, Val
|
||||
|
||||
function Value
|
||||
compare_values(Token *pos, Token_Kind op, Value a, Value b, bool is_const){
|
||||
if(is_enum(a.type) && (a.type == b.type))
|
||||
goto skip_eval;
|
||||
if(!(is_numeric(a.type) && is_numeric(b.type)))
|
||||
compiler_error(pos, "Constant application of binary %s on values of type %s and %s is not allowed", name(op), docname(a.type), docname(b.type));
|
||||
|
||||
make_sure_types_are_compatible_for_constant_evaluation(pos, &a, &b);
|
||||
|
||||
B32 result = 0;
|
||||
skip_eval: B32 result = 0;
|
||||
if(is_const){
|
||||
switch(a.type->kind){
|
||||
CASE_INT:{
|
||||
@@ -379,7 +381,7 @@ resolve_typespec(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context =
|
||||
|
||||
Operand resolved = resolve_expr(ast, flags, compound_context);
|
||||
if(is_flag_set(flags, RESOLVE_TYPESPEC_COMPLETE))
|
||||
type_complete(resolved.type);
|
||||
type_complete(resolved.type_val);
|
||||
if(resolved.type != type_type)
|
||||
compiler_error(ast->pos, "Expected [Type] got instead %s", docname(resolved.type));
|
||||
return resolved.type_val;
|
||||
@@ -1115,7 +1117,7 @@ resolve_decl(Ast_Decl *ast){
|
||||
value = bigint_as_signed(&op.big_int_val) + 1;
|
||||
} else{
|
||||
it->state = DECL_RESOLVED;
|
||||
op.type = untyped_int;
|
||||
op.type = node->type_val;
|
||||
bigint_init_signed(&op.big_int_val, value);
|
||||
if(is_flag_set(node->flags, AST_FLAG)){
|
||||
value = value << 1;
|
||||
|
||||
@@ -32,7 +32,7 @@ operand(Ast_Decl *decl){
|
||||
result.value = decl->value;
|
||||
if(decl->kind == AST_LAMBDA){
|
||||
result.is_const = false;
|
||||
} else assert(!is_lambda(decl->type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user