// File: Mespyr[P]bop-lisp/src/main.cpp
// Function: REPL()
void REPL()
{  
    printf("Bop Version 1.0.0\n");
    printf("Press 'Ctrl+C' to exit.\n");

    rl_bind_key('\t', rl_insert);
    
    // Global Evaluator
    Evaluator eval;
    
    while (true) 
    {
        std::string buf = readline("$ ");
        if (buf.length() > 0) 
        {
            add_history(buf.c_str());
        }
        TokenList tokens = tokenize(buf+" ");
        AST ast = parse(tokens);

        if (ast.error_found) 
        {
            std::cout << ast.error.error() << std::endl;
            continue;
        }
        AST_Handler ast_buf{ast};

        while (!ast_buf.eof) 
        {
            Node node = ast_buf.next();
            // ast_out(node.nodes);
            object obj = eval.evaluate(node);
            if (eval.error_found) 
            {
                std::cout << eval.error.error() << std::endl;
                ast_buf.eof = true;
                eval.error_found = false;
            }
            else 
            {
                std::cout << "> " << repr(obj) << std::endl;
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
leaq 0x5cdd(%rip), %rdi      # 0x1ce2f
movb $0x0, %al
callq 0x3060
leaq 0x5ce2(%rip), %rdi      # 0x1ce42
movb $0x0, %al
callq 0x3060
movl $0x9, %edi
movq 0xee75(%rip), %rsi      # 0x25fe8
callq 0x3130
leaq -0xd0(%rbp), %rdi
callq 0x178f0
jmp 0x17186
leaq 0x5cce(%rip), %rdi      # 0x1ce5b
callq 0x32d0
movq %rax, -0x408(%rbp)
jmp 0x1719b
leaq -0xfd(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x3520
movq -0x408(%rbp), %rsi
movq -0x410(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x3df0
jmp 0x171ca
leaq -0xfd(%rbp), %rdi
callq 0x3370
leaq -0xf0(%rbp), %rdi
callq 0x3480
cmpq $0x0, %rax
jbe 0x17251
leaq -0xf0(%rbp), %rdi
callq 0x3170
movq %rax, %rdi
callq 0x3420
jmp 0x171fe
jmp 0x17251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x176d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0xfd(%rbp), %rdi
callq 0x3370
jmp 0x176d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x176c5
leaq 0x5bd5(%rip), %rdx      # 0x1ce2d
leaq -0x138(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x177b0
jmp 0x1726d
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x18c40
jmp 0x17282
leaq -0x138(%rbp), %rdi
callq 0x3210
leaq -0x1c0(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x17830
jmp 0x172a3
leaq -0x1a8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x19be0
jmp 0x172b8
leaq -0x1c0(%rbp), %rdi
callq 0x17860
testb $0x1, -0x190(%rbp)
je 0x173c9
leaq -0x188(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x7f80
jmp 0x172e6
movq 0xecdb(%rip), %rdi      # 0x25fc8
leaq -0x1e0(%rbp), %rsi
callq 0x32b0
movq %rax, -0x418(%rbp)
jmp 0x17302
movq -0x418(%rbp), %rdi
movq 0xec98(%rip), %rsi      # 0x25fa8
callq 0x3340
jmp 0x17317
leaq -0x1e0(%rbp), %rdi
callq 0x3210
movl $0x2, -0x1e4(%rbp)
jmp 0x17667
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x3210
jmp 0x176c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x176b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x17860
jmp 0x176b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x176ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3210
jmp 0x176ad
leaq -0x260(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x17880
jmp 0x173de
movl $0x0, -0x1f0(%rbp)
movb $0x0, -0x1ec(%rbp)
movb -0x1ec(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x17400
jmp 0x17651
leaq -0x2d0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x8ce0
jmp 0x17415
leaq -0x380(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x13dc0
jmp 0x1742a
leaq -0x310(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0x380(%rbp), %rdx
callq 0x96e0
jmp 0x17446
leaq -0x380(%rbp), %rdi
callq 0x141d0
testb $0x1, -0x8(%rbp)
je 0x17549
leaq -0xb8(%rbp), %rsi
leaq -0x3a0(%rbp), %rdi
callq 0x8850
jmp 0x17471
movq 0xeb50(%rip), %rdi      # 0x25fc8
leaq -0x3a0(%rbp), %rsi
callq 0x32b0
movq %rax, -0x420(%rbp)
jmp 0x1748d
movq -0x420(%rbp), %rdi
movq 0xeb0d(%rip), %rsi      # 0x25fa8
callq 0x3340
jmp 0x174a2
leaq -0x3a0(%rbp), %rdi
callq 0x3210
movb $0x1, -0x1ec(%rbp)
movb $0x0, -0x8(%rbp)
jmp 0x1761a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x176a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x17643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x141d0
jmp 0x17643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x17637
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x3a0(%rbp), %rdi
callq 0x3210
jmp 0x17637
movq 0xea78(%rip), %rdi      # 0x25fc8
leaq 0x5907(%rip), %rsi      # 0x1ce5e
callq 0x32f0
movq %rax, -0x428(%rbp)
jmp 0x17565
leaq -0x400(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3d80
jmp 0x1757a
leaq -0x3c0(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x1b840
jmp 0x1758f
movq -0x428(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x32b0
movq %rax, -0x430(%rbp)
jmp 0x175ab
movq -0x430(%rbp), %rdi
movq 0xe9ef(%rip), %rsi      # 0x25fa8
callq 0x3340
jmp 0x175c0
leaq -0x3c0(%rbp), %rdi
callq 0x3210
leaq -0x400(%rbp), %rdi
callq 0x40f0
jmp 0x1761a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x1760c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x3210
leaq -0x400(%rbp), %rdi
callq 0x40f0
jmp 0x17637
leaq -0x310(%rbp), %rdi
callq 0x40f0
leaq -0x2d0(%rbp), %rdi
callq 0x141d0
jmp 0x173ef
leaq -0x310(%rbp), %rdi
callq 0x40f0
leaq -0x2d0(%rbp), %rdi
callq 0x141d0
jmp 0x176a1
leaq -0x260(%rbp), %rdi
callq 0x17960
movl $0x0, -0x1e4(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x17980
leaq -0x118(%rbp), %rdi
callq 0x17860
leaq -0xf0(%rbp), %rdi
callq 0x3210
movl -0x1e4(%rbp), %eax
testl %eax, %eax
je 0x1769c
jmp 0x17697
jmp 0x17184
jmp 0x17184
leaq -0x260(%rbp), %rdi
callq 0x17960
leaq -0x1a8(%rbp), %rdi
callq 0x17980
leaq -0x118(%rbp), %rdi
callq 0x17860
leaq -0xf0(%rbp), %rdi
callq 0x3210
leaq -0xd0(%rbp), %rdi
callq 0x17930
movq -0xf8(%rbp), %rdi
callq 0x3510
nopl (%rax)