// File: BlinfoldKing[P]lisval/src/lib/evaluator.cpp
// Function: Evaluator::plus()
pair<Token*, function<Token*(Token*)>> Evaluator::plus() {
    Token* op = new BinaryOperator(BinaryOperatorType::PLUS);
    Token* var1 = new Variable("L");
    Token* var2 = new Variable("R");
    List* signature = new List();
    signature->list.push_back(op);
    signature->list.push_back(var1);
    signature->list.push_back(var2);
    Token* token = signature;
    auto res = make_pair(token, [this](Token* input) {
            List* list = static_cast<List*>(input);

            Token* a_token = this->eval(list->list[1]);
            Token* b_token = this->eval(list->list[2]);

            if (a_token->type != TokenType::NUMBER) {
                Token* t = new Error("expect a number, got: " + a_token->debug(), input);
                return t;
            }

            if (b_token->type != TokenType::NUMBER) {
                Token* t = new Error("expect a number, got: " + b_token->debug(), input);
                return t;
            }

            Number* a = static_cast<Number*>(a_token);
            Number* b = static_cast<Number*>(b_token);

            Token* res = new Number(a->value + b->value);
            return res;
    });

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xd0(%rbp)
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl $0x8, %edi
callq 0x32b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movl $0x1, %esi
callq 0x11920
jmp 0x4bf2
movq -0xb8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x28, %edi
callq 0x32b0
movq %rax, -0xe0(%rbp)
movb $0x1, -0x52(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x34a0
movq -0xd8(%rbp), %rdx
leaq 0x1e757(%rip), %rsi     # 0x23387
leaq -0x50(%rbp), %rdi
callq 0x33b0
jmp 0x4c3b
movq -0xe0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x11830
jmp 0x4c4d
movb $0x0, -0x52(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31c0
leaq -0x51(%rbp), %rdi
callq 0x3300
movq -0xe0(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x28, %edi
callq 0x32b0
movq %rax, -0xf0(%rbp)
movb $0x1, -0x82(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x34a0
movq -0xe8(%rbp), %rdx
leaq 0x1e919(%rip), %rsi     # 0x235c0
leaq -0x80(%rbp), %rdi
callq 0x33b0
jmp 0x4cb2
movq -0xf0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x11830
jmp 0x4cc4
movb $0x0, -0x82(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31c0
leaq -0x81(%rbp), %rdi
callq 0x3300
movq -0xf0(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x20, %edi
callq 0x32b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xf8(%rbp)
callq 0x11870
jmp 0x4d09
movq -0xf8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
leaq -0x18(%rbp), %rsi
callq 0x118b0
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x118b0
movq -0x90(%rbp), %rdi
addq $0x8, %rdi
leaq -0x60(%rbp), %rsi
callq 0x118b0
movq -0xc0(%rbp), %rax
movq -0x90(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0xb0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4e90
movq -0xd0(%rbp), %rdi
movq %rax, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0x4ec0
movq -0xc8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x8, %esi
callq 0x32c0
jmp 0x4e86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4df8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31c0
leaq -0x51(%rbp), %rdi
callq 0x3300
testb $0x1, -0x52(%rbp)
jne 0x4e09
jmp 0x4e1a
movq -0xe0(%rbp), %rdi
movl $0x28, %esi
callq 0x32c0
jmp 0x4e86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x4e3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31c0
leaq -0x81(%rbp), %rdi
callq 0x3300
testb $0x1, -0x82(%rbp)
jne 0x4e56
jmp 0x4e67
movq -0xf0(%rbp), %rdi
movl $0x28, %esi
callq 0x32c0
jmp 0x4e86
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x20, %esi
callq 0x32c0
movq -0x20(%rbp), %rdi
callq 0x3490
nop