// File: cphinton42[P]hinton-language/src/check.cpp
// Function: typecheck_enum(Context*, unsigned int, Expr_AST*, Enum_AST*)
internal
bool typecheck_enum(Context *ctx, u32 stage, Expr_AST *type, Enum_AST *enum_ast)
{
    u32 new_stage = 0;
    switch(stage)
    {
        case 0: {
            if(type)
            {
                Status status = types_match(ctx, type, &type_t_ast);
                if(status != Status::good)
                {
                    break;
                }
            }
        } // fall through
        case 1: {
            new_stage = 1;
            set_resolved_type(enum_ast, &type_t_ast);
            for(u64 i = 0; i < enum_ast->values.count; ++i)
            {
                // TODO: enum values should all have the same type
                auto job = make_typecheck_job(nullptr, enum_ast->values[i]);
                do_typecheck_job(ctx, job);
            }
            new_stage = 2;
        } // fall through
    }
    
    if(new_stage < 2)
    {
        auto job = make_typecheck_job(type, enum_ast, new_stage);
        array_add(ctx->waiting_jobs, job);
    }
    return new_stage != stage;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xa4(%rbp)
testl %eax, %eax
je 0x8060
jmp 0x8050
movl -0xa4(%rbp), %eax
subl $0x1, %eax
je 0x8092
jmp 0x8135
cmpq $0x0, -0x18(%rbp)
je 0x8090
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x17e7a(%rip), %rdx     # 0x1fef0
movl $0x1, %ecx
callq 0x9240
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x808e
jmp 0x8135
jmp 0x8090
jmp 0x8092
movl $0x1, -0x24(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x17e4c(%rip), %rsi     # 0x1fef0
callq 0x3be0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x812e
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movq -0x30(%rbp), %rsi
callq 0x16fb0
movq (%rax), %rdx
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x4a80
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x4b40
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x80b1
movl $0x2, -0x24(%rbp)
cmpl $0x2, -0x24(%rbp)
jae 0x81c8
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
leaq -0x78(%rbp), %rdi
callq 0x4a80
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x17b00(%rip), %rax     # 0x1fc80
movq %rax, -0xa0(%rbp)
movq 0x17afa(%rip), %rax     # 0x1fc88
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
leaq -0x90(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x17c30
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
setne %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)