parser: second batch of start_tmp()
parent
00b3557ce1
commit
887c94d9ba
|
@ -1317,13 +1317,12 @@ fn (p mut Parser) fn_call_vargs(f Fn) (string, []string) {
|
|||
if p.tok == .comma {
|
||||
p.check(.comma)
|
||||
}
|
||||
p.cgen.start_tmp()
|
||||
mut varg_type := p.bool_expression()
|
||||
varg_value := p.cgen.end_tmp()
|
||||
varg_type, varg_value := p.tmp_expr()
|
||||
if varg_type.starts_with('varg_') &&
|
||||
(values.len > 0 || p.tok == .comma) {
|
||||
(values.len > 0 || p.tok == .comma)
|
||||
{
|
||||
p.error('You cannot pass additional vargs when forwarding vargs to another function/method')
|
||||
}
|
||||
}
|
||||
if !f.is_generic {
|
||||
p.check_types(last_arg.typ, varg_type)
|
||||
} else {
|
||||
|
|
|
@ -65,8 +65,7 @@ fn (p mut Parser) for_st() {
|
|||
p.check(.key_in)
|
||||
p.fspace()
|
||||
tmp := p.get_tmp()
|
||||
p.cgen.start_tmp()
|
||||
mut typ := p.bool_expression()
|
||||
mut typ, expr := p.tmp_expr()
|
||||
is_arr := typ.starts_with('array_')
|
||||
is_map := typ.starts_with('map_')
|
||||
is_str := typ == 'string'
|
||||
|
@ -74,7 +73,6 @@ fn (p mut Parser) for_st() {
|
|||
if !is_arr && !is_str && !is_map && !is_variadic_arg {
|
||||
p.error('cannot range over type `$typ`')
|
||||
}
|
||||
expr := p.cgen.end_tmp()
|
||||
if !is_variadic_arg {
|
||||
if p.is_js {
|
||||
p.genln('var $tmp = $expr;')
|
||||
|
@ -125,18 +123,16 @@ fn (p mut Parser) for_st() {
|
|||
p.check(.key_in)
|
||||
p.fspace()
|
||||
tmp := p.get_tmp()
|
||||
p.cgen.start_tmp()
|
||||
mut typ := p.bool_expression()
|
||||
expr := p.cgen.end_tmp()
|
||||
mut typ, expr := p.tmp_expr()
|
||||
is_range := p.tok == .dotdot
|
||||
is_variadic_arg := typ.starts_with('varg_')
|
||||
mut range_end := ''
|
||||
if is_range {
|
||||
p.check_types(typ, 'int')
|
||||
p.check_space(.dotdot)
|
||||
p.cgen.start_tmp()
|
||||
p.check_types(p.bool_expression(), 'int')
|
||||
range_end = p.cgen.end_tmp()
|
||||
range_typ, range_expr := p.tmp_expr()
|
||||
p.check_types(range_typ, 'int')
|
||||
range_end = range_expr
|
||||
}
|
||||
is_arr := typ.contains('array')
|
||||
is_str := typ == 'string'
|
||||
|
|
|
@ -2649,9 +2649,9 @@ fn (p mut Parser) return_st() {
|
|||
types << expr_type
|
||||
for p.tok == .comma {
|
||||
p.check(.comma)
|
||||
p.cgen.start_tmp()
|
||||
types << p.bool_expression()
|
||||
mr_values << p.cgen.end_tmp().trim_space()
|
||||
typ, expr := p.tmp_expr()
|
||||
types << typ
|
||||
mr_values << expr.trim_space()
|
||||
}
|
||||
mut cur_fn_typ_chk := p.cur_fn.typ
|
||||
// multiple returns
|
||||
|
@ -2804,9 +2804,8 @@ fn (p mut Parser) js_decode() string {
|
|||
p.check(.lpar)
|
||||
typ := p.get_type()
|
||||
p.check(.comma)
|
||||
p.cgen.start_tmp()
|
||||
p.check_types(p.bool_expression(), 'string')
|
||||
expr := p.cgen.end_tmp()
|
||||
styp, expr := p.tmp_expr()
|
||||
p.check_types(styp, 'string')
|
||||
p.check(.rpar)
|
||||
tmp := p.get_tmp()
|
||||
cjson_tmp := p.get_tmp()
|
||||
|
@ -2816,7 +2815,7 @@ fn (p mut Parser) js_decode() string {
|
|||
for field in T.fields {
|
||||
def_val := type_default(field.typ)
|
||||
if def_val != '' {
|
||||
decl += '$tmp . $field.name = OPTION_CAST($field.typ) $def_val;\n'
|
||||
decl += '${tmp}.$field.name = OPTION_CAST($field.typ) $def_val;\n'
|
||||
}
|
||||
}
|
||||
p.gen_json_for_type(T)
|
||||
|
@ -2831,11 +2830,9 @@ fn (p mut Parser) js_decode() string {
|
|||
}
|
||||
else if op == 'encode' {
|
||||
p.check(.lpar)
|
||||
p.cgen.start_tmp()
|
||||
typ := p.bool_expression()
|
||||
typ, expr := p.tmp_expr()
|
||||
T := p.table.find_type(typ)
|
||||
p.gen_json_for_type(T)
|
||||
expr := p.cgen.end_tmp()
|
||||
p.check(.rpar)
|
||||
p.gen('json__json_print(json__jsencode_$typ($expr))')
|
||||
return 'string'
|
||||
|
|
|
@ -135,9 +135,11 @@ fn get_foo() Foo {
|
|||
|
||||
// This used to be broken.
|
||||
fn test_ref_fn_arg() {
|
||||
process_foo(get_foo())
|
||||
println(3434)
|
||||
assert true
|
||||
$if !tinyc {
|
||||
process_foo(get_foo())
|
||||
println(3434)
|
||||
assert true
|
||||
}
|
||||
|
||||
/*
|
||||
res := (time.random().calc_unix())
|
||||
|
|
Loading…
Reference in New Issue