// File: /workspace/github_c_makefile_star2_O3/mahrr[P]raven/src/compiler.c
// Function: map
static void map(Parser* parser) {
    Debug_Log(parser);

    if (consume_if(parser, TOKEN_RIGHT_BRACE)) {
        emit_bytes(parser, OP_MAP_8, 0);
        Debug_Exit(parser);
        return;
    }

    size_t count = 0;
    do {
        consume(parser, TOKEN_IDENTIFIER, "expect a map key name");

        // key
        RavString *key = object_string(
            &parser->vm->allocator,
            parser->previous.lexeme,
            parser->previous.length
        );
        emit_constant(parser, Obj_Value(key));

        consume(parser, TOKEN_COLON, "expect ':' after map key");

        if (count == MAP_LIMIT) {
            error_limit(parser, "map literal elements", MAP_LIMIT);
            break;
        }

        // value
        expression(parser);

        count++;
    } while (consume_if(parser, TOKEN_COMMA));

    if (count > UINT8_MAX) {
        emit_byte(parser, OP_MAP_16);
        emit_bytes(parser, (count >> 8) & 0xff, count & 0xff);
    } else {
        emit_bytes(parser, OP_MAP_8, (uint8_t)count);
    }

    consume(parser, TOKEN_RIGHT_BRACE, "expect '}' after map elements");

    Debug_Exit(parser);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x18(%rdi), %r14
movl 0x18(%rdi), %eax
leaq 0x30(%rdi), %r13
cmpl $0x2b, %eax
jne 0x7b73
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq %rsp, %r15
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x7b1d
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x28, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
xorl %esi, %esi
callq 0x4af1
jmp 0x7dca
xorl %ebp, %ebp
movq %rsp, %r15
cmpl $0x2f, %eax
jne 0x7bb2
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x7b8e
jmp 0x7bc4
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x40d8(%rip), %rdx      # 0xbc97
callq 0x61ef
movq 0x10(%rbx), %rdi
movq 0x38(%rbx), %rsi
movl 0x40(%rbx), %edx
callq 0x4fd0
movabsq $-0x4000000000000, %rcx # imm = 0xFFFC000000000000
orq %rcx, %rax
movq 0x8(%rbx), %rcx
movq 0x8(%rcx), %rdi
addq $0x20, %rdi
movq %rax, %rsi
callq 0x4b99
cmpl $0x100, %eax            # imm = 0x100
jl 0x7c27
movq %rbx, %rdi
leaq 0x3ce5(%rip), %rsi      # 0xb8eb
movl $0x100, %edx            # imm = 0x100
callq 0x621b
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl $0x0, 0x848(%rdi)
xorl %r12d, %r12d
jmp 0x7c32
movl %eax, %r12d
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl 0x44(%rbx), %edx
addq $0x20, %rdi
movl $0x3, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movzbl %r12b, %esi
callq 0x4af1
cmpl $0x27, 0x18(%rbx)
jne 0x7c96
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x7c72
jmp 0x7ca8
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x400a(%rip), %rdx      # 0xbcad
callq 0x61ef
cmpq $0x10000, %rbp          # imm = 0x10000
je 0x7d05
movq %rbx, %rdi
movl $0x1, %esi
callq 0x679e
leaq 0x1(%rbp), %r12
cmpl $0x25, 0x18(%rbx)
jne 0x7d21
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
movl 0x18(%rbx), %eax
cmpl $0x35, %eax
je 0x7cd9
movq %r12, %rbp
jmp 0x7b78
leaq 0x3fba(%rip), %rsi      # 0xbcc6
movq %rbx, %rdi
movl $0x10000, %edx          # imm = 0x10000
callq 0x621b
movl $0x10000, %r12d         # imm = 0x10000
jmp 0x7d2c
movb $0x28, %al
cmpq $0xff, %rbp
jb 0x7d4b
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x29, %esi
callq 0x4af1
movl %r12d, %eax
shrl $0x8, %eax
movq 0x8(%rbx), %rcx
movl 0x44(%rbx), %edx
movq 0x8(%rcx), %rdi
addq $0x20, %rdi
movzbl %al, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movzbl %r12b, %esi
callq 0x4af1
cmpl $0x2b, 0x18(%rbx)
jne 0x7db8
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq %rsp, %r15
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x7d94
jmp 0x7dca
leaq 0x3f1c(%rip), %rdx      # 0xbcdb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x61ef
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq