Lambdas are now const while resolving, Aliasing lambdas
This commit is contained in:
@@ -88,7 +88,6 @@ struct Ast_Expr:Ast{
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Ast_Atom: Ast_Expr{
|
struct Ast_Atom: Ast_Expr{
|
||||||
Ast_Decl *resolved_decl;
|
|
||||||
INLINE_VALUE_FIELDS;
|
INLINE_VALUE_FIELDS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ In the future
|
|||||||
- [ ] Cleanup
|
- [ ] Cleanup
|
||||||
- [ ] Remove tuple stuff or cleanup, in the future might replace it with a better implementation
|
- [ ] 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
|
- [ ] 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
|
- [ ] Conditional compilation
|
||||||
- [ ] Expand macros
|
- [ ] Expand macros
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ operand(Ast_Decl *decl){
|
|||||||
result.is_lvalue= decl->kind == AST_CONST ? false : true; // Cant assign to const values
|
result.is_lvalue= decl->kind == AST_CONST ? false : true; // Cant assign to const values
|
||||||
result.value = decl->value;
|
result.value = decl->value;
|
||||||
result.resolved_decl = decl;
|
result.resolved_decl = decl;
|
||||||
if(decl->kind == AST_LAMBDA){
|
|
||||||
result.is_const = false;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,10 +753,16 @@ function void _rewrite_into_const(Ast *node, U64 ast_size, Value value){
|
|||||||
auto ast = (Ast_Atom *)node;
|
auto ast = (Ast_Atom *)node;
|
||||||
assert(ast_size >= sizeof(Ast_Atom));
|
assert(ast_size >= sizeof(Ast_Atom));
|
||||||
set_flag(ast->flags, AST_ATOM);
|
set_flag(ast->flags, AST_ATOM);
|
||||||
|
if(value.type && is_lambda(value.type)){
|
||||||
|
ast->kind = AST_IDENT;
|
||||||
|
ast->value = value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
ast->kind = AST_VALUE;
|
ast->kind = AST_VALUE;
|
||||||
ast->value = value;
|
ast->value = value;
|
||||||
ast->resolved_type = value.type;
|
ast->resolved_type = value.type;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
inside_scope_search(Scope_Search *search, Ast_Scope *scope, int level){
|
inside_scope_search(Scope_Search *search, Ast_Scope *scope, int level){
|
||||||
@@ -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;
|
Ast_Scope *scope = field_access_scope ? field_access_scope : node->parent_scope;
|
||||||
Search_Flag flag = field_access_scope ? SEARCH_ONLY_CURRENT_SCOPE : 0;
|
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;
|
node->resolved_type = node->resolved_decl->type;
|
||||||
|
|
||||||
Operand result = operand(node->resolved_decl);
|
Operand result = operand(node->resolved_decl);
|
||||||
if(result.is_const)
|
if(result.is_const){
|
||||||
rewrite_into_const(node, Ast_Atom, node->resolved_decl->value);
|
rewrite_into_const(node, Ast_Atom, node->resolved_decl->value);
|
||||||
|
node->resolved_decl = decl;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
BREAK();
|
BREAK();
|
||||||
@@ -1891,6 +1903,9 @@ resolve_decl(Ast_Decl *ast){
|
|||||||
|
|
||||||
ast->state = DECL_RESOLVING;
|
ast->state = DECL_RESOLVING;
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// @idea: LAMBDAS maybe get rid of lambdas and replace them with a
|
||||||
|
// marker that signifies whether code
|
||||||
switch(ast->kind){
|
switch(ast->kind){
|
||||||
CASE(LAMBDA, Decl){
|
CASE(LAMBDA, Decl){
|
||||||
Ast_Lambda *lambda = node->lambda;
|
Ast_Lambda *lambda = node->lambda;
|
||||||
@@ -1933,9 +1948,11 @@ resolve_decl(Ast_Decl *ast){
|
|||||||
if(is_flag_set(node->flags, AST_STRICT)){
|
if(is_flag_set(node->flags, AST_STRICT)){
|
||||||
node->type_val = type_copy(pctx->perm, node->type_val);
|
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();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
struct Operand{
|
struct Operand{
|
||||||
INLINE_VALUE_FIELDS;
|
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_const : 1;
|
||||||
U8 is_lvalue : 1;
|
U8 is_lvalue : 1;
|
||||||
U8 pound_strict: 1;
|
U8 pound_strict: 1;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ enum Ast_Type_Kind{
|
|||||||
|
|
||||||
#define VALUE_FIELDS \
|
#define VALUE_FIELDS \
|
||||||
Ast_Type *type; \
|
Ast_Type *type; \
|
||||||
|
Ast_Decl *resolved_decl; \
|
||||||
union{ \
|
union{ \
|
||||||
bool bool_val; \
|
bool bool_val; \
|
||||||
F64 f64_val; \
|
F64 f64_val; \
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ HDC :: *void
|
|||||||
LPVOID :: *void
|
LPVOID :: *void
|
||||||
SIZE_T :: U64
|
SIZE_T :: U64
|
||||||
BOOL :: int
|
BOOL :: int
|
||||||
|
HMODULE :: HANDLE
|
||||||
HANDLE :: *void
|
HANDLE :: *void
|
||||||
VOID :: void
|
VOID :: void
|
||||||
HICON :: HANDLE
|
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
|
WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL
|
||||||
__debugbreak :: #foreign ()
|
__debugbreak :: #foreign ()
|
||||||
|
|
||||||
|
GetModuleHandleA :: #foreign (lpModuleName: LPCSTR): HMODULE
|
||||||
ExitProcess :: #foreign (uExitCode: UINT)
|
ExitProcess :: #foreign (uExitCode: UINT)
|
||||||
GetLastError :: #foreign (): DWORD
|
GetLastError :: #foreign (): DWORD
|
||||||
QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL
|
QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL
|
||||||
|
|||||||
@@ -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
|
Any :: struct
|
||||||
data: *void
|
data: *void
|
||||||
type: Type
|
type: Type
|
||||||
|
|||||||
Reference in New Issue
Block a user