// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_expr.c
// Function: parseExprList
void parseExprList(Compiler *comp, const Type **type, Const *constant)
{
    const Type *inferredType = *type;
    if (inferredType && typeExprListStruct(inferredType) && inferredType->numItems > 0)
        *type = inferredType->field[0]->type;

    parseExpr(comp, type, constant);

    if (comp->lex.tok.kind == TOK_COMMA)
    {
        // Expression list (syntactic sugar - actually a structure literal)
        Const fieldConstantBuf[MAX_IDENTS_IN_LIST], *fieldConstant = NULL;
        if (constant)
        {
            fieldConstantBuf[0] = *constant;
            fieldConstant = &fieldConstantBuf[0];
        }

        const Type *fieldType = *type;

        Type *exprListType = typeAdd(&comp->types, &comp->blocks, TYPE_STRUCT);
        exprListType->isExprList = true;

        // Evaluate expressions and get the total structure size
        while (1)
        {
            // Convert field to the desired type if necessary and possible (no error is thrown anyway)
            if (inferredType && typeExprListStruct(inferredType) && inferredType->numItems > exprListType->numItems)
            {
                const Type *inferredFieldType = inferredType->field[exprListType->numItems]->type;
                doImplicitTypeConv(comp, inferredFieldType, &fieldType, fieldConstant);
                if (typeCompatible(inferredFieldType, fieldType))
                    fieldType = inferredFieldType;
            }

            if (typeExprListStruct(fieldType))
                comp->error.handler(comp->error.context, "Nested expression lists are not allowed");

            if (exprListType->numItems >= MAX_IDENTS_IN_LIST)
                comp->error.handler(comp->error.context, "Too many expressions in list");

            typeAddField(&comp->types, exprListType, fieldType, NULL);

            if (comp->lex.tok.kind != TOK_COMMA)
                break;

            fieldConstant = constant ? &fieldConstantBuf[exprListType->numItems] : NULL;

            lexNext(&comp->lex);

            fieldType = NULL;
            if (inferredType && typeExprListStruct(inferredType) && inferredType->numItems > exprListType->numItems)
                fieldType = inferredType->field[exprListType->numItems]->type;

            parseExpr(comp, &fieldType, fieldConstant);
        }

        *type = exprListType;

        // Allocate structure
        const Ident *exprList = NULL;
        if (constant)
            constant->ptrVal = storageAdd(&comp->storage, typeSize(&comp->types, *type));
        else
        {
            exprList = identAllocTempVar(&comp->idents, &comp->types, &comp->modules, &comp->blocks, *type, false);
            doZeroVar(comp, exprList);
        }

        // Assign expressions
        for (int i = (*type)->numItems - 1; i >= 0; i--)
        {
            const Field *field = (*type)->field[i];
            int fieldSize = typeSize(&comp->types, field->type);

            if (constant)
                constAssign(&comp->consts, (char *)constant->ptrVal + field->offset, &fieldConstantBuf[i], field->type->kind, fieldSize);
            else
            {
                genPushLocalPtr(&comp->gen, exprList->offset + field->offset);
                genSwapChangeRefCntAssign(&comp->gen, field->type);
            }
        }

        if (!constant)
            doPushVarPtr(comp, exprList);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x870, %rsp            # imm = 0x870
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xeefb
movq -0x20(%rbp), %rdi
callq 0xf380
testb $0x1, %al
jne 0xeed8
jmp 0xeefb
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0xeefb
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq 0x108(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xe8c0
movq -0x8(%rbp), %rax
cmpl $0x3f, 0x4bd0(%rax)
jne 0xf374
movq $0x0, -0x828(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xef4b
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x820(%rbp)
leaq -0x820(%rbp), %rax
movq %rax, -0x828(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x830(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movl $0x16, %edx
callq 0x21950
movq %rax, -0x838(%rbp)
movq -0x838(%rbp), %rax
movb $0x1, 0x14(%rax)
cmpq $0x0, -0x20(%rbp)
je 0xf024
movq -0x20(%rbp), %rdi
callq 0xf380
testb $0x1, %al
jne 0xefa5
jmp 0xf024
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x838(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0xf024
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x838(%rbp), %rcx
movslq 0x10(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x108(%rax), %rax
movq %rax, -0x840(%rbp)
movq -0x8(%rbp), %rdi
movq -0x840(%rbp), %rsi
movq -0x828(%rbp), %rcx
leaq -0x830(%rbp), %rdx
callq 0xd190
movq -0x840(%rbp), %rdi
movq -0x830(%rbp), %rsi
callq 0x22790
testb $0x1, %al
jne 0xf014
jmp 0xf022
movq -0x840(%rbp), %rax
movq %rax, -0x830(%rbp)
jmp 0xf024
movq -0x830(%rbp), %rdi
callq 0xf380
testb $0x1, %al
jne 0xf036
jmp 0xf057
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1c98af(%rip), %rsi    # 0x1d8902
movb $0x0, %al
callq *%rcx
movq -0x838(%rbp), %rax
cmpl $0x100, 0x10(%rax)      # imm = 0x100
jl 0xf088
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1c98a6(%rip), %rsi    # 0x1d892a
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x838(%rbp), %rsi
movq -0x830(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x23070
movq -0x8(%rbp), %rax
cmpl $0x3f, 0x4bd0(%rax)
je 0xf0bc
jmp 0xf183
cmpq $0x0, -0x18(%rbp)
je 0xf0e5
movq -0x838(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq -0x820(%rbp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x868(%rbp)
jmp 0xf0f0
xorl %eax, %eax
movq %rax, -0x868(%rbp)
jmp 0xf0f0
movq -0x868(%rbp), %rax
movq %rax, -0x828(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq $0x0, -0x830(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xf167
movq -0x20(%rbp), %rdi
callq 0xf380
testb $0x1, %al
jne 0xf12f
jmp 0xf167
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x838(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0xf167
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x838(%rbp), %rcx
movslq 0x10(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x108(%rax), %rax
movq %rax, -0x830(%rbp)
movq -0x8(%rbp), %rdi
movq -0x828(%rbp), %rdx
leaq -0x830(%rbp), %rsi
callq 0xe8c0
jmp 0xef8b
movq -0x838(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x848(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf1e6
movq -0x8(%rbp), %rax
addq $0xf0, %rax
movq %rax, -0x870(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x21fe0
movq -0x870(%rbp), %rdi
movslq %eax, %rsi
callq 0x4b20
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0xf238
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
addq $0x4220, %rcx           # imm = 0x4220
movq -0x10(%rbp), %rax
movq (%rax), %r8
xorl %r9d, %r9d
callq 0x1a540
movq %rax, -0x848(%rbp)
movq -0x8(%rbp), %rdi
movq -0x848(%rbp), %rsi
callq 0x1d5e0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x84c(%rbp)
cmpl $0x0, -0x84c(%rbp)
jl 0xf35b
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movslq -0x84c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x858(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x858(%rbp), %rax
movq 0x108(%rax), %rsi
callq 0x21fe0
movl %eax, -0x85c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf2f6
movq -0x8(%rbp), %rdi
addq $0x4e68, %rdi           # imm = 0x4E68
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x858(%rbp), %rax
movslq 0x110(%rax), %rax
addq %rax, %rsi
movslq -0x84c(%rbp), %rax
leaq -0x820(%rbp), %rdx
shlq $0x3, %rax
addq %rax, %rdx
movq -0x858(%rbp), %rax
movq 0x108(%rax), %rax
movl (%rax), %ecx
movl -0x85c(%rbp), %r8d
callq 0x88c0
jmp 0xf345
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x848(%rbp), %rax
movq 0x120(%rax), %rax
movq -0x858(%rbp), %rcx
movslq 0x110(%rcx), %rcx
addq %rcx, %rax
movl %eax, %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x858(%rbp), %rax
movq 0x108(%rax), %rsi
callq 0x17500
jmp 0xf347
movl -0x84c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x84c(%rbp)
jmp 0xf24b
cmpq $0x0, -0x18(%rbp)
jne 0xf372
movq -0x8(%rbp), %rdi
movq -0x848(%rbp), %rsi
callq 0xd010
jmp 0xf374
addq $0x870, %rsp            # imm = 0x870
popq %rbp
retq
nopl (%rax)