cgen: enum
parent
d4ffed89c0
commit
7e930c2a75
|
@ -60,7 +60,6 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||
// println('cgen.stmt()')
|
||||
// g.writeln('//// stmt start')
|
||||
match node {
|
||||
ast.Import {}
|
||||
ast.ConstDecl {
|
||||
for i, field in it.fields {
|
||||
field_type_sym := g.table.get_type_symbol(field.typ)
|
||||
|
@ -69,6 +68,14 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||
g.writeln(';')
|
||||
}
|
||||
}
|
||||
ast.EnumDecl {
|
||||
g.writeln('enum $it.name {')
|
||||
for i, val in it.vals {
|
||||
g.writeln('\t${it.name}_$val, // $i')
|
||||
}
|
||||
g.writeln('}')
|
||||
}
|
||||
ast.Import {}
|
||||
ast.FnDecl {
|
||||
g.reset_tmp_count()
|
||||
g.fn_decl = it // &it
|
||||
|
@ -194,7 +201,7 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
verror('cgen.stmt(): bad node')
|
||||
verror('cgen.stmt(): unhandled node ' + typeof(node))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ typedef struct {
|
|||
int age;
|
||||
} User;
|
||||
|
||||
enum Color {
|
||||
Color_red, // 0
|
||||
Color_green, // 1
|
||||
Color_blue, // 2
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a = 10;
|
||||
a++;
|
||||
|
|
|
@ -11,6 +11,10 @@ struct User {
|
|||
age int
|
||||
}
|
||||
|
||||
enum Color {
|
||||
red green blue
|
||||
}
|
||||
|
||||
/*
|
||||
struct One {
|
||||
two Two
|
||||
|
|
Loading…
Reference in New Issue