This commit is contained in:
uan
2026-02-04 21:13:22 +01:00
parent ff30ef8153
commit ce51292f7c
5 changed files with 11 additions and 9 deletions

View File

@@ -73,9 +73,8 @@ fn (mut g Generator) gen_expr(expr Expr) {
PrintExpr { PrintExpr {
g.out.write_string('printf(\"%') g.out.write_string('printf(\"%')
format := match expr.type { format := match expr.type {
'int' {'d'} 'int', 'bool' {'d'}
'real' {'lf'} 'real' {'lf'}
'bool' {'d'}
else {panic("Tried printing illegal type")} else {panic("Tried printing illegal type")}
} }
g.out.write_string('${format}\\n\", ') g.out.write_string('${format}\\n\", ')

8
main.v
View File

@@ -7,17 +7,23 @@ fn main() {
content := os.read_file("source.one") or { return } content := os.read_file("source.one") or { return }
println("---------\n" + content + "---------") println("---------\n" + content + "---------")
tokens := lex(content) or { return } tokens := lex(content) or { return }
$if debug {
println("-- TOK --") println("-- TOK --")
print_toks(tokens) print_toks(tokens)
}
mut parser := Parser{ mut parser := Parser{
tokens: tokens tokens: tokens
pos: 0 pos: 0
} }
statements := parser.parse_program() statements := parser.parse_program()
$if debug {
println("-- AST --") println("-- AST --")
println(statements) println(statements)
}
mut generator := Generator{ mut generator := Generator{
out: strings.new_builder(100) out: strings.new_builder(100)
@@ -25,8 +31,6 @@ fn main() {
out_c := generator.gen_c(statements) out_c := generator.gen_c(statements)
println("--- C ---")
println(out_c)
compile_with_clang(out_c, 'test', true) compile_with_clang(out_c, 'test', true)
} }

BIN
one Executable file

Binary file not shown.

View File

@@ -86,7 +86,6 @@ fn (mut s SymbolTable) lookup_func(name string) ?FuncSymbolInfo {
} }
fn (mut s SymbolTable) is_in_global_scope() bool { fn (mut s SymbolTable) is_in_global_scope() bool {
println("scope count: ${s.variable_scopes.len}")
return s.variable_scopes.len == 1 return s.variable_scopes.len == 1
} }

BIN
test

Binary file not shown.