// File: kram[P]kram/./src/vm/vm.cpp
// Function: VM::run(Instruction*, vm::ON)
Value* VM::run(Instruction* ins, vm::ON on) {
	switch (ins->instruction) {
		case Ins::ASSIGN:          return this->assign(ins, on);      break;
		case Ins::SET:             return this->set(ins, on);         break;
		case Ins::LITERAL:         return this->literal(ins);         break;
		case Ins::NAME:            return this->name(ins, on);        break;
		case Ins::MATH:            return this->math(ins);            break;
		case Ins::IF:              return this->if_case(ins);         break;
		case Ins::IGNORE:          return this->ignore(ins);          break;
		case Ins::PUSH_CLASS:      return this->push_class(ins);      break;
		case Ins::CALL:            return this->call(ins, on);        break;
		case Ins::FUNCTION:        return this->function(ins);        break;
		case Ins::CREATE_INSTANCE: return this->create_instance(ins); break;
		case Ins::WHILE:           return this->loop_while(ins);      break;
		case Ins::DEFINE_CLASS:    return this->define_class(ins);    break;
		case Ins::LIST_CREATE:     return this->list_create(ins);     break;
		case Ins::LIST_EXTRACT:    return this->list_extract(ins);    break;
		case Ins::RETURN:          return this->kw_return(ins);       break;

		case Ins::FUNCTION_PARAMETER:
			std::cout << "Could not evaluate FUNCTION_PARAMETER\n";
			exit(1);
			break;
	}

	return this->get_value_null();
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x10(%rsp)
subq $0x10, %rax
ja 0x11768
movq 0x10(%rsp), %rax
leaq 0x19df2(%rip), %rcx     # 0x2b3a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x100e0
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x10250
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x10390
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x103b0
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x10710
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x10fa0
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11490
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x114b0
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x12200
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11790
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11f20
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11250
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x118f0
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11b50
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11d50
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x11360
movq %rax, 0x30(%rsp)
jmp 0x11777
movq 0x28886(%rip), %rdi     # 0x39fd8
leaq 0x19f75(%rip), %rsi     # 0x2b6ce
callq 0x32d0
movl $0x1, %edi
callq 0x3330
movq 0x8(%rsp), %rdi
callq 0x1d770
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)