Constants in structs
This commit is contained in:
@@ -136,6 +136,7 @@ gen_expr(Ast_Expr *ast){
|
||||
}
|
||||
|
||||
CASE(CALL, Call){
|
||||
// @todo: Reach into map instead of direct lookup
|
||||
if(node->type->kind == TYPE_STRUCT){ // @todo: Should this be type_type maybe???
|
||||
gen("(");
|
||||
gen_simple_decl(node->type, {});
|
||||
@@ -145,9 +146,9 @@ gen_expr(Ast_Expr *ast){
|
||||
For(node->exprs){
|
||||
auto comp = it;
|
||||
if(comp->name){
|
||||
gen("[");
|
||||
gen(".");
|
||||
gen_expr(comp->name);
|
||||
gen("] = ");
|
||||
gen(" = ");
|
||||
}
|
||||
if(comp->index){
|
||||
gen("[");
|
||||
|
||||
@@ -16,7 +16,7 @@ if_stmt :: (cond: int): type
|
||||
|
||||
add_10 :: (size: int): int
|
||||
// @todo: before the generation c pass, each stage should have it's own
|
||||
// tree transformation phase, where it yanks functions etc.
|
||||
// tree transformation phase, where it yanks functions out etc.
|
||||
add_20 :: (new_size: int): int
|
||||
return 20
|
||||
|
||||
|
||||
15
main.cpp
15
main.cpp
@@ -37,11 +37,12 @@
|
||||
/// [x] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int
|
||||
/// [x] - Initial order independence algorithm
|
||||
/// [ ] - Cleanup the mess with constant bindings
|
||||
/// [ ] - Struct calls
|
||||
/// [ ] - Default values in calls
|
||||
/// [ ] - Resolving calls with default values
|
||||
/// [ ] - Resolving calls with named args, with indexed args
|
||||
/// [ ] - Structs
|
||||
/// [x] - Struct calls
|
||||
/// [x] - Default values in calls
|
||||
/// [x] - Resolving calls with default values
|
||||
/// [x] - Resolving calls with named args, with indexed args
|
||||
/// [x] - Structs
|
||||
/// [ ] - Default values in structs???
|
||||
/// [ ] - Enums
|
||||
/// [ ] - For loop
|
||||
/// [ ] - Switch
|
||||
@@ -65,8 +66,8 @@ int main(){
|
||||
|
||||
String result = {};
|
||||
// result = compile_file("order1.kl"_s);
|
||||
result = compile_file("lambdas.kl"_s);
|
||||
// result = compile_file("order2.kl"_s);
|
||||
// result = compile_file("lambdas.kl"_s);
|
||||
result = compile_file("order2.kl"_s);
|
||||
// result = compile_file("globals.kl"_s);
|
||||
printf("%s", result.str);
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ type_incomplete(Ast *ast){
|
||||
function void
|
||||
type_complete(Ast_Resolved_Type *type){
|
||||
if(type->kind == TYPE_COMPLETING){
|
||||
parsing_error(0, "Cyclic type dependency");
|
||||
parsing_error(type->ast->pos, "Cyclic type dependency");
|
||||
}
|
||||
else if(type->kind != TYPE_INCOMPLETE){
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,9 @@ Arena :: struct
|
||||
len : int
|
||||
cap : int
|
||||
|
||||
get_len :: (s: *Arena): int
|
||||
return s.len
|
||||
|
||||
string16: Str16
|
||||
|
||||
String16 :: struct
|
||||
|
||||
@@ -402,6 +402,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
|
||||
assert(name->kind == AST_IDENT);
|
||||
For_It(agg->members, member){
|
||||
if(member->name.str == name->intern_val.str){
|
||||
if(member->kind == AST_CONST) parsing_error(expr->pos, "Initializing a value that is a constant");
|
||||
found = member;
|
||||
found_type = &type->agg.members[agg->members.get_index(&member)];
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user