// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_FunctionExpression::codeGen(Symbol*)
DEF_AST_METHOD(FunctionExpression,AST_CODEGEN)
{
    auto symbol_bak=symbol;
    GET_SCOPE();
    int funcLabel=nextLabel();
    FunctionInfo func;
    functionStack.push(&func);
    FILE *bak=AST::fp;
    FILE *tmp_fp=AST::fp=tmpfile();
    func_tmpfile.push_back(tmp_fp);
    PRINTF("; function expression\n");
    PRINTF("label_%d:\n",funcLabel);
    auto localCount=symbol->localCount;
    if(localCount)PRINTF("addsp %d\n",symbol->localCount);
    CODEGEN(block);
    PRINTF("push null\n");
    PRINTF("ret\n");
    // if(localCount)PRINTF("subsp %d\n",symbol->localCount);
    functionStack.pop();
    AST::fp=bak;
    this_count++;
    PRINTF("new_array\n");
    for(auto &x:func.ext_list)
    {
        variantMethod(symbol_bak,x,"load");
        PRINTF("array_push\n");
    }
    PRINTF("create_function label_%d\n",funcLabel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movq %rax, -0x20(%rbp)
leaq 0x35907(%rip), %rdi     # 0x8a768
leaq -0x20(%rbp), %rsi
callq 0x20310
movq %rax, %rdi
callq 0x203f0
movq %rax, -0x10(%rbp)
callq 0x1a000
movl %eax, -0x24(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x556a0
movq -0xc8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0x359e8(%rip), %rdi     # 0x8a888
leaq -0x78(%rbp), %rsi
callq 0x556d0
jmp 0x54eab
leaq 0x35a36(%rip), %rax     # 0x8a8e8
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x7480
movq %rax, -0xd8(%rbp)
jmp 0x54eca
movq -0xd8(%rbp), %rax
leaq 0x35a10(%rip), %rcx     # 0x8a8e8
movq %rax, (%rcx)
movq %rax, -0x98(%rbp)
leaq 0x35d2f(%rip), %rdi     # 0x8ac18
leaq -0x98(%rbp), %rsi
callq 0x55700
jmp 0x54ef7
movl 0x35d13(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35d0a(%rip)     # 0x8ac10
leaq 0x359db(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4ab8(%rip), %rsi      # 0x599cf
movb $0x0, %al
callq 0x74c0
movl 0x35cec(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35ce3(%rip)     # 0x8ac10
leaq 0x359b4(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x24(%rbp), %edx
leaq 0x4995(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
movq -0x10(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x54fab
movl 0x35cac(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35ca3(%rip)     # 0x8ac10
leaq 0x35974(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x3c(%rax), %edx
leaq 0x4a61(%rip), %rsi      # 0x599e6
movb $0x0, %al
callq 0x74c0
jmp 0x54fab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x55810
jmp 0x55170
movq -0xd0(%rbp), %rdi
addq $0x10, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
jmp 0x54fcd
movl 0x35c3d(%rip), %eax     # 0x8ac10
incl %eax
movl %eax, 0x35c35(%rip)     # 0x8ac10
leaq 0x35906(%rip), %rax     # 0x8a8e8
movq %rax, -0xe8(%rbp)
movq (%rax), %rdi
leaq 0x49fd(%rip), %rsi      # 0x599f0
xorl %eax, %eax
movb %al, -0xd9(%rbp)
callq 0x74c0
movq -0xe8(%rbp), %rcx
movb -0xd9(%rbp), %al
movl 0x35bfd(%rip), %edx     # 0x8ac10
incl %edx
movl %edx, 0x35bf5(%rip)     # 0x8ac10
movq (%rcx), %rdi
leaq 0x49d6(%rip), %rsi      # 0x599fb
callq 0x74c0
leaq 0x35857(%rip), %rdi     # 0x8a888
callq 0x55770
jmp 0x55038
movq -0x90(%rbp), %rcx
leaq 0x358a2(%rip), %rax     # 0x8a8e8
movq %rcx, (%rax)
leaq 0x3588c(%rip), %rax     # 0x8a8dc
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x35880(%rip), %rax     # 0x8a8dc
movl %ecx, (%rax)
movl 0x35bac(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35ba3(%rip)     # 0x8ac10
leaq 0x35874(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4713(%rip), %rsi      # 0x59791
movb $0x0, %al
callq 0x74c0
leaq -0x70(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x49c90
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x49b10
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x55790
testb $0x1, %al
jne 0x550d3
jmp 0x55134
leaq -0xb0(%rbp), %rdi
callq 0x557d0
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
movq -0xc0(%rbp), %rsi
leaq 0x4908(%rip), %rdx      # 0x59a00
callq 0x521a0
jmp 0x550ff
movl 0x35b0b(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35b02(%rip)     # 0x8ac10
leaq 0x357d3(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4689(%rip), %rsi      # 0x597a8
movb $0x0, %al
callq 0x74c0
leaq -0xb0(%rbp), %rdi
callq 0x557f0
jmp 0x550ba
movl 0x35ad6(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35acd(%rip)     # 0x8ac10
leaq 0x3579e(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x24(%rbp), %edx
leaq 0x48ae(%rip), %rsi      # 0x59a05
movb $0x0, %al
callq 0x74c0
leaq -0x70(%rbp), %rdi
callq 0x55810
addq $0xf0, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x75e0
nopl (%rax)