// File: iamlouk[P]asbi/src/main.cc
// Function: repl(asbi::Context&)
static void repl(Context &ctx) {
	char* line = NULL;
	auto file = Value::string(".", &ctx);
	ctx.global_env->decl(ctx.names.__file, file);
	ctx.global_env->decl(ctx.names.__main, file);
	auto env = std::make_shared<Env>(&ctx, ctx.global_env);

	char prompt[256];
	while ((line = readline(get_prompt(prompt, sizeof(prompt))))) {
		if (line[0] == '\0') {
			free(line);
			continue;
		}

		try {
			auto res = ctx.run(line, env);
			std::cout << "\033[0;37m->\033[0m " << res.to_string(true) << std::endl;
			add_history(line);
		} catch (std::runtime_error e) {
			std::cerr << "\033[0;31mError:\033[0m " << e.what() << ' ';
			std::cerr << "\033[0;37m(C++ Exceptions cause Memory Leaks!)\033[0m" << '\n';
		}

		free(line);
	}

	free(line);
}

// Assembly:
subq $0x258, %rsp            # imm = 0x258
movq %rdi, 0x250(%rsp)
movq $0x0, 0x248(%rsp)
movq 0x250(%rsp), %rsi
leaq 0x30a4a(%rip), %rdi     # 0x38134
callq 0x218a0
movl %eax, 0x238(%rsp)
movq %rdx, 0x240(%rsp)
movq 0x250(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
callq 0x7bd0
movq %rax, %rdi
movq 0x250(%rsp), %rax
movq 0x538(%rax), %rsi
movq 0x238(%rsp), %rax
movq %rax, 0x228(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x230(%rsp)
movl 0x228(%rsp), %edx
movq 0x230(%rsp), %rcx
callq 0x26220
movq 0x250(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
callq 0x7bd0
movq %rax, %rdi
movq 0x250(%rsp), %rax
movq 0x540(%rax), %rsi
movq 0x238(%rsp), %rax
movq %rax, 0x218(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x220(%rsp)
movl 0x218(%rsp), %edx
movq 0x220(%rsp), %rcx
callq 0x26220
movq 0x250(%rsp), %rax
movq %rax, 0x200(%rsp)
movq 0x250(%rsp), %rdx
addq $0x4f8, %rdx            # imm = 0x4F8
leaq 0x208(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x7d00
leaq 0x100(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x7b70
movq %rax, 0x70(%rsp)
jmp 0x77ff
movq 0x70(%rsp), %rdi
callq 0x63f0
movq %rax, 0x68(%rsp)
jmp 0x7810
movq 0x68(%rsp), %rax
movq %rax, 0x248(%rsp)
cmpq $0x0, %rax
je 0x7b29
movq 0x248(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x785f
movq 0x248(%rsp), %rdi
callq 0x6550
jmp 0x77e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0x7b4b
movq 0x250(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x248(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x67b0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0xc0(%rsp), %rdi
callq 0x7c20
jmp 0x78a4
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
leaq 0x208(%rsp), %rsi
callq 0x7d80
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rdx
leaq 0xc0(%rsp), %rsi
callq 0x26c90
movq %rdx, 0x40(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0x78e0
movq 0x40(%rsp), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0xe0(%rsp)
movq %rax, 0xe8(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7db0
leaq 0xc0(%rsp), %rdi
callq 0x6290
leaq 0xbf(%rsp), %rdi
callq 0x64c0
movq 0x4468a(%rip), %rdi     # 0x4bfb0
leaq 0x30809(%rip), %rsi     # 0x38136
callq 0x6450
movq %rax, 0x30(%rsp)
jmp 0x7939
leaq 0x88(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl $0x1, %edx
callq 0x220c0
jmp 0x7955
movq 0x30(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x63d0
movq %rax, 0x28(%rsp)
jmp 0x796e
movq 0x28(%rsp), %rdi
movq 0x445fe(%rip), %rsi     # 0x4bf78
callq 0x64a0
jmp 0x7981
leaq 0x88(%rsp), %rdi
callq 0x6290
movq 0x248(%rsp), %rdi
callq 0x65f0
jmp 0x799d
jmp 0x7af0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0x79e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7db0
leaq 0xc0(%rsp), %rdi
callq 0x6290
leaq 0xbf(%rsp), %rdi
callq 0x64c0
jmp 0x7a2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0x7a2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x6290
movl 0xf4(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x7b4b
movq 0xf8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x65a0
movq %rax, %rsi
leaq 0x78(%rsp), %rdi
callq 0x6190
movq 0x18(%rsp), %rdi
callq 0x6170
movq 0x44578(%rip), %rdi     # 0x4bfe8
leaq 0x306ce(%rip), %rsi     # 0x38145
callq 0x6450
movq %rax, 0x20(%rsp)
jmp 0x7a83
leaq 0x78(%rsp), %rdi
callq 0x6640
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x6450
movq %rax, 0x10(%rsp)
jmp 0x7aa1
movq 0x10(%rsp), %rdi
movl $0x20, %esi
callq 0x6540
jmp 0x7ab2
movq 0x4452f(%rip), %rdi     # 0x4bfe8
leaq 0x30698(%rip), %rsi     # 0x38158
callq 0x6450
movq %rax, 0x8(%rsp)
jmp 0x7acc
movq 0x8(%rsp), %rdi
movl $0xa, %esi
callq 0x6540
jmp 0x7add
leaq 0x78(%rsp), %rdi
callq 0x6848
callq 0x6740
jmp 0x7aee
jmp 0x7af0
movq 0x248(%rsp), %rdi
callq 0x6550
jmp 0x77e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x6848
callq 0x6740
jmp 0x7b27
jmp 0x7b4b
movq 0x248(%rsp), %rdi
callq 0x6550
leaq 0x208(%rsp), %rdi
callq 0x7db0
addq $0x258, %rsp            # imm = 0x258
retq
leaq 0x208(%rsp), %rdi
callq 0x7db0
movq 0xf8(%rsp), %rdi
callq 0x67a0
movq %rax, %rdi
callq 0x7dc0
nopl (%rax)