diff --git a/core_ast.cpp b/core_ast.cpp index 7542be8..6bbd43e 100644 --- a/core_ast.cpp +++ b/core_ast.cpp @@ -88,7 +88,6 @@ struct Ast_Expr:Ast{ }; struct Ast_Atom: Ast_Expr{ - Ast_Decl *resolved_decl; INLINE_VALUE_FIELDS; }; diff --git a/core_main.cpp b/core_main.cpp index 5053c4d..8d9572d 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -10,6 +10,14 @@ In the future - [ ] Cleanup - [ ] Remove tuple stuff or cleanup, in the future might replace it with a better implementation - [ ] Add ability to do i: int = 0 inside for loops + - [ ] The fact that symbols from main file get introduced to the loaded files + might be kind of confusing, need to watch out for that + - [ ] You can't alias Lambdas because they are not evaluated as constant. + I used a little simplification where lambdas and structs were marked as such + in parsing I think. BUT Structs work so it's maybe just a little fix of constant + propagation using Operands, where I will need to modify Operand of lambda to + be constant AND rewrite_const to not rewrite a lambda OR SOMETHING, maybe it's cool + dont know. BUT not sure if we wont need to rewrite the idea that Lambdas can be Decls. - [ ] Conditional compilation - [ ] Expand macros diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 4f0a38a..852ba2e 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -72,9 +72,6 @@ operand(Ast_Decl *decl){ result.is_lvalue= decl->kind == AST_CONST ? false : true; // Cant assign to const values result.value = decl->value; result.resolved_decl = decl; - if(decl->kind == AST_LAMBDA){ - result.is_const = false; - } return result; } @@ -756,9 +753,15 @@ function void _rewrite_into_const(Ast *node, U64 ast_size, Value value){ auto ast = (Ast_Atom *)node; assert(ast_size >= sizeof(Ast_Atom)); set_flag(ast->flags, AST_ATOM); - ast->kind = AST_VALUE; - ast->value = value; - ast->resolved_type = value.type; + if(value.type && is_lambda(value.type)){ + ast->kind = AST_IDENT; + ast->value = value; + } + else { + ast->kind = AST_VALUE; + ast->value = value; + ast->resolved_type = value.type; + } } function void @@ -1427,12 +1430,21 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_ Ast_Scope *scope = field_access_scope ? field_access_scope : node->parent_scope; Search_Flag flag = field_access_scope ? SEARCH_ONLY_CURRENT_SCOPE : 0; - node->resolved_decl = resolve_name(scope, node->pos, node->intern_val, flag); + Ast_Decl *decl = resolve_name(scope, node->pos, node->intern_val, flag); + + // Substitute lambda alias + if(decl->kind == AST_CONST && decl->resolved_decl && decl->resolved_decl->kind == AST_LAMBDA){ + decl = decl->resolved_decl; + } + + node->resolved_decl = decl; node->resolved_type = node->resolved_decl->type; Operand result = operand(node->resolved_decl); - if(result.is_const) + if(result.is_const){ rewrite_into_const(node, Ast_Atom, node->resolved_decl->value); + node->resolved_decl = decl; + } return result; BREAK(); @@ -1891,6 +1903,9 @@ resolve_decl(Ast_Decl *ast){ ast->state = DECL_RESOLVING; { + + // @idea: LAMBDAS maybe get rid of lambdas and replace them with a + // marker that signifies whether code switch(ast->kind){ CASE(LAMBDA, Decl){ Ast_Lambda *lambda = node->lambda; @@ -1933,9 +1948,11 @@ resolve_decl(Ast_Decl *ast){ if(is_flag_set(node->flags, AST_STRICT)){ node->type_val = type_copy(pctx->perm, node->type_val); } - } else if(is_lambda(op.value.type)){ - node->kind = AST_LAMBDA; } + + // if(is_lambda(op.type)){ + // node->unique_name = node->resolved_decl->unique_name; + // } BREAK(); } diff --git a/core_typechecking.h b/core_typechecking.h index 04c0f48..8eb7804 100644 --- a/core_typechecking.h +++ b/core_typechecking.h @@ -1,7 +1,9 @@ + struct Operand{ INLINE_VALUE_FIELDS; - Ast_Decl *resolved_decl; + // is_const is used to rewrite the tree and bound + // something to the const name at the end U8 is_const : 1; U8 is_lvalue : 1; U8 pound_strict: 1; diff --git a/core_types.h b/core_types.h index 73cf5cb..89978c4 100644 --- a/core_types.h +++ b/core_types.h @@ -55,6 +55,7 @@ enum Ast_Type_Kind{ #define VALUE_FIELDS \ Ast_Type *type; \ +Ast_Decl *resolved_decl; \ union{ \ bool bool_val; \ F64 f64_val; \ diff --git a/modules/KERNEL32.core b/modules/KERNEL32.core index 89e752a..9ebb3aa 100644 --- a/modules/KERNEL32.core +++ b/modules/KERNEL32.core @@ -10,6 +10,7 @@ HDC :: *void LPVOID :: *void SIZE_T :: U64 BOOL :: int +HMODULE :: HANDLE HANDLE :: *void VOID :: void HICON :: HANDLE @@ -54,6 +55,7 @@ WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfChars WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL __debugbreak :: #foreign () +GetModuleHandleA :: #foreign (lpModuleName: LPCSTR): HMODULE ExitProcess :: #foreign (uExitCode: UINT) GetLastError :: #foreign (): DWORD QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL diff --git a/modules/Language.core b/modules/Language.core index a3bf020..1c3d322 100644 --- a/modules/Language.core +++ b/modules/Language.core @@ -1,20 +1,4 @@ -/* -String :: struct - str: *U8 - len: S64 - -Slice :: struct - data: *void - len : S64 - -*/ - -Dynamic_Array :: struct - data: *void - len : S64 - cap : S64 - Any :: struct data: *void type: Type