// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x838, %rsp            # imm = 0x838
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movq (%rsi), %r13
testq %r13, %r13
je 0x11666
cmpl $0x16, (%r13)
jne 0x11666
cmpb $0x1, 0x14(%r13)
jne 0x11666
cmpl $0x0, 0x10(%r13)
jle 0x11666
movq 0x28(%r13), %rax
movq (%rax), %rax
movq 0x108(%rax), %rax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x111c3
cmpl $0x3f, 0x4bd0(%rbx)
jne 0x11956
testq %r14, %r14
je 0x11695
movq (%r14), %rax
leaq 0x30(%rsp), %r15
movq %rax, (%r15)
jmp 0x11698
xorl %r15d, %r15d
leaq 0x4ba8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rsp, %rcx
movq %rax, (%rcx)
leaq 0x4e18(%rbx), %r12
leaq 0x4220(%rbx), %rsi
movq %r12, %rdi
movq %rsi, 0x10(%rsp)
movl $0x16, %edx
callq 0x19a70
movq %rax, %rbp
movb $0x1, 0x14(%rax)
testq %r13, %r13
je 0x11736
cmpl $0x16, (%r13)
jne 0x11736
cmpb $0x1, 0x14(%r13)
jne 0x11736
movl 0x10(%r13), %eax
testl %eax, %eax
jle 0x11736
movslq 0x10(%rbp), %rcx
cmpl %ecx, %eax
jle 0x11736
movq 0x28(%r13), %rax
movq (%rax,%rcx,8), %rax
movq 0x108(%rax), %rsi
movq %rbx, %rdi
movq %rsp, %rdx
movq %r15, %rcx
movq %rsi, %r15
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xcabc
movq (%rsp), %rsi
movq %r15, %rdi
callq 0x1a220
testb %al, %al
je 0x11736
movq %r15, (%rsp)
movq (%rsp), %rax
cmpl $0x16, (%rax)
jne 0x11761
cmpb $0x1, 0x14(%rax)
jne 0x11761
cmpl $0x0, 0x10(%rax)
jle 0x11761
movq 0x5118(%rbx), %rdi
leaq 0x650c1(%rip), %rsi     # 0x7681a
xorl %eax, %eax
callq *0x50f8(%rbx)
cmpl $0x100, 0x10(%rbp)      # imm = 0x100
jl 0x11780
movq 0x5118(%rbx), %rdi
leaq 0x650ca(%rip), %rsi     # 0x76842
xorl %eax, %eax
callq *0x50f8(%rbx)
movq (%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x1a697
cmpl $0x3f, 0x4bd0(%rbx)
jne 0x1180b
testq %r14, %r14
je 0x117ad
movslq 0x10(%rbp), %rax
leaq (%rsp,%rax,8), %r15
addq $0x30, %r15
jmp 0x117b0
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
callq 0x15914
movq $0x0, (%rsp)
testq %r13, %r13
je 0x117f8
cmpl $0x16, (%r13)
jne 0x117f8
cmpb $0x1, 0x14(%r13)
jne 0x117f8
movl 0x10(%r13), %eax
testl %eax, %eax
jle 0x117f8
movslq 0x10(%rbp), %rcx
cmpl %ecx, %eax
jle 0x117f8
movq 0x28(%r13), %rax
movq (%rax,%rcx,8), %rax
movq 0x108(%rax), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
movq %r15, %rdx
callq 0x111c3
jmp 0x116d9
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
testq %r14, %r14
je 0x11843
leaq 0xf0(%rbx), %r15
movq %r12, %rdi
movq %rbp, %rsi
callq 0x19e29
movslq %eax, %rsi
movq %r15, %rdi
callq 0x7a70
movq %rax, (%r14)
movq $0x0, 0x10(%rsp)
jmp 0x11874
leaq 0x4e38(%rbx), %rdi
leaq 0x100(%rbx), %rdx
movq %r12, %rsi
movq 0x10(%rsp), %rcx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x153ba
movq %rbx, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rsi
callq 0x17011
movq 0x8(%rsp), %rax
movq (%rax), %rax
movslq 0x10(%rax), %r13
testq %r13, %r13
jle 0x11944
leaq 0x4e68(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x4e70(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq (%rsp,%r13,8), %r15
addq $0x28, %r15
incq %r13
movq %rbx, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rax,%r13,8), %rbp
movq 0x108(%rbp), %rsi
movq %r12, %rdi
callq 0x19e29
movslq 0x110(%rbp), %rsi
testq %r14, %r14
je 0x118fb
addq (%r14), %rsi
movq 0x108(%rbp), %rcx
movl (%rcx), %ecx
movq 0x18(%rsp), %rdi
movq %r15, %rdx
movl %eax, %r8d
callq 0x9d0e
jmp 0x11933
movq 0x10(%rsp), %rax
addl 0x120(%rax), %esi
movq %r14, %rbx
movq %r12, %r14
movq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x12f97
movq 0x108(%rbp), %rsi
movq %r12, %rdi
movq %r14, %r12
movq %rbx, %r14
movq 0x20(%rsp), %rbx
callq 0x1362e
decq %r13
addq $-0x8, %r15
cmpq $0x1, %r13
ja 0x118b1
testq %r14, %r14
jne 0x11956
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xc9da
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq