3 expr_parse.pir - parse an expression and dispatch function calls with their appropriate arguments.
9 .sub 'setup_global_parsing_tokens' :init :load :anon
11 $P0 = 'MKAY end of statement marker'
12 store_global 'MKAY', $P0
16 .param pmc tokens :slurpy
19 t_iter = new 'Iterator', tokens
23 .local pmc arity_stack
25 sub_stack = new 'ResizablePMCArray'
26 val_stack = new 'ResizablePMCArray'
27 arity_stack = new 'ResizableIntegerArray'
30 mkay = find_name 'MKAY'
32 unless t_iter goto it_done
34 .local pmc sub_to_call
37 unless_null item, not_found
40 $I0 = isntsame item, mkay
41 if $I0 goto check_type
43 sub_to_call = pop sub_stack
44 $I0 = shift arity_stack
45 args_array = new 'ResizablePMCArray'
48 $I0 = issame $P1, mkay
49 if $I0 goto call_the_sub
50 unshift args_array, $P1
55 unless $I0 goto has_val
57 $I2 = $P0['pos_slurpy']
58 unless $I2 goto no_slurpy
60 unshift arity_stack, -1
66 unshift arity_stack, $I1
77 unless $I0 == 0 goto skip_call
78 sub_to_call = pop sub_stack
79 $I1 = sub_to_call.arity()
80 args_array = new 'ResizablePMCArray'
82 if $I1 == 0 goto args_loop_end
85 unshift args_array, $P1
88 $I2 = shift arity_stack
90 $P2 = sub_to_call(args_array :flat)
99 $I0 = elements sub_stack
100 if $I0 == 0 goto no_leftover_function
101 sub_to_call = pop sub_stack
102 args_array = new 'ResizablePMCArray'
103 $P2 = new 'Iterator', val_stack
104 getting_more_varargs:
105 $I1 = elements val_stack
106 unless $I1 goto got_more_varargs
108 $I0 = issame $P1, mkay
109 if $I0 goto got_more_varargs
110 unshift args_array, $P1
111 goto getting_more_varargs
113 $P0 = sub_to_call(args_array :flat)
115 no_leftover_function:
116 .local pmc return_val
117 return_val = pop val_stack
124 if_null $P0, null_token
134 # vim: expandtab shiftwidth=4 ft=pir: