string ancora un po' rustiche
This commit is contained in:
@@ -27,6 +27,7 @@ fn get_type_format(type string) string {
|
||||
return match type {
|
||||
'int', 'bool' {'d'}
|
||||
'real' {'f'}
|
||||
'string' {'s'}
|
||||
else {panic("invalid type to print")}
|
||||
}
|
||||
}
|
||||
@@ -45,6 +46,7 @@ fn (mut g Generator) get_c_type(typ string) string {
|
||||
return match typ {
|
||||
'real' {'float'}
|
||||
'int' {'int32_t'}
|
||||
'string' {'char*'}
|
||||
else {typ}
|
||||
}
|
||||
}
|
||||
@@ -150,6 +152,9 @@ fn (mut g Generator) gen_expr(expr Expr) {
|
||||
BoolLiteral {
|
||||
g.out.write_string(expr.val.str())
|
||||
}
|
||||
StringLiteral {
|
||||
g.out.write_string('\"${expr.val}\"')
|
||||
}
|
||||
Variable {
|
||||
g.out.write_string(mangle_var(expr.name))
|
||||
}
|
||||
@@ -231,6 +236,7 @@ fn (mut g Generator) gen_c(program []Stmt) string {
|
||||
g.out.writeln('#include <stdio.h>')
|
||||
g.out.writeln('#include <stdbool.h>')
|
||||
g.out.writeln('#include <stdint.h>')
|
||||
//g.out.writeln('typedef struct __one_string_builtin__ {\nchar* string;\nint len;\n} string;')
|
||||
for stmt in program {
|
||||
g.gen_stmt(stmt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user