From 7f87ac996d76a89eeddda1582db7a5d916f4d318 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 10 Apr 2020 17:26:15 +0800 Subject: [PATCH] test: fix vlib/math/big/big_test.v --- vlib/math/big/big.v | 12 ++++-------- vlib/v/gen/cgen.v | 4 ++-- vlib/v/util/util.v | 3 +++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/vlib/math/big/big.v b/vlib/math/big/big.v index 058cd5cf25..5c06008598 100644 --- a/vlib/math/big/big.v +++ b/vlib/math/big/big.v @@ -2,14 +2,10 @@ module big // Wrapper for https://github.com/kokke/tiny-bignum-c -#flag -I @VROOT/thirdparty/bignum -#flag @VROOT/thirdparty/bignum/bn.o +#flag -I thirdparty/bignum +#flag thirdparty/bignum/bn.o #include "bn.h" -const ( - STRING_BUFFER_SIZE = 8192 -) - pub struct Number { array [32]u32 } @@ -77,8 +73,8 @@ pub fn (n Number) str() string { } pub fn (n Number) hexstr() string { - mut buf := [STRING_BUFFER_SIZE]byte - C.bignum_to_string( &n, buf, STRING_BUFFER_SIZE) + mut buf := [8192]byte + C.bignum_to_string( &n, buf, 8192) // NB: bignum_to_string , returns the HEXADECIMAL representation of the bignum n s := tos_clone( buf ) if s.len == 0 { return '0' } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index a97f06dd3e..bab53411bc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -799,7 +799,7 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) { } else { mut name := it.name c := name[0] - if c in [`+`, `-`, `*`, `/`] { + if c in [`+`, `-`, `*`, `/`, `%`] { name = util.replace_op(name) } if it.is_method { @@ -1439,7 +1439,7 @@ fn (g mut Gen) infix_expr(node ast.InfixExpr) { g.write(',') g.expr(node.right) g.write(')') - } else if node.op in [.plus, .minus, .mul, .div] && (left_sym.name[0].is_capital() || left_sym.name.contains('.')) && + } else if node.op in [.plus, .minus, .mul, .div, .mod] && (left_sym.name[0].is_capital() || left_sym.name.contains('.')) && left_sym.kind != .alias { // !left_sym.is_number() { g.write(g.typ(node.left_type)) diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index fef61901a3..3a6b183011 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -211,6 +211,9 @@ fn replace_op(s string) string { `/` { '_div' } + `%` { + '_mod' + } else { '' }