| 3576 | } |
| 3577 | |
| 3578 | FUNCTION * function_bind_variables( FUNCTION * f, module_t * module, |
| 3579 | int * counter ) |
| 3580 | { |
| 3581 | if ( f->type == FUNCTION_BUILTIN ) |
| 3582 | return f; |
| 3583 | #ifdef HAVE_PYTHON |
| 3584 | if ( f->type == FUNCTION_PYTHON ) |
| 3585 | return f; |
| 3586 | #endif |
| 3587 | { |
| 3588 | JAM_FUNCTION * func = (JAM_FUNCTION *)f; |
| 3589 | JAM_FUNCTION * new_func = BJAM_MALLOC( sizeof( JAM_FUNCTION ) ); |
| 3590 | instruction * code; |
| 3591 | int i; |
| 3592 | assert( f->type == FUNCTION_JAM ); |
| 3593 | memcpy( new_func, func, sizeof( JAM_FUNCTION ) ); |
| 3594 | new_func->base.reference_count = 1; |
| 3595 | new_func->base.formal_arguments = argument_list_bind_variables( |
| 3596 | f->formal_arguments, f->num_formal_arguments, module, counter ); |
| 3597 | new_func->code = BJAM_MALLOC( func->code_size * sizeof( instruction ) ); |
| 3598 | memcpy( new_func->code, func->code, func->code_size * sizeof( |
| 3599 | instruction ) ); |
| 3600 | new_func->generic = (FUNCTION *)func; |
| 3601 | func = new_func; |
| 3602 | for ( i = 0; ; ++i ) |
| 3603 | { |
| 3604 | OBJECT * key; |
| 3605 | int op_code; |
| 3606 | code = func->code + i; |
| 3607 | switch ( code->op_code ) |
| 3608 | { |
| 3609 | case INSTR_PUSH_VAR: op_code = INSTR_PUSH_VAR_FIXED; break; |
| 3610 | case INSTR_PUSH_LOCAL: op_code = INSTR_PUSH_LOCAL_FIXED; break; |
| 3611 | case INSTR_POP_LOCAL: op_code = INSTR_POP_LOCAL_FIXED; break; |
| 3612 | case INSTR_SET: op_code = INSTR_SET_FIXED; break; |
| 3613 | case INSTR_APPEND: op_code = INSTR_APPEND_FIXED; break; |
| 3614 | case INSTR_DEFAULT: op_code = INSTR_DEFAULT_FIXED; break; |
| 3615 | case INSTR_RETURN: return (FUNCTION *)new_func; |
| 3616 | case INSTR_CALL_MEMBER_RULE: |
| 3617 | case INSTR_CALL_RULE: ++i; continue; |
| 3618 | case INSTR_PUSH_MODULE: |
| 3619 | { |
| 3620 | int depth = 1; |
| 3621 | ++i; |
| 3622 | while ( depth > 0 ) |
| 3623 | { |
| 3624 | code = func->code + i; |
| 3625 | switch ( code->op_code ) |
| 3626 | { |
| 3627 | case INSTR_PUSH_MODULE: |
| 3628 | case INSTR_CLASS: |
| 3629 | ++depth; |
| 3630 | break; |
| 3631 | case INSTR_POP_MODULE: |
| 3632 | --depth; |
| 3633 | break; |
| 3634 | case INSTR_CALL_RULE: |
| 3635 | ++i; |
no test coverage detected