| 3143 | } |
| 3144 | |
| 3145 | void argument_list_push( struct arg_list * formal, int formal_count, |
| 3146 | FUNCTION * function, FRAME * frame, STACK * s ) |
| 3147 | { |
| 3148 | LOL * all_actual = frame->args; |
| 3149 | int i; |
| 3150 | |
| 3151 | for ( i = 0; i < formal_count; ++i ) |
| 3152 | { |
| 3153 | LIST * actual = lol_get( all_actual, i ); |
| 3154 | LISTITER actual_iter = list_begin( actual ); |
| 3155 | LISTITER const actual_end = list_end( actual ); |
| 3156 | int j; |
| 3157 | for ( j = 0; j < formal[ i ].size; ++j ) |
| 3158 | { |
| 3159 | struct argument * formal_arg = &formal[ i ].args[ j ]; |
| 3160 | LIST * value; |
| 3161 | |
| 3162 | switch ( formal_arg->flags ) |
| 3163 | { |
| 3164 | case ARG_ONE: |
| 3165 | if ( actual_iter == actual_end ) |
| 3166 | argument_error( "missing argument", function, frame, |
| 3167 | formal_arg->arg_name ); |
| 3168 | value = list_new( object_copy( list_item( actual_iter ) ) ); |
| 3169 | actual_iter = list_next( actual_iter ); |
| 3170 | break; |
| 3171 | case ARG_OPTIONAL: |
| 3172 | if ( actual_iter == actual_end ) |
| 3173 | value = L0; |
| 3174 | else |
| 3175 | { |
| 3176 | value = list_new( object_copy( list_item( actual_iter ) ) ); |
| 3177 | actual_iter = list_next( actual_iter ); |
| 3178 | } |
| 3179 | break; |
| 3180 | case ARG_PLUS: |
| 3181 | if ( actual_iter == actual_end ) |
| 3182 | argument_error( "missing argument", function, frame, |
| 3183 | formal_arg->arg_name ); |
| 3184 | /* fallthrough */ |
| 3185 | case ARG_STAR: |
| 3186 | value = list_copy_range( actual, actual_iter, actual_end ); |
| 3187 | actual_iter = actual_end; |
| 3188 | break; |
| 3189 | case ARG_VARIADIC: |
| 3190 | return; |
| 3191 | } |
| 3192 | |
| 3193 | type_check( formal_arg->type_name, value, frame, function, |
| 3194 | formal_arg->arg_name ); |
| 3195 | |
| 3196 | if ( formal_arg->index != -1 ) |
| 3197 | { |
| 3198 | LIST * * const old = &frame->module->fixed_variables[ |
| 3199 | formal_arg->index ]; |
| 3200 | stack_push( s, *old ); |
| 3201 | *old = value; |
| 3202 | } |
no test coverage detected