From dca49e43d933a1221d2b061754e7b8afd19f8ec6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 24 Oct 2019 14:51:22 +0300 Subject: [PATCH] c defs --- vlib/builtin/builtin.v | 5 ----- vlib/builtin/cdefs.v | 13 +++++++++++++ vlib/compiler/enum.v | 1 - vlib/compiler/parser.v | 10 +++++++--- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 vlib/builtin/cdefs.v diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 9f5e07a601..50e60a35dc 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -17,11 +17,6 @@ fn init() { } } -fn C.memcpy(byteptr, byteptr, int) -fn C.memmove(byteptr, byteptr, int) -//fn C.malloc(int) byteptr -fn C.realloc(byteptr, int) byteptr - pub fn exit(code int) { C.exit(code) } diff --git a/vlib/builtin/cdefs.v b/vlib/builtin/cdefs.v new file mode 100644 index 0000000000..775331b5bd --- /dev/null +++ b/vlib/builtin/cdefs.v @@ -0,0 +1,13 @@ +// Copyright (c) 2019 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +module builtin + +fn C.memcpy(byteptr, byteptr, int) +fn C.memmove(byteptr, byteptr, int) +//fn C.malloc(int) byteptr +fn C.realloc(byteptr, int) byteptr + +//fn C.qsort() + diff --git a/vlib/compiler/enum.v b/vlib/compiler/enum.v index 90853ac642..1976145245 100644 --- a/vlib/compiler/enum.v +++ b/vlib/compiler/enum.v @@ -49,7 +49,6 @@ fn (p mut Parser) enum_decl(_enum_name string) { if p.tok == .comma { p.next() } - // TODO free name [memory] val++ } p.table.register_type2(Type { diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 05e4bd7432..afd5f1e02b 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -1264,6 +1264,7 @@ fn (p mut Parser) gen(s string) { // Generate V header from V source fn (p mut Parser) statement(add_semi bool) string { + //p.expected_type = '' if p.returns && !p.is_vweb { p.error('unreachable code') } @@ -1982,6 +1983,8 @@ fn (p mut Parser) get_const_type(name string, is_ptr bool) string { } fn (p mut Parser) get_c_func_type(name string) string { + //p.warn(name + ' ' + p.expected_type) + //} f := Fn { name: name is_c: true @@ -1994,9 +1997,10 @@ fn (p mut Parser) get_c_func_type(name string) string { cfn := p.table.find_fn(name) or { // Not Found? Return 'void*' //return 'cvoid' //'void*' - if false { - p.warn('\ndefine imported C function with ' + - '`fn C.$name([args]) [return_type]`\n') + //if false { + if p.expected_type != '' && p.expected_type != 'void' { + p.warn('\ndefine imported C function with ' + + '`fn C.$name([args]) [return_type]`\n') } return 'void*' }