diff --git a/vlib/eventbus/eventbus_test.v b/vlib/eventbus/eventbus_test.v index 1749a0e5be..8c76d77882 100644 --- a/vlib/eventbus/eventbus_test.v +++ b/vlib/eventbus/eventbus_test.v @@ -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){} \ No newline at end of file +fn on_test_2(sender voidptr, p eventbus.Params){} diff --git a/vlib/eventbus/params.v b/vlib/eventbus/params.v index a815938184..1ddbb4aa1d 100644 --- a/vlib/eventbus/params.v +++ b/vlib/eventbus/params.v @@ -96,4 +96,4 @@ fn unmarshall_array (s T, m voidptr) array_T { fn unmarshall_map (s T, m voidptr) map_T { return *(*map_T(m)) -} \ No newline at end of file +} diff --git a/vlib/math/factorial/factorial_test.v b/vlib/math/factorial/factorial_test.v index 539ccb05be..6c2b57575f 100644 --- a/vlib/math/factorial/factorial_test.v +++ b/vlib/math/factorial/factorial_test.v @@ -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) -} \ No newline at end of file +} diff --git a/vlib/compiler2/ast/ast.v b/vlib/v/ast/ast.v similarity index 99% rename from vlib/compiler2/ast/ast.v rename to vlib/v/ast/ast.v index e79c9290b6..e7046ba68c 100644 --- a/vlib/compiler2/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -4,7 +4,7 @@ module ast import ( - compiler2.token + v.token ) diff --git a/vlib/compiler2/cgen/cgen.v b/vlib/v/cgen/cgen.v similarity index 94% rename from vlib/compiler2/cgen/cgen.v rename to vlib/v/cgen/cgen.v index c952a50930..6a65325818 100644 --- a/vlib/compiler2/cgen/cgen.v +++ b/vlib/v/cgen/cgen.v @@ -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() { diff --git a/vlib/compiler2/fmt/fmt.v b/vlib/v/fmt/fmt.v similarity index 100% rename from vlib/compiler2/fmt/fmt.v rename to vlib/v/fmt/fmt.v diff --git a/vlib/compiler2/parser/parser.v b/vlib/v/parser/parser.v similarity index 98% rename from vlib/compiler2/parser/parser.v rename to vlib/v/parser/parser.v index 85fcf20682..cb1d89e98a 100644 --- a/vlib/compiler2/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 { diff --git a/vlib/compiler2/parser/parser_test.v b/vlib/v/parser/parser_test.v similarity index 65% rename from vlib/compiler2/parser/parser_test.v rename to vlib/v/parser/parser_test.v index 933b3d7523..2147e6b19c 100644 --- a/vlib/compiler2/parser/parser_test.v +++ b/vlib/v/parser/parser_test.v @@ -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() } diff --git a/vlib/compiler2/scanner/scanner.v b/vlib/v/scanner/scanner.v similarity index 99% rename from vlib/compiler2/scanner/scanner.v rename to vlib/v/scanner/scanner.v index 86ff4f3dbd..32946c9d3f 100644 --- a/vlib/compiler2/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -5,7 +5,7 @@ module scanner import ( os - compiler2.token + v.token // strings ) diff --git a/vlib/compiler2/scanner/scanner_test.v b/vlib/v/scanner/scanner_test.v similarity index 97% rename from vlib/compiler2/scanner/scanner_test.v rename to vlib/v/scanner/scanner_test.v index 8681251551..29e3e0206d 100644 --- a/vlib/compiler2/scanner/scanner_test.v +++ b/vlib/v/scanner/scanner_test.v @@ -4,7 +4,7 @@ module scanner import ( - compiler2.token + v.token ) fn test_scan() { diff --git a/vlib/compiler2/table/table.v b/vlib/v/table/table.v similarity index 100% rename from vlib/compiler2/table/table.v rename to vlib/v/table/table.v diff --git a/vlib/compiler2/token/token.v b/vlib/v/token/token.v similarity index 100% rename from vlib/compiler2/token/token.v rename to vlib/v/token/token.v