// File: iamlouk[P]asbi/src/types.cc
// Function: asbi::Value::call(asbi::Context*, unsigned int, std::shared_ptr<asbi::Env>) const
Value Value::call(Context *ctx, unsigned int n, std::shared_ptr<Env> callerenv) const {
	switch (type) {
	case type_t::Lambda:{
		if (_lambda->argnames.size() != n)
			throw std::runtime_error("callable argnum does not match call");

		auto lbdenv = std::make_shared<Env>(ctx, _lambda->env);
		for (unsigned int i = 0; i < n; ++i)
			lbdenv->decl(_lambda->argnames[i], ctx->pop());

		lbdenv->caller = callerenv;
		return execute(*_lambda->ops, lbdenv, ctx);
	}
	case type_t::Macro:
		return _macro(n, ctx, callerenv);
	default:
		throw std::runtime_error("not callable");
	}
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rcx, 0x80(%rsp)
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movl %edx, 0x114(%rsp)
movq %rcx, 0x108(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x88(%rsp)
movl (%rax), %eax
movl %eax, 0x94(%rsp)
subl $0x5, %eax
je 0x21a23
jmp 0x21a0e
movl 0x94(%rsp), %eax
subl $0x7, %eax
je 0x21ca5
jmp 0x21d52
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
addq $0x30, %rdi
callq 0x141a0
movl 0x114(%rsp), %ecx
cmpq %rcx, %rax
je 0x21aa2
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x78(%rsp)
leaq 0x17566(%rip), %rsi     # 0x38fc6
callq 0x6160
jmp 0x21a67
movq 0x78(%rsp), %rdi
movq 0x2a57d(%rip), %rsi     # 0x4bff0
movq 0x2a526(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x6320
jmp 0x21dc4
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdx
addq $0x18, %rdx
leaq 0xe8(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x1d240
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
cmpl 0x114(%rsp), %eax
jae 0x21ba2
leaq 0xe8(%rsp), %rdi
callq 0x7bd0
movq %rax, %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rdi
addq $0x30, %rdi
movl 0xe4(%rsp), %eax
movl %eax, %esi
callq 0x22d70
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x118(%rsp), %rdi
callq 0x26b50
movq %rdx, 0x68(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x21b39
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdi
movq 0x68(%rsp), %rax
movl 0x74(%rsp), %ecx
movl %ecx, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
movl 0xd0(%rsp), %edx
movq 0xd8(%rsp), %rcx
callq 0x26220
jmp 0x21b71
jmp 0x21b73
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x21ad2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x21c93
leaq 0xe8(%rsp), %rdi
callq 0x7bd0
movq 0x80(%rsp), %rsi
movq %rax, %rdi
addq $0x10, %rdi
callq 0x1d2f0
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x22d90
jmp 0x21be2
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
leaq 0xe8(%rsp), %rsi
callq 0x7d80
movq 0x40(%rsp), %rsi
movq 0x118(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x1abf0
movq %rdx, 0x48(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x21c21
movq 0x48(%rsp), %rax
movl 0x54(%rsp), %ecx
movl %ecx, 0x128(%rsp)
movq %rax, 0x130(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7db0
leaq 0xb8(%rsp), %rdi
callq 0x22e90
leaq 0xe8(%rsp), %rdi
callq 0x7db0
jmp 0x21dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7db0
leaq 0xb8(%rsp), %rdi
callq 0x22e90
leaq 0xe8(%rsp), %rdi
callq 0x7db0
jmp 0x21dc4
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movl 0x114(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x98(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7d80
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
callq *%rax
movq %rdx, 0x30(%rsp)
movl %eax, 0x3c(%rsp)
jmp 0x21d08
movq 0x30(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, 0x128(%rsp)
movq %rax, 0x130(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x7db0
jmp 0x21dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x7db0
jmp 0x21dc4
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
leaq 0x1727c(%rip), %rsi     # 0x38fea
callq 0x6160
jmp 0x21d75
movq 0x8(%rsp), %rdi
movq 0x2a26f(%rip), %rsi     # 0x4bff0
movq 0x2a218(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x6320
jmp 0x21dc4
movl 0x128(%rsp), %eax
movq 0x130(%rsp), %rdx
addq $0x138, %rsp            # imm = 0x138
retq
movq 0x100(%rsp), %rdi
callq 0x67a0
nopw %cs:(%rax,%rax)