More work on packages
This commit is contained in:
63
ccodegen.cpp
63
ccodegen.cpp
@@ -4,6 +4,8 @@
|
||||
global S32 global_indent;
|
||||
global S32 is_inside_struct;
|
||||
|
||||
function void gen_ast(Ast *ast);
|
||||
|
||||
function void
|
||||
gen_indent(){
|
||||
for(S32 i = 0; i < global_indent; i++) gen(" ");
|
||||
@@ -172,57 +174,13 @@ gen_expr(Ast_Expr *ast){
|
||||
// BREAK();
|
||||
// }
|
||||
|
||||
CASE(VAR, Decl){
|
||||
gen_ast(node);
|
||||
BREAK();
|
||||
}
|
||||
|
||||
CASE(CALL, Call){
|
||||
// @todo: Reach into map instead of direct lookup
|
||||
if(is_struct(node->type) || is_array(node->type)){
|
||||
if(is_array(node->type)){
|
||||
gen("(Slice){%d, ", node->exprs.len);
|
||||
}
|
||||
gen("(");
|
||||
gen_simple_decl(node->type, {});
|
||||
gen(")");
|
||||
|
||||
gen("{");
|
||||
For(node->exprs){
|
||||
auto comp = it;
|
||||
if(comp->name){
|
||||
gen(".");
|
||||
gen_expr(comp->name);
|
||||
gen(" = ");
|
||||
}
|
||||
if(comp->index){
|
||||
gen("[");
|
||||
gen_expr(comp->index);
|
||||
gen("] = ");
|
||||
}
|
||||
assert(comp->item);
|
||||
gen_expr(comp->item);
|
||||
|
||||
if(!node->exprs.is_last(&it)) gen(", ");
|
||||
}
|
||||
gen("}");
|
||||
if(is_array(node->type)){
|
||||
gen("}");
|
||||
}
|
||||
}
|
||||
else{
|
||||
gen_expr(node->name);
|
||||
gen("(");
|
||||
auto name_for_printf = (Ast_Atom *)node->name;
|
||||
For(node->exprs){
|
||||
// @special_case @todo in the future this should be replaced
|
||||
// with []Any
|
||||
if(intern_printf == name_for_printf->intern_val && &it == node->exprs.data){
|
||||
Ast_Atom *atom = (Ast_Atom *)it->item;
|
||||
assert(atom->kind == AST_VALUE);
|
||||
assert(atom->type == untyped_string);
|
||||
gen("\"%s\"", atom->intern_val.str);
|
||||
}
|
||||
else gen_expr(it->item);
|
||||
if(!node->exprs.is_last(&it)) gen(", ");
|
||||
}
|
||||
gen(")");
|
||||
}
|
||||
unused(node);
|
||||
|
||||
BREAK();
|
||||
}
|
||||
@@ -237,8 +195,6 @@ gen_line(Ast *node){
|
||||
genln("#line %d", node->pos->line+1);
|
||||
}
|
||||
|
||||
function void
|
||||
gen_ast(Ast *ast);
|
||||
function void
|
||||
gen_stmt_scope(Ast_Scope *scope){
|
||||
gen("{");
|
||||
@@ -368,8 +324,7 @@ gen_ast(Ast *ast){
|
||||
gen(")");
|
||||
|
||||
if(lambda->scope) {
|
||||
// gen_stmt_scope(lambda->scope);
|
||||
// @todo stmts
|
||||
gen_stmt_scope(lambda->scope);
|
||||
}
|
||||
else gen(";");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user