fix high order fns

pull/1181/head
Alexander Medvednikov 2019-07-16 14:31:08 +02:00
parent 9c586e7e92
commit 54b069f9ad
1 changed files with 9 additions and 5 deletions

View File

@ -759,7 +759,12 @@ fn (p mut Parser) get_type() string {
if debug { if debug {
println('same line getting type') println('same line getting type')
} }
f.typ = p.get_type() if p.tok == .name {
f.typ = p.get_type()
}
else {
f.typ = 'void'
}
// println('fn return typ=$f.typ') // println('fn return typ=$f.typ')
} }
else { else {
@ -1441,7 +1446,6 @@ fn (p mut Parser) name_expr() string {
if f.name == '' { if f.name == '' {
// We are in a second pass, that means this function was not defined, throw an error. // We are in a second pass, that means this function was not defined, throw an error.
if !p.first_run() { if !p.first_run() {
// println('name_expr():')
// If orig_name is a pkg, then printing undefined: `pkg` tells us nothing // If orig_name is a pkg, then printing undefined: `pkg` tells us nothing
// if p.table.known_pkg(orig_name) { // if p.table.known_pkg(orig_name) {
if p.table.known_pkg(orig_name) || p.import_table.known_alias(orig_name) { if p.table.known_pkg(orig_name) || p.import_table.known_alias(orig_name) {
@ -1453,6 +1457,7 @@ fn (p mut Parser) name_expr() string {
} }
} }
p.next() p.next()
// First pass, the function can be defined later.
return 'void' return 'void'
} }
// no () after func, so func is an argument, just gen its name // no () after func, so func is an argument, just gen its name
@ -1484,14 +1489,13 @@ fn (p mut Parser) name_expr() string {
fn (p mut Parser) var_expr(v Var) string { fn (p mut Parser) var_expr(v Var) string {
p.log('\nvar_expr() v.name="$v.name" v.typ="$v.typ"') p.log('\nvar_expr() v.name="$v.name" v.typ="$v.typ"')
// println('var expr is_tmp=$p.cgen.is_tmp\n') // println('var expr is_tmp=$p.cgen.is_tmp\n')
// p.gen('VAR EXPR ')
p.cur_fn.mark_var_used(v) p.cur_fn.mark_var_used(v)
fn_ph := p.cgen.add_placeholder() fn_ph := p.cgen.add_placeholder()
p.expr_var = v p.expr_var = v
p.gen(p.table.var_cgen_name(v.name)) p.gen(p.table.var_cgen_name(v.name))
p.next() p.next()
mut typ := v.typ mut typ := v.typ
// fn_pointer() // Function pointer?
if typ.starts_with('fn ') { if typ.starts_with('fn ') {
println('CALLING FN PTR') println('CALLING FN PTR')
p.print_tok() p.print_tok()