Rearrange # flags, Add Windows.kl

This commit is contained in:
Krzosa Karol
2022-06-12 19:41:31 +02:00
parent cd29798c1d
commit 31c2c00452
6 changed files with 24 additions and 52 deletions

10
Windows.kl Normal file
View File

@@ -0,0 +1,10 @@
DWORD :: U32
LPCSTR :: *char
HWND :: *void
HMENU :: *void
HINSTANCE :: *void
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
// @todo: enum #flag

View File

@@ -49,6 +49,7 @@ enum{
AST_FOREIGN = bit_flag(8),
AST_DECL = bit_flag(9),
AST_PACKAGE_LEVEL = bit_flag(10),
AST_FLAG = bit_flag(11),
};
struct Ast{

View File

@@ -162,6 +162,7 @@ Intern_String keyword_enum;
Intern_String intern_void;
Intern_String intern_foreign;
Intern_String intern_strict;
Intern_String intern_flag;
struct Ast_Scope;
@@ -212,6 +213,7 @@ lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l){
intern_foreign = intern_string(&l->interns, "foreign"_s);
intern_strict = intern_string(&l->interns, "strict"_s);
intern_void = intern_string(&l->interns, "void"_s);
intern_flag = intern_string(&l->interns, "flag"_s);
}
function void

View File

@@ -1,6 +1,6 @@
package Memory
Allocator_Kind :: enum
Allocator_Kind :: enum #flag
Null
Arena
Heap :: 4

View File

@@ -31,50 +31,6 @@ For now I don't thing it should be overloadable.
-------------------------------------------------------------------------------
Type resolution cases
CONST :: expr - dont need to handle
make new symbol
val := expr (1)
convert untyped to typed default
check bounds
make new symbol
call(default:type = expr) (1)
val: type = expr (1)
convert untyped to typed based on type
make sure expr.type == type
check bounds
expr == expr (2)
expr * expr (2)
make sure compatible types, floats with ints are ok(convert to float)
if only one of them is typed convert the untyped to typed
if both types typed make sure they are the same
check bounds
!expr
make sure correct type
return bool
compound(expr)
call(expr, expr)
convert untyped to matching typed
check if types match
cast(expr: type)
convert from untyped to typed
convert between typed to other typed
check if types compatible
Stmt:
Return - Expression should match lambda return type
Expr:
Lambda - Arguments, default values should match type
ArrayT - Should match type int and be constant or not at all
Call - Arguments should match type
@todo
[ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
@@ -82,7 +38,10 @@ Expr:
[ ] - Add c string
[ ] - Some way to take slice of data
[ ] - slices should be properly displayed in debugger
[ ] - Rewrite where # happen,
[ ] - cast ->
[ ] - #assert that handles constants at compile time and vars at runtime
[ ] - Comma notation when declaring variables thing1, thing2: S32
[ ] - Array of inferred size
[ ] - Add single line lambda expressions
@@ -90,6 +49,7 @@ Expr:
[ ] - Disable ability to parse inner structs, functions, constants etc. ?
[ ] - Write up on order independent declarations
[ ] - constructor => thing :: (i: S32) -> {i = i, thing = 10}
[ ] - Casting to basic types by call S64(x)
[ ] - Default values in structs??? Should compound stmts bring values from default values?? Maybe not? Whats the alternative
[ ] - Type aliases :: should probably be strictly typed, but assigning constant values should work
@@ -101,7 +61,6 @@ Expr:
[ ] - Rust like enum where you associate values(other structs) with keys
[ ] - Compound that zeros values - .{} , Compound that assumes defaults from struct definition - {}
[ ] - Inject stack traces into the program
[ ] - Rewrite constants to embed lambda, types, structs etc.
[ ] - Conditional compilation #if
@donzo

View File

@@ -562,6 +562,7 @@ function Ast_Decl *
parse_enum(Token *pos){
Scratch scratch;
Ast_Expr *typespec = parse_optional_type();
Token *flag = token_match_pound(intern_flag);
token_match(OPEN_SCOPE);
Ast_Scope *scope = begin_decl_scope(scratch, token_get());
@@ -577,6 +578,7 @@ parse_enum(Token *pos){
token_expect(CLOSE_SCOPE);
Ast_Decl *result = ast_enum(pos, typespec, scope);
if(flag) set_flag(result->flags, AST_FLAG);
return result;
}
@@ -595,13 +597,11 @@ parse_decl(B32 is_global){
}
}
Ast_Flag flags = 0;
Token *tname = token_get();
if(token_match(TK_Identifier, TK_DoubleColon)){
if(token_match_pound(intern_strict)){
set_flag(flags, AST_STRICT);
} else if(token_match_pound(intern_foreign)){
Ast_Flag flags = 0;
if(token_match_pound(intern_foreign)){
set_flag(flags, AST_FOREIGN);
}
@@ -620,7 +620,8 @@ parse_decl(B32 is_global){
if(expr->kind == AST_LAMBDA_EXPR){
auto a = (Ast_Lambda *)expr;
if(a->scope){
if(a->scope || is_flag_set(flags, AST_FOREIGN)){
set_flag(result->flags, flags);
result->kind = AST_LAMBDA;
}
}
@@ -643,7 +644,6 @@ parse_decl(B32 is_global){
if(result){
result->name = tname->intern_val;
set_flag(result->flags, flags);
}
return result;