// File: iamlouk[P]asbi/src/macros.cc
// Function: macro_eval(int, asbi::Context*, std::shared_ptr<asbi::Env>)
static Value macro_eval(int n, Context* ctx, std::shared_ptr<Env> callerenv) {
	if (n != 2)
		throw std::runtime_error("eval macro usage error");

	auto string = ctx->pop();
	auto envdepth = ctx->pop();
	if (string.type != type_t::String || envdepth.type != type_t::Number)
		throw std::runtime_error("eval macro usage error");

	auto env = callerenv;
	for (int i = 0; i < envdepth._number; i++) {
		if (callerenv->getOuter() == nullptr)
			break;

		env = callerenv->getOuter();
	}

	return ctx->run(string._string->data, env);
}

// Assembly:
subq $0xe8, %rsp
movq %rdx, 0x40(%rsp)
movl %edi, 0xd4(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
cmpl $0x2, 0xd4(%rsp)
je 0x2c06b
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x38(%rsp)
leaq 0xd43e(%rip), %rsi      # 0x39467
callq 0x6160
jmp 0x2c030
movq 0x38(%rsp), %rdi
movq 0x1ffb4(%rip), %rsi     # 0x4bff0
movq 0x1ff5d(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
callq 0x6320
jmp 0x2c2ac
movq 0xc8(%rsp), %rdi
callq 0x26b50
movl %eax, 0xa0(%rsp)
movq %rdx, 0xa8(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x26b50
movl %eax, 0x90(%rsp)
movq %rdx, 0x98(%rsp)
cmpl $0x4, 0xa0(%rsp)
jne 0x2c0b7
cmpl $0x1, 0x90(%rsp)
je 0x2c115
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
leaq 0xd394(%rip), %rsi      # 0x39467
callq 0x6160
jmp 0x2c0da
movq 0x30(%rsp), %rdi
movq 0x1ff0a(%rip), %rsi     # 0x4bff0
movq 0x1feb3(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
callq 0x6320
jmp 0x2c2ac
movq 0x40(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x7d80
movl $0x0, 0x7c(%rsp)
cvtsi2sdl 0x7c(%rsp), %xmm1
movsd 0x98(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2c1e7
movq 0x40(%rsp), %rdi
callq 0x7bd0
movq %rax, %rsi
leaq 0x68(%rsp), %rdi
callq 0x2cd70
jmp 0x2c161
leaq 0x68(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2cd40
movb %al, 0x2f(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7db0
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x2c187
jmp 0x2c1a2
jmp 0x2c1e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x2c29f
movq 0x40(%rsp), %rdi
callq 0x7bd0
movq %rax, %rsi
leaq 0x58(%rsp), %rdi
callq 0x2cd70
jmp 0x2c1bb
leaq 0x80(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1d2c0
leaq 0x58(%rsp), %rdi
callq 0x7db0
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x2c12f
movq 0xc8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x10(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x80(%rsp), %rsi
callq 0x7d80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x26c90
movq %rdx, 0x20(%rsp)
movl %eax, 0x28(%rsp)
jmp 0x2c23b
movq 0x20(%rsp), %rax
movl 0x28(%rsp), %ecx
movl %ecx, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x7db0
leaq 0x80(%rsp), %rdi
callq 0x7db0
movl 0xd8(%rsp), %eax
movq 0xe0(%rsp), %rdx
addq $0xe8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x7db0
leaq 0x80(%rsp), %rdi
callq 0x7db0
movq 0xb8(%rsp), %rdi
callq 0x67a0
nopl (%rax)