// File: BlinfoldKing[P]lisval/src/lib/repl.cpp
// Function: Repl::run()
void Repl::run() {

	/* linenoiseHistoryLoad(file); */
	cout << "Press Ctrl+C to exit\n\n";

	string prompt = "(\x1b[1;32mlisval\x1b[0m) \u03bb ";

	string input = "";
	while (1) {
        cout << prompt;

        string result;
        getline(cin, result);

		if (input == "(history)") {

		} else if (result == "") {
			continue;
		}

		string str_result(result);
		while (str_result.back() == ' ') str_result.pop_back();
		if (str_result.back() == '\\') {
			str_result.pop_back();
			input += str_result + ' ';
			continue;
		}

		input += str_result;

		Parser p(input);
		Token *ast = p.parse();
		if (ast)
		{
			Token *eval_result = this->evaluator.eval(ast);
			if (eval_result)
				cout << eval_result->debug() << '\n';
		}
		else
		{
			cout << "invalid pattern: " << result << '\n';
		}

		input = "";
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x148(%rbp)
movq 0x12297(%rip), %rdi     # 0x33fc8
leaq 0x1909(%rip), %rsi      # 0x23641
callq 0x32a0
leaq -0x29(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x34a0
movq -0x140(%rbp), %rdx
leaq 0x18fd(%rip), %rsi      # 0x23658
leaq -0x28(%rbp), %rdi
callq 0x33b0
jmp 0x21d66
leaq -0x29(%rbp), %rdi
callq 0x3300
leaq -0x61(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x34a0
movq -0x150(%rbp), %rdx
leaq 0x18ca(%rip), %rsi      # 0x23657
leaq -0x60(%rbp), %rdi
callq 0x33b0
jmp 0x21d98
leaq -0x61(%rbp), %rdi
callq 0x3300
jmp 0x21da3
movq 0x1221e(%rip), %rdi     # 0x33fc8
leaq -0x28(%rbp), %rsi
callq 0x3280
jmp 0x21db5
leaq -0x88(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x33c0
movq -0x158(%rbp), %rsi
movq 0x1220a(%rip), %rdi     # 0x33fe0
callq 0x3080
jmp 0x21ddd
leaq 0x188c(%rip), %rsi      # 0x23670
leaq -0x60(%rbp), %rdi
callq 0x18b40
movb %al, -0x159(%rbp)
jmp 0x21df5
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0x21e01
jmp 0x21e5c
jmp 0x21e94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x3300
jmp 0x22155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x3300
jmp 0x2214c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x22143
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x22137
leaq 0x17f4(%rip), %rsi      # 0x23657
leaq -0x88(%rbp), %rdi
callq 0x18b40
movb %al, -0x15a(%rbp)
jmp 0x21e77
movb -0x15a(%rbp), %al
testb $0x1, %al
jne 0x21e83
jmp 0x21e92
movl $0x2, -0x8c(%rbp)
jmp 0x220fd
jmp 0x21e94
leaq -0xb0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3140
jmp 0x21ea9
jmp 0x21eab
leaq -0xb0(%rbp), %rdi
callq 0x3220
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x21ecd
leaq -0xb0(%rbp), %rdi
callq 0x3330
jmp 0x21eab
leaq -0xb0(%rbp), %rdi
callq 0x3220
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x21f6d
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3330
movq -0x168(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movl $0x20, %edx
callq 0x3a60
jmp 0x21f12
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3380
jmp 0x21f24
leaq -0xd0(%rbp), %rdi
callq 0x31c0
movl $0x2, -0x8c(%rbp)
jmp 0x220f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2212b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31c0
jmp 0x2212b
leaq -0x60(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3380
jmp 0x21f7f
leaq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3ae0
jmp 0x21f91
leaq -0x108(%rbp), %rdi
callq 0x171c0
movq %rax, -0x170(%rbp)
jmp 0x21fa6
movq -0x170(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, -0x110(%rbp)
je 0x2207c
movq -0x148(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x5980
movq %rax, -0x178(%rbp)
jmp 0x21fde
movq -0x178(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
je 0x2207a
movq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x17be0
jmp 0x2200f
movq 0x11fb2(%rip), %rdi     # 0x33fc8
leaq -0x138(%rbp), %rsi
callq 0x3280
movq %rax, -0x180(%rbp)
jmp 0x2202b
movq -0x180(%rbp), %rdi
movl $0xa, %esi
callq 0x3320
jmp 0x2203e
leaq -0x138(%rbp), %rdi
callq 0x31c0
jmp 0x2207a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2211f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x31c0
jmp 0x2211f
jmp 0x220c9
movq 0x11f45(%rip), %rdi     # 0x33fc8
leaq 0xf8f(%rip), %rsi       # 0x23019
callq 0x32a0
movq %rax, -0x188(%rbp)
jmp 0x22098
movq -0x188(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3280
movq %rax, -0x190(%rbp)
jmp 0x220b4
movq -0x190(%rbp), %rdi
movl $0xa, %esi
callq 0x3320
jmp 0x220c7
jmp 0x220c9
leaq 0x1587(%rip), %rsi      # 0x23657
leaq -0x60(%rbp), %rdi
callq 0x33a0
jmp 0x220db
leaq -0x108(%rbp), %rdi
callq 0x3b70
movl $0x0, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x31c0
leaq -0x88(%rbp), %rdi
callq 0x31c0
movl -0x8c(%rbp), %eax
testl %eax, %eax
je 0x2211a
jmp 0x22115
jmp 0x21da1
jmp 0x21da1
leaq -0x108(%rbp), %rdi
callq 0x3b70
leaq -0xb0(%rbp), %rdi
callq 0x31c0
leaq -0x88(%rbp), %rdi
callq 0x31c0
leaq -0x60(%rbp), %rdi
callq 0x31c0
leaq -0x28(%rbp), %rdi
callq 0x31c0
movq -0x38(%rbp), %rdi
callq 0x3490