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

compiler/lang: add variadic function args support

This commit is contained in:
joe-conigliaro
2019-09-30 20:46:50 +10:00
committed by Alexander Medvednikov
parent 5fb3c0e3a8
commit f7c8e923c0
7 changed files with 158 additions and 32 deletions

View File

@@ -20,9 +20,15 @@ mut:
cflags []CFlag // ['-framework Cocoa', '-lglfw3']
fn_cnt int //atomic
obfuscate bool
varg_access []VargAccess
//names []Name
}
struct VargAccess {
fn_name string
tok_idx int
index int
}
/*
enum NameCategory {
@@ -331,6 +337,10 @@ fn (t mut Table) register_fn(new_fn Fn) {
fn (table &Table) known_type(typ_ string) bool {
mut typ := typ_
// vararg
if typ.starts_with('...') && typ.len > 3 {
typ = typ.right(3)
}
// 'byte*' => look up 'byte', but don't mess up fns
if typ.ends_with('*') && !typ.contains(' ') {
typ = typ.left(typ.len - 1)
@@ -558,6 +568,13 @@ fn (p mut Parser) _check_types(got_, expected_ string, throw bool) bool {
if p.pref.translated {
return true
}
// variadic
if expected.starts_with('...') {
expected = expected.right(3)
}
if got.starts_with('...') {
got = got.right(3)
}
// Allow ints to be used as floats
if got == 'int' && expected == 'f32' {
return true