From 71b5b0d9553a40d8ae7b7b123040e6f36dab7aa8 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Sat, 29 Feb 2020 17:24:28 +1100 Subject: [PATCH] v2: fix C fn calls, save C fns with prefix besides odd cases --- vlib/v/parser/fn.v | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index ebf67a5a18..5aaaf9df4e 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -11,7 +11,11 @@ import ( pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { tok := p.tok name := p.check_name() - fn_name := if mod.len > 0 { '${mod}.$name' } else { name } + // these fns are are not defined as C functions, but are v fns and have no C prefix + // but for some reason are called with the C pefix. for now add exception until fixed + v_fns_called_with_c_prefix := ['exit', 'calloc', 'free'] + fn_name := if is_c && !(name in v_fns_called_with_c_prefix) {'C.$name' } + else if mod.len > 0 { '${mod}.$name' } else { name } p.check(.lpar) args, muts := p.call_args() node := ast.CallExpr{ @@ -152,10 +156,9 @@ fn (p mut Parser) fn_decl() ast.FnDecl { } } else { - // TODO: prefix c fuctions with C. - // since v1 does not currently it sees - // `fn C.free` and `fn free` as the same - if !is_c { + if is_c { + name = 'C.$name' + } else { name = p.prepend_mod(name) } p.table.register_fn(table.Fn{