// File: /workspace/github_c_makefile_star2_O3/Liutos[P]Eloquent/vm.c
// Function: vm_execute
void vm_execute(vm_t *vm, ins_t *ins)
{
    value_t *_fun_, *_val_, *_val2_;
    value_t **_addr_; // Used only by BC_ADDR
    vm->ip = 0;
    while (vm_hasnext(vm, ins)) {
        bytecode_t *bc = vm_nextins(vm, ins);
        switch (BC_OPCODE(bc)) {
            case BC_ADDR:
                _addr_ = env_getaddr(vm->env, BC_ADDR_NAME(bc));
                if (_addr_ == NULL)
                    _addr_ = env_getaddr(vm->global_env, BC_ADDR_NAME(bc));
                if (_addr_ == NULL) {
                    stack_push(vm->stack, value_error_newf("Undefined variable: %s", BC_ADDR_NAME(bc)));
                    goto __check_exception;
                }
                stack_push(vm->stack, value_ref_new(_addr_));
                break;
            case BC_ARGS:
                for (int i = BC_ARGS_ARITY(bc) - 1; i >= 0; i--) {
                    value_t *obj = (value_t *)stack_nth(vm->stack, i);
                    env_set(vm->env, NULL, obj);
                }
                stack_shrink(vm->stack, BC_ARGS_ARITY(bc));
                break;
            case BC_ASET:
                _val_ = (value_t *)stack_pop(vm->stack);
                _val2_ = (value_t *)stack_top(vm->stack);
                if (elo_type(_val_) != VALUE_REF) {
                    stack_push(vm->stack, value_error_new("Operand of `valof' must be a reference"));
                    goto __check_exception;
                }
                *VALUE_REF_ADDR(_val_) = _val2_;
                break;
            case BC_CALL:
                _fun_ = (value_t *)stack_pop(vm->stack);
                if (BC_CALL_NARGS(bc) != VALUE_FUNC_ARITY(_fun_)) {
                    stack_push(vm->stack, value_error_newf("Incorrect number of arguments. Expecting %d but get %d ones", VALUE_FUNC_ARITY(_fun_), BC_CALL_NARGS(bc)));
                    break;
                }

                if (VALUE_FUNC_ISBIF(_fun_))
                    vm_execute_bif(vm, _fun_);
                else {
                    vm_trace_callucf(vm, _fun_);
                    vm_save(vm, ins, _fun_);
                    vm->depth++;
                    /* 初始化环境、字节码序列和指令指针 */
                    vm->env = env_new(VALUE_FUNC_ENV(_fun_));
                    vm->denv = env_new(vm->denv);
                    vm->fun = _fun_;
                    ins = VALUE_UCF_CODE(_fun_);
                    vm_goto(vm, 0);
                    /* 开始执行新的字节码指令 */
                }
                break;
__check_exception:
            case BC_CHKEX:
                _val_ = (value_t *)stack_top(vm->stack);
                if (elo_ERRORP(_val_)) {
                    if (!stack_isempty(vm->sys_stack)) {
                        vm_restore(vm, &ins, &_fun_);
                        /* 将运行时错误压回参数栈 */
                        stack_push(vm->stack, _val_);
                    } else
                        return;
                }
                break;
            case BC_DGET:
                _val_ = env_get(vm->denv, BC_DGET_NAME(bc));
                if (_val_ == NULL) {
                    stack_push(vm->stack, value_error_newf("Undefined dynamic variable: %s", BC_DGET_NAME(bc)));
                    goto __check_exception;
                }

                stack_push(vm->stack, _val_);
                break;
            case BC_DSET:
                env_set(vm->denv, BC_DSET_NAME(bc), (value_t *)stack_top(vm->stack));
                break;
            case BC_FJUMP:
                _val_ = (value_t *)stack_pop(vm->stack);
                if (_val_->kind == VALUE_INT && VALUE_INT_VALUE(_val_) == 0)
                    vm_goto(vm, BC_FJUMP_INDEX(bc));
                break;
            case BC_GREF:
                _val_ = env_ref(vm->global_env, BC_REF_I(bc), BC_REF_J(bc));
                if (_val_ == NULL) {
                    stack_push(vm->stack, value_error_newf("Undefined variable: %s", BC_REF_NAME(bc)));
                    goto __check_exception;
                }

                stack_push(vm->stack, _val_);
                break;
            case BC_GSET:
                _val_ = (value_t *)stack_top(vm->stack);
                vm_env_set(vm->global_env, BC_SET_I(bc), BC_SET_J(bc), BC_SET_NAME(bc), _val_);
                break;
            case BC_FUNC:
                _val_ = (value_t *)stack_top(vm->stack);
                VALUE_FUNC_ENV(_val_) = vm->env;
                break;
            case BC_JUMP:
                vm_goto(vm, BC_JUMP_INDEX(bc));
                break;
            case BC_NOPE:
                break;
            case BC_POP:
                stack_pop(vm->stack);
                break;
            case BC_PRINT:
                _val_ = (value_t *)stack_top(vm->stack);
                vm_value_print(vm, _val_);
                break;
            case BC_PUSH:
                stack_push(vm->stack, BC_PUSH_PTR(bc));
                break;
            case BC_RETURN:
                vm->depth--;
                vm_restore(vm, &ins, &_fun_);
                vm_trace_retucf(vm, _fun_, (value_t *)stack_top(vm->stack));
                /* 开始执行旧的字节码指令 */
                break;
            case BC_REF:
                _val_ = env_ref(vm->env, BC_REF_I(bc), BC_REF_J(bc));
                if (_val_ == NULL) {
                    stack_push(vm->stack, value_error_newf("Undefined variable: %s", BC_REF_NAME(bc)));
                    goto __check_exception;
                }

                stack_push(vm->stack, _val_);
                break;
            case BC_SET:
                _val_ = (value_t *)stack_top(vm->stack);
                vm_env_set(vm->env, BC_SET_I(bc), BC_SET_J(bc), BC_SET_NAME(bc), _val_);
                break;
            case BC_TRACE: {
                _val_ = (value_t *)stack_top(vm->stack);
                ident_t *id = BC_TRACE_VAR(bc);
                if (id == NULL) {
                    char name[32] = {0};
                    snprintf(name, sizeof(name), "#<%p>", _val_);
                    id = ident_intern(name);
                }
                hash_table_set(vm->traced_objs, _val_, id);
            }
                break;
            case BC_VALOF:
                _val_ = (value_t *)stack_pop(vm->stack);
                if (elo_type(_val_) != VALUE_REF) {
                    stack_push(vm->stack, value_error_new("Argument of `valof' must be a reference"));
                    goto __check_exception;
                }
                stack_push(vm->stack, *VALUE_REF_ADDR(_val_));
                break;
            default :
                fprintf(stderr, "Not support: %s\n", bc_name(bc));
                exit(0);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x8(%rsp)
movl $0x0, 0x4(%rdi)
cmpq $0x0, 0x10(%rsi)
je 0x3064
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x46bb(%rip), %r13      # 0x7118
movq 0x856c(%rip), %r12      # 0xafd0
xorl %esi, %esi
movq %rbp, %rdi
callq 0x629b
incl 0x4(%rbx)
movq %rax, %r15
movl (%rax), %eax
cmpq $0x15, %rax
ja 0x3073
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x10(%rbx), %rdi
movq 0x8(%r15), %rax
movq (%rax), %rsi
callq 0x57fd
testq %rax, %rax
jne 0x2ab8
movq 0x18(%rbx), %rdi
movq 0x8(%r15), %rax
movq (%rax), %rsi
callq 0x57fd
testq %rax, %rax
je 0x2fca
movq 0x30(%rbx), %r14
movq %rax, %rdi
callq 0x2692
jmp 0x2e1e
movq 0x18(%rbx), %rdi
jmp 0x2c69
movq 0x30(%rbx), %rdi
callq 0x6286
cmpl $0x6, (%rax)
movq 0x30(%rbx), %r14
jne 0x2e03
movq 0x8(%rax), %rax
movq (%rax), %rsi
movq %r14, %rdi
jmp 0x2e7d
movq 0x30(%rbx), %rdi
callq 0x6286
cmpl $0x5, (%rax)
jne 0x2e82
cmpl $0x0, 0x8(%rax)
jne 0x2e82
movl 0x10(%r15), %eax
movl %eax, 0x4(%rbx)
jmp 0x2e82
movq 0x30(%rbx), %rdi
callq 0x62a3
movq %rax, %r14
movq 0x8(%r15), %rdx
testq %rdx, %rdx
jne 0x2b6a
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0x20, %esi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0x45b9(%rip), %rdx      # 0x710e
movq %r14, %rcx
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
callq 0x28f8
movq %rax, %rdx
movq 0x28(%rbx), %rdi
movq %r14, %rsi
callq 0x5cd0
jmp 0x2e82
movq 0x30(%rbx), %rdi
callq 0x62a3
movq 0x18(%rbx), %rdi
jmp 0x2dce
movq 0x30(%rbx), %rdi
callq 0x62a3
movq 0x10(%rbx), %rcx
movq %rcx, 0x18(%rax)
jmp 0x2e82
movq 0x30(%rbx), %rdi
callq 0x6286
jmp 0x2e82
decl (%rbx)
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x3082
movq 0x10(%rsp), %r14
movq 0x30(%rbx), %rdi
callq 0x62a3
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3275
jmp 0x2e82
movq 0x30(%rbx), %rdi
callq 0x62a3
cmpl $0x4, (%rax)
jne 0x2de7
cmpl $0x0, 0xc(%rax)
je 0x2de7
movq 0x20(%rax), %r14
cmpq $0x0, 0x10(%r14)
je 0x2e82
xorl %r15d, %r15d
movq %r14, %rdi
movq %r15, %rsi
callq 0x629b
movq %r12, %rbp
movq %rax, %r12
movq (%rbp), %rdi
leaq 0x4654(%rip), %rsi      # 0x7284
movl %r15d, %edx
xorl %eax, %eax
callq 0x20d0
movq (%rbp), %rsi
movq %r12, %rdi
movq %rbp, %r12
callq 0x4830
movq (%rbp), %rsi
movl $0xa, %edi
callq 0x20a0
incq %r15
cmpq %r15, 0x10(%r14)
ja 0x2c14
jmp 0x2e82
movq 0x10(%rbx), %rdi
movl 0x8(%r15), %esi
movl 0xc(%r15), %edx
callq 0x57b6
movq 0x30(%rbx), %r14
testq %rax, %rax
jne 0x2e1e
movq 0x10(%r15), %rsi
leaq 0x44e2(%rip), %rdi      # 0x7170
jmp 0x2d8e
movq 0x30(%rbx), %rdi
movq 0x8(%r15), %rsi
jmp 0x2e7d
movq 0x30(%rbx), %rdi
callq 0x6286
movq %rax, 0x10(%rsp)
movl 0x8(%r15), %edx
movl 0x10(%rax), %esi
cmpl %esi, %edx
jne 0x2e0c
movq %rax, %r14
cmpl $0x0, 0x8(%rax)
je 0x2e9a
cmpl $0x2, %edx
je 0x3005
cmpl $0x1, %edx
je 0x2fda
testl %edx, %edx
jne 0x307b
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3105
movq 0x8(%rbx), %rdi
callq *0x20(%r14)
jmp 0x3047
movl 0x8(%r15), %r14d
testl %r14d, %r14d
jle 0x2d34
incl %r14d
leal -0x2(%r14), %esi
movq 0x30(%rbx), %rdi
callq 0x6271
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x55ee
decl %r14d
cmpl $0x1, %r14d
ja 0x2d0c
movl 0x8(%r15), %r14d
movq 0x30(%rbx), %rdi
movslq %r14d, %rsi
callq 0x61d1
jmp 0x2e82
movq 0x8(%r15), %r14
movq 0x8(%rbx), %r15
movq 0x30(%rbx), %rdi
callq 0x62a3
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x55ee
jmp 0x2e82
movq 0x8(%rbx), %rdi
movq 0x8(%r15), %rsi
callq 0x574b
movq 0x30(%rbx), %r14
testq %rax, %rax
jne 0x2e1e
movq 0x8(%r15), %rsi
leaq 0x445c(%rip), %rdi      # 0x71ea
xorl %eax, %eax
callq 0x2596
jmp 0x2e36
movq 0x30(%rbx), %rdi
callq 0x6286
movq %rax, %r14
movq 0x30(%rbx), %rdi
callq 0x62a3
cmpl $0x6, (%r14)
jne 0x2e26
movq 0x8(%r14), %rcx
movq %rax, (%rcx)
jmp 0x2e82
movq 0x30(%rbx), %rdi
callq 0x62a3
movq 0x10(%rbx), %rdi
movl 0x8(%r15), %esi
movl 0xc(%r15), %edx
movq 0x10(%r15), %rcx
movq %rax, %r8
callq 0x30d4
jmp 0x2e82
movq (%r12), %rsi
movq %rax, %rdi
callq 0x2755
movq (%r12), %rsi
movl $0xa, %edi
callq 0x20a0
jmp 0x2e82
leaq 0x43ff(%rip), %rdi      # 0x7209
jmp 0x2e31
movq 0x30(%rbx), %r14
leaq 0x4397(%rip), %rdi      # 0x71ae
xorl %eax, %eax
callq 0x2596
movq %r14, %rdi
movq %rax, %rsi
jmp 0x2e7d
movq 0x30(%rbx), %r14
leaq 0x4356(%rip), %rdi      # 0x7187
callq 0x255d
movq %rax, %rsi
movq %r14, %rdi
callq 0x61d6
movq 0x30(%rbx), %rdi
callq 0x62a3
cmpl $0x2, (%rax)
jne 0x2e82
movq %rax, %r14
movq 0x38(%rbx), %rdi
callq 0x62b0
testq %rax, %rax
je 0x3064
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x3082
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x61d6
movq 0x8(%rsp), %rbp
movslq 0x4(%rbx), %rsi
cmpq %rsi, 0x10(%rbp)
ja 0x2a66
jmp 0x3064
movq 0x28(%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5d56
testq %rax, %rax
je 0x2f56
movq %rax, %r15
movq %rbx, %rdi
callq 0x32ee
movq (%r12), %rdi
movl (%rbx), %edx
movq (%r15), %rcx
leaq 0x4394(%rip), %rsi      # 0x7260
xorl %eax, %eax
callq 0x20d0
movl 0x10(%r14), %r15d
movl %r15d, %eax
decl %eax
js 0x2f3c
movq 0x30(%rbx), %rdi
movl %eax, %esi
movl %eax, 0x1c(%rsp)
callq 0x6271
movq (%r12), %rsi
movq %rax, %rdi
callq 0x2755
cmpl $0x0, 0x1c(%rsp)
je 0x2f3c
addl $-0x2, %r15d
movq (%r12), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x4350(%rip), %rdi      # 0x7269
callq 0x2140
movq 0x30(%rbx), %rdi
movl %r15d, %esi
callq 0x6271
movq (%r12), %rsi
movq %rax, %rdi
callq 0x2755
addl $-0x1, %r15d
jb 0x2f04
movq (%r12), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x431b(%rip), %rdi      # 0x726c
callq 0x2140
movq 0x8(%rbx), %rsi
movq 0x38(%rbx), %rdi
callq 0x61d6
movq 0x10(%rbx), %rsi
movq 0x38(%rbx), %rdi
callq 0x61d6
movq 0x38(%rbx), %rdi
movq %rbp, %rsi
callq 0x61d6
movq 0x38(%rbx), %rdi
movslq 0x4(%rbx), %rsi
callq 0x61d6
movq 0x38(%rbx), %rdi
movq %r14, %rsi
callq 0x61d6
incl (%rbx)
movq 0x18(%r14), %rdi
callq 0x556b
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %rdi
callq 0x556b
movq %rax, 0x8(%rbx)
movq %r14, 0x40(%rbx)
movq 0x20(%r14), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x4(%rbx)
jmp 0x2e82
movq 0x30(%rbx), %r14
movq 0x8(%r15), %rax
movq (%rax), %rsi
jmp 0x2c87
movq 0x30(%rbx), %rdi
callq 0x6286
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3105
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq *0x20(%r14)
jmp 0x3047
movq 0x30(%rbx), %rdi
callq 0x6286
movq %rax, %r15
movq 0x30(%rbx), %rdi
callq 0x6286
movq %r12, %rbp
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3105
movq 0x8(%rbx), %rdi
movq %r12, %rsi
movq %rbp, %r12
movq %r15, %rdx
callq *0x20(%r14)
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3275
movq 0x30(%rbx), %rdi
movq %r15, %rsi
jmp 0x2e7d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x21b5
movl %edx, %edi
callq 0x2193