| 3751 | } |
| 3752 | |
| 3753 | FUNCTION * function_bind_variables( FUNCTION * f, module_t * module, |
| 3754 | int32_t * counter ) |
| 3755 | { |
| 3756 | if ( f->type == FUNCTION_BUILTIN ) |
| 3757 | return f; |
| 3758 | #ifdef HAVE_PYTHON |
| 3759 | if ( f->type == FUNCTION_PYTHON ) |
| 3760 | return f; |
| 3761 | #endif |
| 3762 | { |
| 3763 | JAM_FUNCTION * func = (JAM_FUNCTION *)f; |
| 3764 | JAM_FUNCTION * new_func = (JAM_FUNCTION *)BJAM_MALLOC( sizeof( JAM_FUNCTION ) ); |
| 3765 | instruction * code; |
| 3766 | int32_t i; |
| 3767 | assert( f->type == FUNCTION_JAM ); |
| 3768 | memcpy( new_func, func, sizeof( JAM_FUNCTION ) ); |
| 3769 | new_func->base.reference_count = 1; |
| 3770 | new_func->base.formal_arguments = argument_list_bind_variables( |
| 3771 | f->formal_arguments, f->num_formal_arguments, module, counter ); |
| 3772 | new_func->code = (instruction *)BJAM_MALLOC( func->code_size * sizeof( instruction ) ); |
| 3773 | memcpy( new_func->code, func->code, func->code_size * sizeof( |
| 3774 | instruction ) ); |
| 3775 | new_func->generic = (FUNCTION *)func; |
| 3776 | func = new_func; |
| 3777 | for ( i = 0; ; ++i ) |
| 3778 | { |
| 3779 | OBJECT * key; |
| 3780 | int32_t op_code; |
| 3781 | code = func->code + i; |
| 3782 | switch ( code->op_code ) |
| 3783 | { |
| 3784 | case INSTR_PUSH_VAR: op_code = INSTR_PUSH_VAR_FIXED; break; |
| 3785 | case INSTR_PUSH_LOCAL: op_code = INSTR_PUSH_LOCAL_FIXED; break; |
| 3786 | case INSTR_POP_LOCAL: op_code = INSTR_POP_LOCAL_FIXED; break; |
| 3787 | case INSTR_SET: op_code = INSTR_SET_FIXED; break; |
| 3788 | case INSTR_APPEND: op_code = INSTR_APPEND_FIXED; break; |
| 3789 | case INSTR_DEFAULT: op_code = INSTR_DEFAULT_FIXED; break; |
| 3790 | case INSTR_RETURN: |
| 3791 | if( code->arg == 1 ) return (FUNCTION *)new_func; |
| 3792 | else continue; |
| 3793 | case INSTR_CALL_MEMBER_RULE: |
| 3794 | case INSTR_CALL_RULE: ++i; continue; |
| 3795 | case INSTR_PUSH_MODULE: |
| 3796 | { |
| 3797 | int32_t depth = 1; |
| 3798 | ++i; |
| 3799 | while ( depth > 0 ) |
| 3800 | { |
| 3801 | code = func->code + i; |
| 3802 | switch ( code->op_code ) |
| 3803 | { |
| 3804 | case INSTR_PUSH_MODULE: |
| 3805 | case INSTR_CLASS: |
| 3806 | ++depth; |
| 3807 | break; |
| 3808 | case INSTR_POP_MODULE: |
| 3809 | --depth; |
| 3810 | break; |
no test coverage detected