From f782388148c6be19fc38dcf4b3f9d84300a70870 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 7 Feb 2020 21:29:28 +0100 Subject: [PATCH] v2: minor fixes --- vlib/builtin/array.v | 6 +++--- vlib/builtin/builtin_nix.v | 2 +- vlib/v/checker/checker.v | 3 ++- vlib/v/parser/parser.v | 32 +++++++++++++++++++++++++++----- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 2102c348c3..1d7c54ec37 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -368,10 +368,10 @@ pub fn (b []byte) hex() string { mut ptr := &hex[0] for i := 0; i < b.len; i++ { // QTODO - ptr += C.sprintf(ptr as charptr, '%02x', b[i]) + ptr += C.sprintf(ptr, '%02x', b[i]) } - return hex as string - //return string(hex) + //return hex as string + return string(hex) } // copy copies the `src` byte array elements to the `dst` byte array. diff --git a/vlib/builtin/builtin_nix.v b/vlib/builtin/builtin_nix.v index 4e0d5a50a9..150d819f8b 100644 --- a/vlib/builtin/builtin_nix.v +++ b/vlib/builtin/builtin_nix.v @@ -64,7 +64,7 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool { $if macos { buffer := [100]byteptr nr_ptrs := C.backtrace(buffer, 100) - C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 1) + backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 1) } return true } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 31338aae02..a06ec0cc7c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -157,7 +157,7 @@ pub fn (c &Checker) call_expr(call_expr ast.CallExpr) table.TypeRef { c.error('too few arguments in call to `$fn_name`', call_expr.pos) } else if call_expr.args.len > f.args.len { - c.error('too many arguments in call to `$fn_name`', call_expr.pos) + c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos) } } for i, arg in f.args { @@ -206,6 +206,7 @@ pub fn (c &Checker) selector_expr(selector_expr ast.SelectorExpr) table.TypeRef return c.table.type_ref(table.int_type_idx) } } + .string {} else { c.error('`$typ.typ.name` is not a struct', selector_expr.pos) } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 3d8fa0e54c..33d6e30051 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -466,12 +466,34 @@ pub fn (p mut Parser) name_expr() (ast.Expr,table.TypeRef) { p.check_name() return node,typ } - // fn call + // fn call or type cast if p.peek_tok.kind == .lpar { - println('calling $p.tok.lit') - x,ti2 := p.call_expr() // TODO `node,typ :=` should work - node = x - typ = ti2 + name := p.tok.lit + // type cast. TODO: finish + if name in p.table.type_idxs { + // ['byte', 'string', 'int'] + // SKIP FOR NOW + mut par_d := 0 + for { + if p.tok.kind == .lpar { + par_d++ + } + if p.tok.kind == .rpar { + par_d-- + if par_d == 0 { + p.next() + break + } + } + p.next() + } + } + else { + println('calling $p.tok.lit') + x,ti2 := p.call_expr() // TODO `node,typ :=` should work + node = x + typ = ti2 + } } // struct init else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || p.tok.lit in ['array', 'string', 'ustring', 'mapnode', 'map']) && !p.tok.lit[p.tok.lit.len - 1].is_capital() {