-
This commit is contained in:
@@ -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\", ')
|
||||||
|
|||||||
16
main.v
16
main.v
@@ -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 }
|
||||||
println("-- TOK --")
|
|
||||||
print_toks(tokens)
|
$if debug {
|
||||||
|
println("-- TOK --")
|
||||||
|
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()
|
||||||
|
|
||||||
println("-- AST --")
|
$if debug {
|
||||||
println(statements)
|
println("-- AST --")
|
||||||
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
parser.v
1
parser.v
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user