From 3344111a034f978888470404645752743da4e374 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 4 Jan 2020 00:06:01 +0100 Subject: [PATCH] minor fixes and cleaning up --- vlib/builtin/array.v | 23 ++--------------------- vlib/compiler/cc.v | 2 +- vlib/compiler/string_expression.v | 7 ++++++- vlib/freetype/freetype.v | 18 ------------------ vlib/uiold/examples/users_gui/users.v | 2 +- vlib/v/gen/tests/1.vv | 8 ++++++++ vlib/v/parser/parser.v | 13 +++++++------ 7 files changed, 25 insertions(+), 48 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index efb262d241..558a9f5a12 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -42,9 +42,7 @@ fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array { data: calloc(cap_ * elm_size) } // TODO Write all memory functions (like memcpy) in V - C.memcpy( -arr.data, -c_array, len * elm_size) + C.memcpy(arr.data, c_array, len * elm_size) return arr } @@ -63,7 +61,7 @@ fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) arra fn (a mut array) ensure_cap(required int) { if required > a.cap { mut cap := if a.cap == 0 { 2 } else { a.cap * 2 } - for required > cap { + for required > cap && true { cap *= 2 } if a.cap == 0 { @@ -76,23 +74,6 @@ fn (a mut array) ensure_cap(required int) { } } -// Private function, used by V (`[0; 100]`) -fn array_repeat_old(val voidptr, nr_repeats, elm_size int) array { - if nr_repeats < 0 { - panic('[0; len]: `len` is negative (len == $nr_repeats)') - } - arr := array{ - len: nr_repeats - cap: nr_repeats - element_size: elm_size - data: calloc(nr_repeats * elm_size) - } - for i := 0; i < nr_repeats; i++ { - C.memcpy(arr.data + i * elm_size, val, elm_size) - } - return arr -} - // array.repeat returns new array with the given array elements // repeated `nr_repeat` times pub fn (a array) repeat(nr_repeats int) array { diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index 542488980e..6af59d65bf 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -441,7 +441,7 @@ fn (c mut V) cc_windows_cross() { mut cmd := '' cmd = '' $if macos { - cmd = 'x86_64-w64-mingw32-gcc $args -municode' + cmd = 'x86_64-w64-mingw32-gcc -std=gnu11 $args -municode' } $else { panic('your platform is not supported yet') diff --git a/vlib/compiler/string_expression.v b/vlib/compiler/string_expression.v index b11f8a1cb8..40ca61784d 100644 --- a/vlib/compiler/string_expression.v +++ b/vlib/compiler/string_expression.v @@ -20,7 +20,12 @@ fn (p mut Parser) string_expr() { */ if (p.calling_c && p.peek() != .dot) || is_cstr || (p.pref.translated && p.mod == 'main') { - p.gen('"$f"') + if p.os == .windows { + p.gen('L"$f"') + } + else { + p.gen('"$f"') + } } else if p.is_sql { p.gen("'$str'") diff --git a/vlib/freetype/freetype.v b/vlib/freetype/freetype.v index 352ea12078..4ca931a745 100644 --- a/vlib/freetype/freetype.v +++ b/vlib/freetype/freetype.v @@ -236,24 +236,6 @@ pub fn new_context(cfg gg.Cfg) &FreeType { return ctx } -/* -// A dirty hack to implement rendering of cyrillic letters. -// All UTF-8 must be supported. update: no longer needed -fn (ctx mut FreeType) init_utf8_runes() { - s := '≈≠⩽⩾йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ' - print('init utf8 runes: ') - //println(s) - us := s.ustring() - for i := 0; i < us.len; i++ { - _rune := us.at(i) - ch := ft_load_char(ctx.face, _rune.utf32_code()) - // ctx.utf_rune_map.set(rune, ch) - ctx.utf_runes << _rune - ctx.utf_chars << ch - } -} -*/ - pub fn (ctx mut FreeType) draw_text(_x, _y int, text string, cfg gx.TextCfg) { //utext := text.ustring_tmp() utext := text.ustring() diff --git a/vlib/uiold/examples/users_gui/users.v b/vlib/uiold/examples/users_gui/users.v index d1891240d2..a3ccdcca07 100644 --- a/vlib/uiold/examples/users_gui/users.v +++ b/vlib/uiold/examples/users_gui/users.v @@ -4,7 +4,7 @@ import ( ui gx os - darwin + //darwin ) const ( diff --git a/vlib/v/gen/tests/1.vv b/vlib/v/gen/tests/1.vv index 6bca86123d..d4d2c1a955 100644 --- a/vlib/v/gen/tests/1.vv +++ b/vlib/v/gen/tests/1.vv @@ -8,6 +8,14 @@ fn main() { c := -a a == 1 foo(3) + /* + user := User{} + user.age = 10 + mut x := if user.age == 10 { 20 } else { user.age * 2 } + for x > 3 { + + } + */ } fn foo(a int) { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 6580bf0273..e06c2cd1eb 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -229,7 +229,7 @@ pub fn (p &Parser) error_at_line(s string, line_nr int) { } pub fn (p &Parser) warn(s string) { - println(term.blue('x.v:$p.tok.line_nr: $s')) + println(term.blue('$p.file_name:$p.tok.line_nr: $s')) } // Implementation of Pratt Precedence @@ -332,7 +332,7 @@ pub fn (p mut Parser) expr(rbp int) (ast.Expr,types.Type) { typ = t2 } else { - p.error('!unknown token ' + p.tok.str()) + p.error('expr(): unknown token ' + p.tok.str() + ' kind=$p.tok.kind') } } } @@ -342,10 +342,9 @@ pub fn (p mut Parser) expr(rbp int) (ast.Expr,types.Type) { p.next() mut t2 := types.Type{} // left denotation (infix / postfix) - if prev_tok.is_right_assoc() && - !p.tok.kind in [.plus, .minus] && // think of better way to handle this - !p.peek_tok.kind in [.number, .name] { // supposed to be only unary, additive handled in left asssoc - + if prev_tok.is_right_assoc() && !p.tok.kind in [.plus, .minus] && // think of better way to handle this + !p.peek_tok.kind in [.number, .name] { + // supposed to be only unary, additive handled in left asssoc mut expr := ast.Expr{} expr,t2 = p.expr(prev_tok.precedence() - 1) node = ast.BinaryExpr{ @@ -460,8 +459,10 @@ fn (p mut Parser) if_expr() (ast.Expr,types.Type) { } mut typ := types.void_type // mut left := ast.Expr{} + // If the last statement is an expression, return its type match stmts[stmts.len - 1] { ast.ExprStmt { + p.warn('if expr ret $it.typ.name') typ = it.typ // return node,it.typ // left =