Writing more real program and squashing bugs
This commit is contained in:
19
Windows.kl
19
Windows.kl
@@ -5,6 +5,7 @@ HMENU :: *void
|
|||||||
HINSTANCE :: *void
|
HINSTANCE :: *void
|
||||||
LPVOID :: *void
|
LPVOID :: *void
|
||||||
SIZE_T :: U64
|
SIZE_T :: U64
|
||||||
|
BOOL :: int
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@@ -14,9 +15,17 @@ MEM_RESERVE :: 2//0x00002000
|
|||||||
MEM_RESET :: 3//0x00080000
|
MEM_RESET :: 3//0x00080000
|
||||||
MEM_RESET_UNDO :: 4//0x1000000
|
MEM_RESET_UNDO :: 4//0x1000000
|
||||||
|
|
||||||
PAGE_EXECUTE :: 1//0x10
|
MEM_DECOMMIT :: 5//0x00004000
|
||||||
PAGE_EXECUTE_READ :: 2//0x20
|
MEM_RELEASE :: 6//0x00008000
|
||||||
PAGE_EXECUTE_READWRITE :: 3//0x40
|
|
||||||
PAGE_EXECUTE_WRITECOPY :: 4//0x80
|
|
||||||
|
|
||||||
VirtualAlloc :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): LPVOID
|
PAGE_NOACCESS :: 1
|
||||||
|
PAGE_READONLY :: 2
|
||||||
|
PAGE_READWRITE :: 4
|
||||||
|
PAGE_WRITECOPY :: 8
|
||||||
|
PAGE_EXECUTE :: 10//0x10
|
||||||
|
PAGE_EXECUTE_READ :: 20//0x20
|
||||||
|
PAGE_EXECUTE_READWRITE :: 30//0x40
|
||||||
|
PAGE_EXECUTE_WRITECOPY :: 40//0x80
|
||||||
|
|
||||||
|
VirtualAlloc :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): LPVOID
|
||||||
|
VirtualFree :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, dwFreeType: DWORD): BOOL
|
||||||
1
ast.cpp
1
ast.cpp
@@ -498,6 +498,7 @@ ast_module_namespace(Token *pos, Ast_Module *module, Intern_String name){
|
|||||||
function Ast_Module *
|
function Ast_Module *
|
||||||
ast_module(Intern_String filename){
|
ast_module(Intern_String filename){
|
||||||
AST_NEW(Module, MODULE, 0, 0);
|
AST_NEW(Module, MODULE, 0, 0);
|
||||||
|
result->parent_scope = 0;
|
||||||
result->kind = AST_MODULE;
|
result->kind = AST_MODULE;
|
||||||
result->name = filename;
|
result->name = filename;
|
||||||
result->module = result;
|
result->module = result;
|
||||||
|
|||||||
41
base.kl
41
base.kl
@@ -1,12 +1,47 @@
|
|||||||
#import "Windows.kl"
|
#import "Windows.kl"
|
||||||
|
|
||||||
|
SizeU :: #strict U64
|
||||||
|
OS_PAGE_SIZE :: 4096
|
||||||
|
|
||||||
OS_Memory :: struct
|
OS_Memory :: struct
|
||||||
commit : U64
|
commit : SizeU
|
||||||
reserve: U64
|
reserve: SizeU
|
||||||
data : *U8
|
data : *U8
|
||||||
|
|
||||||
Arena :: struct
|
Arena :: struct
|
||||||
memory: OS_Memory
|
memory: OS_Memory
|
||||||
alignment: U64
|
alignment: U64
|
||||||
len: U64
|
len: SizeU
|
||||||
|
|
||||||
|
get_align_offset :: (size: SizeU, align: SizeU): SizeU
|
||||||
|
mask := align - 1
|
||||||
|
val := size & mask
|
||||||
|
if val != 0
|
||||||
|
val = align - val
|
||||||
|
return val
|
||||||
|
|
||||||
|
align_up :: (size: SizeU, align: SizeU): SizeU
|
||||||
|
result := size + get_align_offset(size, align)
|
||||||
|
return result
|
||||||
|
|
||||||
|
reserve :: (size: SizeU): OS_Memory
|
||||||
|
result := OS_Memory{reserve=align_up(size, OS_PAGE_SIZE)}
|
||||||
|
result.data = VirtualAlloc(0, result.reserve, MEM_RESERVE, PAGE_READWRITE)->*U8
|
||||||
|
return result
|
||||||
|
|
||||||
|
clamp_top_sizeu :: (val: SizeU, max: SizeU): SizeU
|
||||||
|
if val > max
|
||||||
|
return max
|
||||||
|
return val
|
||||||
|
|
||||||
|
commit :: (m: *OS_Memory, size: SizeU): Bool
|
||||||
|
commit_size := align_up(size, OS_PAGE_SIZE)
|
||||||
|
total_commit := m.commit + commit_size
|
||||||
|
clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
|
||||||
|
adjusted_commit := clamped_commit - m.commit
|
||||||
|
if adjusted_commit != 0
|
||||||
|
result := VirtualFree(m.data->*void, 0, MEM_RELEASE)
|
||||||
|
m.commit += adjusted_commit
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ gen_ast(Ast *ast){
|
|||||||
}
|
}
|
||||||
|
|
||||||
CASE(LAMBDA, Decl){
|
CASE(LAMBDA, Decl){
|
||||||
if(is_flag_set(node->flags, AST_FOREIGN)){
|
if(is_flag_set(node->expr->flags, AST_FOREIGN)){
|
||||||
gen("/*foreign*/");
|
gen("/*foreign*/");
|
||||||
}
|
}
|
||||||
gen_lambda(node->name, node->lambda);
|
gen_lambda(node->name, node->lambda);
|
||||||
@@ -506,7 +506,8 @@ parse_files(Ast_Module *module){
|
|||||||
function void
|
function void
|
||||||
parse_all_modules(){
|
parse_all_modules(){
|
||||||
parsing_time_begin = os_time();
|
parsing_time_begin = os_time();
|
||||||
For(pctx->modules){
|
for(S64 i = 0; i < pctx->modules.len; i++){
|
||||||
|
Ast_Module *it = pctx->modules[i];
|
||||||
parse_files(it);
|
parse_files(it);
|
||||||
it->implicit_imports.add(pctx->builtins);
|
it->implicit_imports.add(pctx->builtins);
|
||||||
}
|
}
|
||||||
|
|||||||
7
main.cpp
7
main.cpp
@@ -41,13 +41,14 @@ want to export all the symbols, we can namespace them optionally.
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
@todo
|
@todo
|
||||||
|
[ ] - Fix field access, cant cast, cant index
|
||||||
|
[ ] - Fix codegen renames
|
||||||
|
[ ] - Add parent_scope to Ast_Type
|
||||||
[ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
|
[ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
|
||||||
[ ] - Switch
|
[ ] - Switch
|
||||||
[ ] - Add c string
|
[ ] - Add c string
|
||||||
[ ] - Some way to take slice of data
|
[ ] - Some way to take slice of data
|
||||||
[ ] - slices should be properly displayed in debugger
|
[ ] - slices should be properly displayed in debugger
|
||||||
[ ] - Rewrite where # happen,
|
|
||||||
[ ] - cast ->
|
|
||||||
[ ] - elif
|
[ ] - elif
|
||||||
|
|
||||||
[ ] - #assert that handles constants at compile time and vars at runtime
|
[ ] - #assert that handles constants at compile time and vars at runtime
|
||||||
@@ -74,6 +75,8 @@ want to export all the symbols, we can namespace them optionally.
|
|||||||
|
|
||||||
@donzo
|
@donzo
|
||||||
[x] - Scope
|
[x] - Scope
|
||||||
|
[x] - Rewrite where # happen,
|
||||||
|
[x] - cast ->
|
||||||
[x] - Remodel compound from call to {}
|
[x] - Remodel compound from call to {}
|
||||||
[x] - Field access rewrite
|
[x] - Field access rewrite
|
||||||
[-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix
|
[-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix
|
||||||
|
|||||||
10
parsing.cpp
10
parsing.cpp
@@ -402,9 +402,9 @@ binding_power(Binding binding, Token_Kind kind){
|
|||||||
case TK_Mod:
|
case TK_Mod:
|
||||||
return {17,18};
|
return {17,18};
|
||||||
case TK_Dot:
|
case TK_Dot:
|
||||||
return {24,23};
|
|
||||||
case TK_Arrow:
|
|
||||||
return {31,30};
|
return {31,30};
|
||||||
|
case TK_Arrow:
|
||||||
|
return {29,28};
|
||||||
default: return {};
|
default: return {};
|
||||||
}
|
}
|
||||||
Postfix: switch(kind){
|
Postfix: switch(kind){
|
||||||
@@ -605,6 +605,7 @@ register_ast_file(Intern_String filename, Ast_Module *module, B32 global_implici
|
|||||||
file = result;
|
file = result;
|
||||||
file->filename = filename;
|
file->filename = filename;
|
||||||
file->module = module;
|
file->module = module;
|
||||||
|
file->parent_scope = 0;
|
||||||
file->file = file; // @warning: self referential!
|
file->file = file; // @warning: self referential!
|
||||||
file->decls = {pctx->heap};
|
file->decls = {pctx->heap};
|
||||||
file->implicit_imports = {pctx->heap};
|
file->implicit_imports = {pctx->heap};
|
||||||
@@ -657,6 +658,8 @@ parse_decl(B32 is_global){
|
|||||||
Ast_Flag flags = 0;
|
Ast_Flag flags = 0;
|
||||||
if(token_match_pound(intern_foreign)){
|
if(token_match_pound(intern_foreign)){
|
||||||
set_flag(flags, AST_FOREIGN);
|
set_flag(flags, AST_FOREIGN);
|
||||||
|
} else if(token_match_pound(intern_strict)){
|
||||||
|
set_flag(flags, AST_STRICT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @note parse struct binding
|
// @note parse struct binding
|
||||||
@@ -685,7 +688,8 @@ parse_decl(B32 is_global){
|
|||||||
if(expr->kind == AST_LAMBDA_EXPR){
|
if(expr->kind == AST_LAMBDA_EXPR){
|
||||||
auto a = (Ast_Lambda *)expr;
|
auto a = (Ast_Lambda *)expr;
|
||||||
if(a->scope || is_flag_set(flags, AST_FOREIGN)){
|
if(a->scope || is_flag_set(flags, AST_FOREIGN)){
|
||||||
set_flag(result->flags, flags);
|
if(is_flag_set(flags, AST_FOREIGN))
|
||||||
|
set_flag(expr->flags, flags);
|
||||||
result->kind = AST_LAMBDA;
|
result->kind = AST_LAMBDA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user