// File: kram[P]kram/./src/vm/value.cpp
// Function: Value::exec_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<Value*, std::allocator<Value*>>)
Value* Value::exec_method(std::string name, std::vector<Value*> val) {

	if (this->type != Type::REFERENCE && this->type != Type::FUNCTION && this->type != Type::CLASS) {
		std::cout << "Can not execute method '" << name << "': Parent is not of type REFERENCE, CLASS, or FUNCTION\n";
		std::cout << this->print() << "\n";	
		exit(0);
	}

	if (this->type == Type::CLASS) {
		std::cout << "Value::exec_method() Should not be used together with Type::CLASS. This is an error, please report it! :)\n";
		exit(0);
	}

	if (this->type == Type::FUNCTION) {
		return this->data.single_method(this, val);
	}

	if (this->data.methods->find(name) == this->data.methods->end()) {
		std::cout << "UNKNOWN METHOD: " << name << "\n";
		exit(0);
	}

	Method m = this->data.methods->at(name);

	return m(this, val);
}

// Assembly:
subq $0xf8, %rsp
movq %rsi, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movq %rdx, 0xd8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpl $0x4, 0x8(%rax)
je 0x1e24e
movq 0x58(%rsp), %rax
cmpl $0x5, 0x8(%rax)
je 0x1e24e
movq 0x58(%rsp), %rax
cmpl $0x6, 0x8(%rax)
je 0x1e24e
movq 0x1be33(%rip), %rdi     # 0x39fd8
movq %rdi, 0x30(%rsp)
leaq 0xdc2d(%rip), %rsi      # 0x2bdde
callq 0x32d0
movq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x32a0
movq %rax, %rdi
leaq 0xdc2a(%rip), %rsi      # 0x2bdf7
callq 0x32d0
movq 0x58(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
xorl %edx, %edx
callq 0x1e430
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x32a0
movq %rax, 0x40(%rsp)
jmp 0x1e201
movq 0x40(%rsp), %rdi
leaq 0xd654(%rip), %rsi      # 0x2b861
callq 0x32d0
jmp 0x1e214
leaq 0xb8(%rsp), %rdi
callq 0x31f0
xorl %edi, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x31f0
jmp 0x1e41d
movq 0x58(%rsp), %rax
cmpl $0x6, 0x8(%rax)
jne 0x1e273
movq 0x1bd78(%rip), %rdi     # 0x39fd8
leaq 0xdbc8(%rip), %rsi      # 0x2be2f
callq 0x32d0
xorl %edi, %edi
callq 0x3330
movq 0x58(%rsp), %rax
cmpl $0x5, 0x8(%rax)
jne 0x1e303
movq 0x58(%rsp), %rax
movq 0x50(%rsp), %rsi
movq (%rax), %rax
movq %rax, 0x20(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x14280
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rax
callq *%rax
movq %rax, 0x28(%rsp)
jmp 0x1e2be
movq 0x28(%rsp), %rax
movq %rax, 0xf0(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5850
jmp 0x1e40d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5850
jmp 0x1e41d
movq 0x58(%rsp), %rax
movq 0x48(%rsp), %rsi
movq (%rax), %rdi
callq 0x1ebb0
movq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x88(%rsp)
movq (%rax), %rdi
callq 0x1ebe0
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x1eb90
testb $0x1, %al
jne 0x1e350
jmp 0x1e386
movq 0x1bc81(%rip), %rdi     # 0x39fd8
leaq 0xdb3c(%rip), %rsi      # 0x2be9a
callq 0x32d0
movq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x32a0
movq %rax, %rdi
leaq 0xd4e7(%rip), %rsi      # 0x2b861
callq 0x32d0
xorl %edi, %edi
callq 0x3330
movq 0x58(%rsp), %rax
movq 0x48(%rsp), %rsi
movq (%rax), %rdi
callq 0x1ec10
movq 0x50(%rsp), %rsi
movq (%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x14280
movq 0x58(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
callq *%rax
movq %rax, 0x10(%rsp)
jmp 0x1e3d4
movq 0x10(%rsp), %rax
movq %rax, 0xf0(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5850
jmp 0x1e40d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5850
jmp 0x1e41d
movq 0xf0(%rsp), %rax
addq $0xf8, %rsp
retq
movq 0xb0(%rsp), %rdi
callq 0x3490
nopw (%rax,%rax)