multiple expr per print
This commit is contained in:
64
generator.v
64
generator.v
@@ -33,13 +33,13 @@ fn get_type_format(type string) string {
|
||||
}
|
||||
|
||||
fn (mut g Generator) get_print_label(expr Expr) string {
|
||||
return match expr {
|
||||
Variable { expr.name }
|
||||
MemberAccess {
|
||||
"${g.get_print_label(expr.from)}.${expr.member}"
|
||||
}
|
||||
else { "" }
|
||||
return match expr {
|
||||
Variable { expr.name }
|
||||
MemberAccess {
|
||||
"${g.get_print_label(expr.from)}.${expr.member}"
|
||||
}
|
||||
else { "" }
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Generator) get_c_type(typ string) string {
|
||||
@@ -80,7 +80,7 @@ fn (mut g Generator) gen_class_print_func(stmt ClassDecl) {
|
||||
}
|
||||
|
||||
g.out.writeln('for(int i=0; i<indent; i++) printf(" ");')
|
||||
g.out.writeln('printf("}\\n");')
|
||||
g.out.writeln('printf("}\");')
|
||||
g.out.writeln('}')
|
||||
}
|
||||
|
||||
@@ -169,25 +169,37 @@ fn (mut g Generator) gen_expr(expr Expr) {
|
||||
g.out.write_string(')')
|
||||
}
|
||||
PrintExpr {
|
||||
label := g.get_print_label(expr.expr)
|
||||
if g.symbols.lookup_class(expr.type) != none {
|
||||
class_name := mangle_struct(expr.type)
|
||||
if label != "" {
|
||||
g.out.write_string('printf("${label}: ");')
|
||||
}
|
||||
g.out.write_string('print_${class_name}(')
|
||||
g.gen_expr(expr.expr)
|
||||
g.out.write_string(', 0)')
|
||||
} else {
|
||||
g.out.write_string('printf(\"')
|
||||
if label != "" {
|
||||
g.out.write_string('${label}: ')
|
||||
}
|
||||
format := get_type_format(expr.type)
|
||||
g.out.write_string('%${format}\\n\", ')
|
||||
g.gen_expr(expr.expr)
|
||||
g.out.write_string(')')
|
||||
}
|
||||
mut i := 0;
|
||||
for i < expr.exprs.len {
|
||||
inner_expr := expr.exprs[i];
|
||||
expr_type := expr.types[i];
|
||||
label := g.get_print_label(inner_expr);
|
||||
if g.symbols.lookup_class(expr_type) != none {
|
||||
class_name := mangle_struct(expr_type)
|
||||
/*if label != "" {
|
||||
g.out.write_string('${label}: ");')
|
||||
}*/
|
||||
g.out.write_string('print_${class_name}(')
|
||||
g.gen_expr(inner_expr)
|
||||
g.out.write_string(', 0);')
|
||||
} else {
|
||||
g.out.write_string('printf(\"')
|
||||
dump(label);
|
||||
if label != "" {
|
||||
g.out.write_string('${label}')
|
||||
g.out.write_string(': ');
|
||||
}
|
||||
format := get_type_format(expr_type)
|
||||
g.out.write_string('%${format}\", ')
|
||||
g.gen_expr(inner_expr)
|
||||
g.out.write_string(');')
|
||||
}
|
||||
i++;
|
||||
if i < expr.exprs.len {
|
||||
g.out.write_string('printf(\", \");')
|
||||
}
|
||||
}
|
||||
g.out.write_string('printf(\"\\n\");\n')
|
||||
}
|
||||
TypeCast {
|
||||
c_type := g.mangle_if_class(g.get_c_type(expr.type))
|
||||
|
||||
Reference in New Issue
Block a user