2019-12-29 10:51:55 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import (
|
|
|
|
v.parser
|
|
|
|
v.table
|
2019-12-30 10:30:24 +03:00
|
|
|
v.gen
|
2019-12-29 10:51:55 +03:00
|
|
|
os
|
|
|
|
)
|
|
|
|
|
2019-12-30 08:16:59 +03:00
|
|
|
const (
|
|
|
|
cdefs = '
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
2019-12-30 10:30:24 +03:00
|
|
|
typedef int bool;
|
2019-12-30 08:16:59 +03:00
|
|
|
typedef struct { char* str; } string;
|
|
|
|
typedef double f64;
|
|
|
|
string tos3(char* s) { return (string){ .str = s }; }
|
|
|
|
')
|
|
|
|
|
2019-12-29 10:51:55 +03:00
|
|
|
fn main() {
|
|
|
|
path := os.args[1]
|
|
|
|
println('V2 $path')
|
|
|
|
text := os.read_file(path)?
|
|
|
|
table := &table.Table{}
|
|
|
|
program := parser.parse_file(text, table)
|
2019-12-30 19:05:32 +03:00
|
|
|
res := gen.cgen([program])
|
2019-12-29 10:51:55 +03:00
|
|
|
mut out := os.create('out.c')?
|
2019-12-30 08:16:59 +03:00
|
|
|
out.writeln(cdefs)
|
2019-12-29 10:51:55 +03:00
|
|
|
out.writeln(res)
|
|
|
|
out.close()
|
2019-12-30 08:16:59 +03:00
|
|
|
println('out.c generated')
|
|
|
|
os.system('cc out.c')
|
2019-12-29 10:51:55 +03:00
|
|
|
}
|