rename compiler2.parser to v.parser etc

pull/3208/head
Alexander Medvednikov 2019-12-27 05:43:17 +01:00
parent 98b81252b7
commit 14e9c3c7bb
12 changed files with 47 additions and 27 deletions

View File

@ -61,4 +61,4 @@ fn on_test(sender voidptr, p eventbus.Params) {
assert p.get_string("eventbus") == "vevent"
}
fn on_test_2(sender voidptr, p eventbus.Params){}
fn on_test_2(sender voidptr, p eventbus.Params){}

View File

@ -96,4 +96,4 @@ fn unmarshall_array<T> (s T, m voidptr) array_T {
fn unmarshall_map<T> (s T, m voidptr) map_T {
return *(*map_T(m))
}
}

View File

@ -11,4 +11,4 @@ fn test_log_factorial() {
assert fact.log_factorial(12) == math.log(479001600)
assert fact.log_factorial(5) == math.log(120)
assert fact.log_factorial(0) == math.log(1)
}
}

View File

@ -4,7 +4,7 @@
module ast
import (
compiler2.token
v.token
)

View File

@ -2,7 +2,7 @@ module cgen
import (
strings
compiler2.ast
v.ast
)
struct Gen {
@ -10,13 +10,13 @@ struct Gen {
}
pub fn gen(program ast.Program) {
pub fn gen(program ast.Program) string {
mut g := Gen{out:strings.new_builder(100)}
for expr in program.exprs {
g.expr(expr)
g.writeln('')
}
println(g.out.str())
return (g.out.str())
}
pub fn (g &Gen) save() {

View File

@ -4,10 +4,10 @@
module parser
import (
compiler2.scanner
compiler2.ast
compiler2.token
compiler2.table
v.scanner
v.ast
v.token
v.table
)
struct Parser {

View File

@ -1,9 +1,9 @@
module parser
import (
compiler2.ast
compiler2.cgen
compiler2.table
v.ast
v.cgen
v.table
)
@ -55,25 +55,45 @@ fn test_cgen2() {
fn test_cgen() {
//if true { return }
s := [
input := [
'2 + 3',
'2+2*4',
//'(2+2)*4',
'x := 10',
//'x := 10'
'a := 12',
]
output := [
'2 + 3',
'2 + 2 * 4',
//'(2 + 2) * 4',
'int x = 10;',
'int a = 12;',
]
//expr := parse_expr('3 + 7 * 2')
//expr2 := parse_stmt('a := 3 + "f"')
mut e := []ast.Expr
table := &table.Table{}
for ss in s {
//expr2 := parse_expr('x := 10')
//program := ast.Program{
e << parse_expr(ss, table)
//exprs: [
//expr2,
//parse_expr('2 * 2'),
//]
for s in input {
e << parse_expr(s, table)
}
program := ast.Program{exprs:e}
cgen.gen(program)
res := cgen.gen(program)
println('========')
println(res)
println('========')
lines := res.split_into_lines()
mut i := 0
for line in lines {
if line == '' {
continue
}
println('"$line" "${output[i]}"')
assert line == output[i]
i++
if i >= output.len {
break
}
}
//cgen.save()
}

View File

@ -5,7 +5,7 @@ module scanner
import (
os
compiler2.token
v.token
// strings
)

View File

@ -4,7 +4,7 @@
module scanner
import (
compiler2.token
v.token
)
fn test_scan() {