// File: /workspace/github_cpp_makefile_star2_O2/kram[P]kram/./src/vm/vm.cpp
// Function: VM::call(Instruction*, vm::ON)
Value* VM::call(Instruction* ins, vm::ON on) {

	this->env_push();

	// Get the method name or function declaration
	Value* fun = this->name(ins->left[0], on);

	// Result pointer
	Value* res;

	// Function and class methods
	if (fun->type == Type::FUNCTION) {
		// Parse arguments first
		auto arguments = this->run_vector(ins->right);

		// Assign "self" to the parent
		if (on == vm::ON::PUSHED_CLASS) {
			this->name_create("self", this->lib_stack.back());
		}

		// Execute function
		res = fun->exec_method("exec", arguments);

	// Pushed classes (the class has to be fetched from the stack)
	} else if (on == vm::ON::PUSHED_CLASS && fun->type == Type::NAME) {
		Value* top = this->lib_stack.back();

		switch (top->type) {
			case Type::NUMBER:
			case Type::STRING:
			case Type::BOOL:
				res = this->call_builtin(ins, fun);
				break;

			default:
				res = top->exec_method(fun->getString(), this->run_vector(ins->right));
				break;
		}

	// Default action is built in libraries
	} else {
		res = this->call_library(ins);
	}

	this->env_pop();

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x6f98
movq 0x38(%r15), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x71fa
movq %rax, %r14
movl 0x8(%rax), %eax
cmpl $0x5, %eax
jne 0x81de
addq $0x50, %r15
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x40b0
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x8058
leaq 0xc8(%rsp), %rdi
callq 0x42f2
cmpl $0x1, %ebp
jne 0x8178
leaq 0x9533(%rip), %rsi      # 0x1167d
leaq 0x68(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x30f0
movq 0x8(%rbx), %rax
movq -0x8(%rax), %rdx
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x6de0
leaq 0x68(%rsp), %rdi
callq 0x3130
leaq 0x9503(%rip), %rsi      # 0x11682
leaq 0xa8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x30f0
leaq 0x38(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8ee6
leaq 0xa8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
callq 0xbcb2
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x41b6
leaq 0xa8(%rsp), %rdi
callq 0x3130
leaq 0x50(%rsp), %rdi
callq 0x41b6
jmp 0x8288
cmpl $0x1, %ebp
jne 0x820c
cmpl $0x7, %eax
jne 0x820c
movq 0x8(%rbx), %rax
movq -0x8(%rax), %r12
movl 0x8(%r12), %eax
decl %eax
cmpl $0x2, %eax
ja 0x821c
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x8328
jmp 0x8217
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8508
movq %rax, %r14
jmp 0x8288
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0xc030
addq $0x50, %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x40b0
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rsi
callq 0x8058
leaq 0x88(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
callq 0xbcb2
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x41b6
leaq 0x8(%rsp), %rdi
callq 0x42f2
leaq 0x88(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x6f84
movq %r14, %rax
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x41b6
jmp 0x82b5
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x42f2
jmp 0x82c4
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3130
jmp 0x831f
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x82f9
jmp 0x8300
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x41b6
jmp 0x82f1
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3130
jmp 0x8303
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x41b6
jmp 0x831f
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x42f2
movq %rbx, %rdi
callq 0x3390
nop