// File: ConsoleTVs[P]VirtualMachine/src/values.cpp
// Function: VM::Value::to_string[abi:cxx11]()
std::string Value::to_string()
{
    switch (this->type) {
        case VALUE_INTEGER: { return std::to_string(this->ivalue); }
        case VALUE_FLOAT: { return std::to_string(this->fvalue); }
        case VALUE_BOOLEAN: { return std::to_string(this->bvalue ? 1 : 0); }
        case VALUE_STRING: { return *this->svalue; }
        case VALUE_LIST: {
            // Printing a list is a bit more elaborate :)
            std::string result = "[";

            for (auto element : *this->lvalue) {
                result += element->to_string() + ", ";
            }

            // This will pop the last ',' and the ' '
            result.pop_back(); result.pop_back();

            return result + "]";
        }
        default: { printf("Error converting value to int.\n"); }
    }
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0x10(%rsp)
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
movzbl (%rax), %eax
movq %rax, 0x28(%rsp)
subq $0x4, %rax
ja 0x66b7
movq 0x28(%rsp), %rax
leaq 0xd21(%rip), %rcx       # 0x7190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x66f0
jmp 0x66c7
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rax
movss 0x8(%rax), %xmm0
callq 0x6830
jmp 0x66c7
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rax
movb 0x8(%rax), %cl
xorl %esi, %esi
movl $0x1, %eax
testb $0x1, %cl
cmovnel %eax, %esi
callq 0x66f0
jmp 0x66c7
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x20b0
jmp 0x66c7
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2270
movq 0x8(%rsp), %rdx
leaq 0xcc2(%rip), %rsi       # 0x71c4
leaq 0xa8(%rsp), %rdi
callq 0x21f0
jmp 0x6511
leaq 0xa7(%rsp), %rdi
callq 0x21a0
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
callq 0x6100
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdi
callq 0x5f80
movq %rax, 0x78(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x6880
testb $0x1, %al
jne 0x6571
jmp 0x6668
leaq 0x80(%rsp), %rdi
callq 0x68c0
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x6420
jmp 0x6597
leaq 0xc28(%rip), %rdx       # 0x71c6
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x68d0
jmp 0x65af
leaq 0xa8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x21e0
jmp 0x65c3
leaq 0x50(%rsp), %rdi
callq 0x20e0
leaq 0x30(%rsp), %rdi
callq 0x20e0
leaq 0x80(%rsp), %rdi
callq 0x6920
jmp 0x6556
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xa7(%rsp), %rdi
callq 0x21a0
jmp 0x66d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x66a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x665c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x20e0
leaq 0x30(%rsp), %rdi
callq 0x20e0
jmp 0x66a8
leaq 0xa8(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x21c0
movq (%rsp), %rdi
callq 0x21c0
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
leaq 0xb37(%rip), %rdx       # 0x71c9
callq 0x6940
jmp 0x6699
leaq 0xa8(%rsp), %rdi
callq 0x20e0
jmp 0x66c7
leaq 0xa8(%rsp), %rdi
callq 0x20e0
jmp 0x66d4
leaq 0xae6(%rip), %rdi       # 0x71a4
movb $0x0, %al
callq 0x2040
ud2
movq 0x18(%rsp), %rax
addq $0xd8, %rsp
retq
movq 0x98(%rsp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)