From 75c2ef79473cca9df586fe9815ed455a453afaec Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Mar 2020 17:14:24 +0100 Subject: [PATCH] cgen: fix octal and hex int literals --- vlib/builtin/string_test.v | 6 ------ vlib/builtin/utf8_test.v | 7 ++++--- vlib/compiler/tests/struct_test.v | 4 ++-- vlib/v/gen/cgen.v | 16 +++++++++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 80c9c574cc..3173dd28c6 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -99,9 +99,7 @@ fn test_sort() { } fn test_split_nth() { - a := "1,2,3" - println(a) assert (a.split(',').len == 3) assert (a.split_nth(',', -1).len == 3) assert (a.split_nth(',', 0).len == 3) @@ -109,7 +107,6 @@ fn test_split_nth() { assert (a.split_nth(',', 2).len == 2) assert (a.split_nth(',', 10).len == 3) b := "1::2::3" - println(b) assert (b.split('::').len == 3) assert (b.split_nth('::', -1).len == 3) assert (b.split_nth('::', 0).len == 3) @@ -117,19 +114,16 @@ fn test_split_nth() { assert (b.split_nth('::', 2).len == 2) assert (b.split_nth('::', 10).len == 3) c := "ABCDEF" - println(c) println(c.split('').len) assert (c.split('').len == 6) assert (c.split_nth('', 3).len == 3) assert (c.split_nth('BC', -1).len == 2) d := "," - println(d) assert (d.split(',').len == 2) assert (d.split_nth('', 3).len == 1) assert (d.split_nth(',', -1).len == 2) assert (d.split_nth(',', 3).len == 2) e := ",,,0,,,,,a,,b," - println(e) // assert (e.split(',,').len == 5) // assert (e.split_nth(',,', 3).len == 2) assert (e.split_nth(',', -1).len == 12) diff --git a/vlib/builtin/utf8_test.v b/vlib/builtin/utf8_test.v index 356332330c..2181406715 100644 --- a/vlib/builtin/utf8_test.v +++ b/vlib/builtin/utf8_test.v @@ -1,5 +1,6 @@ fn test_utf8_char_len() { - assert utf8_char_len(`a`) == 1 - s := 'п' - assert utf8_char_len(s[0]) == 2 + assert utf8_char_len(`a`) == 1 + println(utf8_char_len(`a`)) + s := 'п' + assert utf8_char_len(s[0]) == 2 } diff --git a/vlib/compiler/tests/struct_test.v b/vlib/compiler/tests/struct_test.v index 2bd123e799..f484cce6af 100644 --- a/vlib/compiler/tests/struct_test.v +++ b/vlib/compiler/tests/struct_test.v @@ -13,7 +13,7 @@ struct CC { mut: b BB nums []int - aarr []A + aarr []AA num int } @@ -82,7 +82,7 @@ fn test_struct_levels() { assert c.b.a.nums[1] == 2 c.b.a.nums [0] = 7 assert c.b.a.nums[0] == 7 - c.aarr << A{val:8} + c.aarr << AA{val:8} assert c.aarr.len == 1 assert c.aarr[0].val == 8 c.num = 20 diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index b733d8a473..e9452e12f1 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -270,14 +270,14 @@ fn (g mut Gen) stmt(node ast.Stmt) { match node { ast.AssertStmt { g.writeln('// assert') - g.write('if (!(') + g.write('if ((') g.expr(it.expr) g.writeln(')) {') - g.writeln('g_test_fails++;') - g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");') - g.writeln('} else {') g.writeln('g_test_oks++;') // g.writeln('puts("OK $g.fn_decl.name");') + g.writeln('} else {') + g.writeln('g_test_fails++;') + g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");') g.writeln('}') } ast.AssignStmt { @@ -952,7 +952,13 @@ fn (g mut Gen) expr(node ast.Expr) { g.infix_expr(it) } ast.IntegerLiteral { - g.write(it.val.int().str()) + if it.val.starts_with('0o') { + g.write('0') + g.write(it.val[2..]) + } + else { + g.write(it.val) // .int().str()) + } } ast.MatchExpr { g.match_expr(it)