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