1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: first step to require explicit definition of imported C fns

This commit is contained in:
Alexander Medvednikov 2019-09-19 05:16:25 +03:00
parent 13e4c79f58
commit cb31eeec55
4 changed files with 13 additions and 2 deletions

View File

@ -1582,6 +1582,10 @@ fn (p mut Parser) name_expr() 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')
}
return 'void*'
}
return cfn.typ

View File

@ -33,6 +33,7 @@ pub fn _make(len, cap, elm_size int) array {
return new_array(len, cap, elm_size)
}
// Private function, used by V (`nums := [1, 2, 3]`)
fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array {
arr := array {

View File

@ -4,6 +4,12 @@
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
pub fn exit(code int) {
C.exit(code)
}

View File

@ -4,8 +4,6 @@
module math
#include <math.h>
// NOTE
// When adding a new function, please make sure it's in the right place.
// All functions are sorted alphabetically.
@ -51,6 +49,8 @@ pub fn abs(a f64) f64 {
return a
}
fn C.acos(a f64) f64
// acos calculates inverse cosine (arccosine).
pub fn acos(a f64) f64 {
return C.acos(a)