| 3657 | */ |
| 3658 | |
| 3659 | LIST * function_run( FUNCTION * function_, FRAME * frame, STACK * s ) |
| 3660 | { |
| 3661 | JAM_FUNCTION * function; |
| 3662 | instruction * code; |
| 3663 | LIST * l; |
| 3664 | LIST * r; |
| 3665 | LIST * result = L0; |
| 3666 | void * saved_stack = s->data; |
| 3667 | |
| 3668 | if ( function_->type == FUNCTION_BUILTIN ) |
| 3669 | { |
| 3670 | BUILTIN_FUNCTION const * const f = (BUILTIN_FUNCTION *)function_; |
| 3671 | if ( function_->formal_arguments ) |
| 3672 | argument_list_check( function_->formal_arguments, |
| 3673 | function_->num_formal_arguments, function_, frame ); |
| 3674 | return f->func( frame, f->flags ); |
| 3675 | } |
| 3676 | |
| 3677 | #ifdef HAVE_PYTHON |
| 3678 | else if ( function_->type == FUNCTION_PYTHON ) |
| 3679 | { |
| 3680 | PYTHON_FUNCTION * f = (PYTHON_FUNCTION *)function_; |
| 3681 | return call_python_function( f, frame ); |
| 3682 | } |
| 3683 | #endif |
| 3684 | |
| 3685 | assert( function_->type == FUNCTION_JAM ); |
| 3686 | |
| 3687 | if ( function_->formal_arguments ) |
| 3688 | argument_list_push( function_->formal_arguments, |
| 3689 | function_->num_formal_arguments, function_, frame, s ); |
| 3690 | |
| 3691 | function = (JAM_FUNCTION *)function_; |
| 3692 | code = function->code; |
| 3693 | for ( ; ; ) |
| 3694 | { |
| 3695 | switch ( code->op_code ) |
| 3696 | { |
| 3697 | |
| 3698 | /* |
| 3699 | * Basic stack manipulation |
| 3700 | */ |
| 3701 | |
| 3702 | case INSTR_PUSH_EMPTY: |
| 3703 | stack_push( s, L0 ); |
| 3704 | break; |
| 3705 | |
| 3706 | case INSTR_PUSH_CONSTANT: |
| 3707 | { |
| 3708 | OBJECT * value = function_get_constant( function, code->arg ); |
| 3709 | stack_push( s, list_new( object_copy( value ) ) ); |
| 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | case INSTR_PUSH_ARG: |
| 3714 | stack_push( s, frame_get_local( frame, code->arg ) ); |
| 3715 | break; |
| 3716 |
no test coverage detected