string ancora un po' rustiche

This commit is contained in:
uan
2026-02-05 22:30:50 +01:00
parent 078a300c1f
commit 1581ca4928
3 changed files with 35 additions and 11 deletions

View File

@@ -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)
}