Cleanup
This commit is contained in:
5
main.cpp
5
main.cpp
@@ -32,13 +32,13 @@ For now I don't thing it should be overloadable.
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
@todo
|
||||
[ ] - Init statements, different kinds [+=] [-=] etc.
|
||||
[ ] - lvalue, rvalue concept so we cant assign value to some arbitrary weird expression
|
||||
[ ] - More operators
|
||||
[ ] - More for loop variations
|
||||
[ ] - Fixing access to constants, in C we cant have constants inside of structs / functions so we need to rewrite the tree
|
||||
[ ] - Default values in structs??? Should compound stmts bring values from default values?? Maybe not? Whats the alternative
|
||||
[ ] - Write up on order independent declarations
|
||||
[ ] - Order independent declarations in structs
|
||||
[ ] - Switch
|
||||
[ ] - More basic types
|
||||
[ ] - Array of inferred size
|
||||
@@ -46,13 +46,14 @@ For now I don't thing it should be overloadable.
|
||||
[ ] - Add single line lambda expressions
|
||||
|
||||
@ideas
|
||||
|
||||
[ ] - Using keyword that brings in the struct enviroment into current scope etc.
|
||||
|
||||
@donzo
|
||||
[x] - Access through struct names to constants Arena.CONSTANT
|
||||
[x] - Enums
|
||||
[x] - Initial for loop
|
||||
[x] - Enum . access to values
|
||||
[x] - Init statements, different kinds [+=] [-=] etc.
|
||||
[x] - Struct calls
|
||||
[x] - Default values in calls
|
||||
[x] - Resolving calls with default values
|
||||
|
||||
18
order2.kl
18
order2.kl
@@ -43,15 +43,29 @@ pointer := &with_type
|
||||
deref := *pointer
|
||||
|
||||
|
||||
test_stmts :: ()
|
||||
test_assignments :: ()
|
||||
i := 0
|
||||
i += 4
|
||||
i -= 1
|
||||
i *= 2
|
||||
i /= 2
|
||||
i %= 2
|
||||
i = 2
|
||||
i &= 2
|
||||
i |= 2
|
||||
i >>= 2
|
||||
i <<= 2
|
||||
|
||||
i + 4 = 32
|
||||
8 = 32
|
||||
j: *int
|
||||
*j = 1
|
||||
/* invalid
|
||||
i += "String"
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for
|
||||
pass
|
||||
|
||||
@@ -189,41 +189,26 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
||||
assert(is_flag_set(ast->flags, AST_EXPR));
|
||||
|
||||
switch(ast->kind){
|
||||
CASE(INT, Atom){
|
||||
Operand result = {type_int, true};
|
||||
result.int_val = node->int_val;
|
||||
return result;
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(STR, Atom){
|
||||
Operand result = {type_string, true};
|
||||
result.intern_val = node->intern_val;
|
||||
return result;
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(INT, Atom){return operand_int(node->int_val); BREAK();}
|
||||
CASE(STR, Atom){return operand_str(node->intern_val); BREAK();}
|
||||
CASE(IDENT, Atom){
|
||||
Sym *sym = resolve_name(node->pos, node->intern_val);
|
||||
|
||||
Operand result = {};
|
||||
// @note: check if null and rewrite the expression to match the expected type
|
||||
if(sym->type->kind == TYPE_NULL){
|
||||
if(!expected_type) parsing_error(node->pos, "Couldn't infer type of null");
|
||||
result.type = expected_type;
|
||||
result.is_const = true;
|
||||
return operand_null(expected_type);
|
||||
}
|
||||
else if(sym->kind == SYM_CONST && sym->type != type_type && sym->type->kind != TYPE_LAMBDA){
|
||||
result = operand(sym);
|
||||
rewrite_into_const(node, Ast_Atom, sym);
|
||||
return operand(sym);
|
||||
}
|
||||
else if(sym->kind == SYM_VAR || sym->kind == SYM_CONST){
|
||||
result = operand(sym);
|
||||
sym_associate(node, sym);
|
||||
return operand(sym);
|
||||
}
|
||||
else invalid_codepath;
|
||||
|
||||
return result;
|
||||
invalid_return;
|
||||
BREAK();
|
||||
}
|
||||
|
||||
|
||||
31
typecheck.h
31
typecheck.h
@@ -122,7 +122,8 @@ struct Sym{
|
||||
|
||||
struct Operand{
|
||||
Ast_Resolved_Type *type;
|
||||
bool is_const;
|
||||
bool is_const: 1;
|
||||
bool is_lvalue: 1;
|
||||
INLINE_VALUE_FIELDS;
|
||||
};
|
||||
|
||||
@@ -288,6 +289,34 @@ operand_type(Ast_Resolved_Type *type){
|
||||
return result;
|
||||
}
|
||||
|
||||
function Operand
|
||||
operand_int(S64 int_val){
|
||||
Operand result = {};
|
||||
result.type = type_int;
|
||||
result.int_val = int_val;
|
||||
result.is_const = true;
|
||||
result.is_lvalue = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Operand
|
||||
operand_str(Intern_String intern_val){
|
||||
Operand result = {};
|
||||
result.type = type_string;
|
||||
result.intern_val = intern_val;
|
||||
result.is_const = true;
|
||||
result.is_lvalue = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Operand
|
||||
operand_null(Ast_Resolved_Type *type){
|
||||
Operand result = {};
|
||||
result.type = type;
|
||||
result.is_const = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type constructors and utillities
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user