mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
force C function definitions
This commit is contained in:
@ -1266,7 +1266,7 @@ fn replace_generic_type(gen_type string, ti &TypeInst) string {
|
||||
args_r << replace_generic_type(arg, ti)
|
||||
}
|
||||
mut t := 'fn (' + args_r.join(',') + ')'
|
||||
if ret_t.len > 0 {
|
||||
if ret_t.len > 0 {
|
||||
t += ' ' + replace_generic_type(ret_t, ti)
|
||||
}
|
||||
typ = t
|
||||
@ -1379,7 +1379,7 @@ fn (p mut Parser) register_multi_return_stuct(types []string) string {
|
||||
return typ
|
||||
}
|
||||
|
||||
// save the tokens for the generic funciton body (between `{}`)
|
||||
// save the tokens for the generic funciton body (between `{}`)
|
||||
// the function signature isn't saved, it is reconstructed from Fn
|
||||
fn (p mut Parser) save_generic_tmpl(f mut Fn, pos int) {
|
||||
mut cbr_depth := 1
|
||||
|
@ -1555,8 +1555,6 @@ 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
|
||||
@ -1564,15 +1562,15 @@ fn (p mut Parser) get_c_func_type(name string) string {
|
||||
p.is_c_fn_call = true
|
||||
p.fn_call(mut f, 0, '', '')
|
||||
p.is_c_fn_call = false
|
||||
// Try looking it up. Maybe its defined with "C.fn_name() fn_type",
|
||||
// then we know what type it returns
|
||||
// C functions must be defined with `C.fn_name() fn_type`
|
||||
cfn := p.table.find_fn(name) or {
|
||||
// Not Found? Return 'void*'
|
||||
//return 'cvoid' //'void*'
|
||||
//if p.expected_type != '' && p.expected_type != 'void' {
|
||||
//p.warn('\n e=$p.expected_type define imported C function with ' +
|
||||
//'`fn C.$name([args]) [return_type]`\n')
|
||||
//}
|
||||
// Is the user trying to do `var := C.foo()` or `bar(C.foo())`
|
||||
// without declaring `foo`?
|
||||
// Do not allow it.
|
||||
if !name.starts_with('gl') && !name.starts_with('glad') {
|
||||
p.error('undefined C function `$f.name`\n' +
|
||||
'define it with `fn C.$name([args]) [return_type]`')
|
||||
}
|
||||
return 'void*'
|
||||
}
|
||||
// println("C fn $name has type $cfn.typ")
|
||||
|
@ -89,7 +89,7 @@ pub fn (g mut Gen) generate_elf_footer() {
|
||||
g.write64_at(file_size, g.file_size_pos+8)
|
||||
// Create the binary
|
||||
f := os.create(g.out_name) or { panic(err) }
|
||||
C.chmod(g.out_name.str, 0775)
|
||||
os.chmod(g.out_name, 0775)
|
||||
f.write_bytes(g.buf.data, g.buf.len)
|
||||
f.close()
|
||||
println('x64 elf binary has been successfully generated')
|
||||
|
Reference in New Issue
Block a user