// File: kram[P]kram/./src/vm/value.cpp
// Function: Value::print[abi:cxx11](bool)
std::string Value::print(bool print_type) {
	std::stringstream res;

	if (print_type) {
		std::string i = "UNKNOWN";
		switch (this->type) {
			case Type::NUL: i = "NUL"; break;
			case Type::STRING: i = "STRING"; break;
			case Type::NUMBER: i = "NUMBER"; break;
			case Type::BOOL: i = "BOOL"; break;
			case Type::REFERENCE: i = "REFERENCE"; break;
			case Type::FUNCTION: i = "FUNCTION"; break;
			case Type::CLASS: i = "CLASS"; break;
			case Type::NAME: i = "NAME"; break;
		}

		res << i << "<";
	}

	switch (this->type) {
		case Type::NUL:
			res << "NULL";
			break;

		case Type::STRING:
			res << *this->data.strval;
			break;

		case Type::NUMBER:
			res << std::setprecision (std::numeric_limits<double>::digits10 + 1);
			res << this->data.number;
			break;

		case Type::BOOL:
			if (this->getBool()) {
				res << "true";
			} else {
				res << "false";
			}
			break;

		// We can probably prettify these even further, eg print what a REFERENCE is actually pointing to.
		// But that is for another time.
		case Type::REFERENCE: res << "REFERENCE"; break;
		case Type::FUNCTION: res << "FUNCTION"; break;
		case Type::CLASS: res << "CLASS"; break;
		case Type::NAME: res << "NAME"; break;
	}

	if (print_type) {
		res << ">";
	}

	return res.str();
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x38(%rsp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, 0x40(%rsp)
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
andb $0x1, %al
movb %al, 0x217(%rsp)
movq 0x218(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x3230
testb $0x1, 0x217(%rsp)
je 0x1e5ff
leaq 0x67(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x34a0
movq 0x30(%rsp), %rdx
leaq 0xcc87(%rip), %rsi      # 0x2b129
leaq 0x68(%rsp), %rdi
callq 0x3390
jmp 0x1e4ae
leaq 0x67(%rsp), %rdi
callq 0x3310
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movq %rax, 0x28(%rsp)
subq $0x7, %rax
ja 0x1e5c9
movq 0x28(%rsp), %rax
leaq 0xd809(%rip), %rcx      # 0x2bce4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x67(%rsp), %rdi
callq 0x3310
jmp 0x1e7c3
leaq 0xd9a3(%rip), %rsi      # 0x2beab
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e514
jmp 0x1e5c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x31f0
jmp 0x1e7c3
leaq 0xcd88(%rip), %rsi      # 0x2b2c5
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e549
jmp 0x1e5c9
leaq 0xcd7a(%rip), %rsi      # 0x2b2cc
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e55e
jmp 0x1e5c9
leaq 0xcd6c(%rip), %rsi      # 0x2b2d3
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e573
jmp 0x1e5c9
leaq 0xd933(%rip), %rsi      # 0x2beaf
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e588
jmp 0x1e5c9
leaq 0xcbdf(%rip), %rsi      # 0x2b170
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e59d
jmp 0x1e5c9
leaq 0xcbc4(%rip), %rsi      # 0x2b16a
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e5b2
jmp 0x1e5c9
leaq 0xdb09(%rip), %rsi      # 0x2c0c4
leaq 0x68(%rsp), %rdi
callq 0x3380
jmp 0x1e5c7
jmp 0x1e5c9
leaq 0x98(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x32a0
movq %rax, 0x20(%rsp)
jmp 0x1e5e2
movq 0x20(%rsp), %rdi
leaq 0xccad(%rip), %rsi      # 0x2b29b
callq 0x32d0
jmp 0x1e5f5
leaq 0x68(%rsp), %rdi
callq 0x31f0
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movq %rax, 0x18(%rsp)
subq $0x7, %rax
ja 0x1e773
movq 0x18(%rsp), %rax
leaq 0xd6e2(%rip), %rcx      # 0x2bd04
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x98(%rsp), %rdi
leaq 0xd87f(%rip), %rsi      # 0x2beb9
callq 0x32d0
jmp 0x1e641
jmp 0x1e773
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x1e7c3
movq 0x48(%rsp), %rax
leaq 0x98(%rsp), %rdi
movq (%rax), %rsi
callq 0x32a0
jmp 0x1e670
jmp 0x1e773
leaq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x10, %edi
callq 0x1ecd0
movl %eax, 0x14(%rsp)
jmp 0x1e692
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %esi
callq 0x3410
jmp 0x1e6aa
movq 0x48(%rsp), %rax
leaq 0x98(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x34d0
jmp 0x1e6c2
jmp 0x1e773
movq 0x48(%rsp), %rdi
callq 0x1e9b0
movb %al, 0x7(%rsp)
jmp 0x1e6d7
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x1e6e1
jmp 0x1e6f9
leaq 0x98(%rsp), %rdi
leaq 0xcb5b(%rip), %rsi      # 0x2b24b
callq 0x32d0
jmp 0x1e6f7
jmp 0x1e711
leaq 0x98(%rsp), %rdi
leaq 0xcb48(%rip), %rsi      # 0x2b250
callq 0x32d0
jmp 0x1e70f
jmp 0x1e711
jmp 0x1e773
leaq 0x98(%rsp), %rdi
leaq 0xd78d(%rip), %rsi      # 0x2beaf
callq 0x32d0
jmp 0x1e729
jmp 0x1e773
leaq 0x98(%rsp), %rdi
leaq 0xca36(%rip), %rsi      # 0x2b170
callq 0x32d0
jmp 0x1e741
jmp 0x1e773
leaq 0x98(%rsp), %rdi
leaq 0xca18(%rip), %rsi      # 0x2b16a
callq 0x32d0
jmp 0x1e759
jmp 0x1e773
leaq 0x98(%rsp), %rdi
leaq 0xd95a(%rip), %rsi      # 0x2c0c4
callq 0x32d0
jmp 0x1e771
jmp 0x1e773
testb $0x1, 0x217(%rsp)
je 0x1e795
leaq 0x98(%rsp), %rdi
leaq 0xcb07(%rip), %rsi      # 0x2b293
callq 0x32d0
jmp 0x1e793
jmp 0x1e795
movq 0x38(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x32c0
jmp 0x1e7a9
leaq 0x88(%rsp), %rdi
callq 0x3250
movq 0x40(%rsp), %rax
addq $0x228, %rsp            # imm = 0x228
retq
leaq 0x88(%rsp), %rdi
callq 0x3250
movq 0x58(%rsp), %rdi
callq 0x3490
nopw (%rax,%rax)