Constants in structs

This commit is contained in:
Krzosa Karol
2022-05-30 13:44:10 +02:00
parent 55fd4ca40c
commit 0e0b95ab52
6 changed files with 17 additions and 11 deletions

View File

@@ -136,6 +136,7 @@ gen_expr(Ast_Expr *ast){
} }
CASE(CALL, Call){ CASE(CALL, Call){
// @todo: Reach into map instead of direct lookup
if(node->type->kind == TYPE_STRUCT){ // @todo: Should this be type_type maybe??? if(node->type->kind == TYPE_STRUCT){ // @todo: Should this be type_type maybe???
gen("("); gen("(");
gen_simple_decl(node->type, {}); gen_simple_decl(node->type, {});
@@ -145,9 +146,9 @@ gen_expr(Ast_Expr *ast){
For(node->exprs){ For(node->exprs){
auto comp = it; auto comp = it;
if(comp->name){ if(comp->name){
gen("["); gen(".");
gen_expr(comp->name); gen_expr(comp->name);
gen("] = "); gen(" = ");
} }
if(comp->index){ if(comp->index){
gen("["); gen("[");

View File

@@ -16,7 +16,7 @@ if_stmt :: (cond: int): type
add_10 :: (size: int): int add_10 :: (size: int): int
// @todo: before the generation c pass, each stage should have it's own // @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 add_20 :: (new_size: int): int
return 20 return 20

View File

@@ -37,11 +37,12 @@
/// [x] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int /// [x] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int
/// [x] - Initial order independence algorithm /// [x] - Initial order independence algorithm
/// [ ] - Cleanup the mess with constant bindings /// [ ] - Cleanup the mess with constant bindings
/// [ ] - Struct calls /// [x] - Struct calls
/// [ ] - Default values in calls /// [x] - Default values in calls
/// [ ] - Resolving calls with default values /// [x] - Resolving calls with default values
/// [ ] - Resolving calls with named args, with indexed args /// [x] - Resolving calls with named args, with indexed args
/// [ ] - Structs /// [x] - Structs
/// [ ] - Default values in structs???
/// [ ] - Enums /// [ ] - Enums
/// [ ] - For loop /// [ ] - For loop
/// [ ] - Switch /// [ ] - Switch
@@ -65,8 +66,8 @@ int main(){
String result = {}; String result = {};
// result = compile_file("order1.kl"_s); // result = compile_file("order1.kl"_s);
result = compile_file("lambdas.kl"_s); // result = compile_file("lambdas.kl"_s);
// result = compile_file("order2.kl"_s); result = compile_file("order2.kl"_s);
// result = compile_file("globals.kl"_s); // result = compile_file("globals.kl"_s);
printf("%s", result.str); printf("%s", result.str);

View File

@@ -162,7 +162,7 @@ type_incomplete(Ast *ast){
function void function void
type_complete(Ast_Resolved_Type *type){ type_complete(Ast_Resolved_Type *type){
if(type->kind == TYPE_COMPLETING){ 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){ else if(type->kind != TYPE_INCOMPLETE){
return; return;

View File

@@ -11,6 +11,9 @@ Arena :: struct
len : int len : int
cap : int cap : int
get_len :: (s: *Arena): int
return s.len
string16: Str16 string16: Str16
String16 :: struct String16 :: struct

View File

@@ -402,6 +402,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *const_sym){
assert(name->kind == AST_IDENT); assert(name->kind == AST_IDENT);
For_It(agg->members, member){ For_It(agg->members, member){
if(member->name.str == name->intern_val.str){ 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 = member;
found_type = &type->agg.members[agg->members.get_index(&member)]; found_type = &type->agg.members[agg->members.get_index(&member)];
break; break;