Union type sizing and code generation

This commit is contained in:
Krzosa Karol
2023-03-29 09:52:24 +02:00
parent b572f4ef7c
commit 9b91f77cf0
4 changed files with 98 additions and 57 deletions

View File

@@ -725,36 +725,37 @@ gen_ast(Ast *ast) {
BREAK();
}
CASE(STRUCT, Decl) {
gen("struct ");
gen("%Q{", node->unique_name);
global_indent++;
is_inside_struct++;
For(node->scope->decls) {
genln("");
gen_ast(it);
case AST_UNION:
CASE(STRUCT, Decl) {
gen("%s ", node->kind == AST_STRUCT ? "struct" : "union");
gen("%Q{", node->unique_name);
global_indent++;
is_inside_struct++;
For(node->scope->decls) {
genln("");
gen_ast(it);
}
is_inside_struct--;
global_indent--;
genln("};");
BREAK();
}
is_inside_struct--;
global_indent--;
genln("};");
BREAK();
}
CASE(ENUM, Decl) {
gen("/*enum %Q{", node->name);
// @todo add typespec
global_indent++;
For(node->scope->decls) {
genln("%Q", it->name);
gen(" = ");
gen_value(it->pos, it->value);
gen(",");
CASE(ENUM, Decl) {
gen("/*enum %Q{", node->name);
// @todo add typespec
global_indent++;
For(node->scope->decls) {
genln("%Q", it->name);
gen(" = ");
gen_value(it->pos, it->value);
gen(",");
}
global_indent--;
genln("};*/");
BREAK();
}
global_indent--;
genln("};*/");
BREAK();
}
case AST_TYPE:
CASE(CONST, Decl) {
@@ -888,6 +889,9 @@ compile_to_c_code() {
if (it->kind == AST_STRUCT) {
genln("typedef struct %Q %Q;", it->unique_name, it->unique_name);
}
else if (it->kind == AST_UNION) {
genln("typedef union %Q %Q;", it->unique_name, it->unique_name);
}
}
// Generate slice and tuple types