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

    Allocator *allocator = &parser->vm->allocator;
    RavString *begin = object_string(
        allocator,
        parser->previous.lexeme + 1, // +1 advances the double quote
        parser->previous.length - 3  // -3 for the delimiters count
    );
    emit_constant(parser, Obj_Value(begin));

    while (parser->previous.type != TOKEN_STRING_END) {
        expression(parser);
        emit_byte(parser, OP_CONCAT);

        bool string_part = consume_if(parser, TOKEN_STRING_PART);
        bool string_end = consume_if(parser, TOKEN_STRING_END);

        if (string_part || string_end) {
            const char *chars = parser->previous.lexeme + 2; // +2 advances '}}'
            int length = 0;

            // enclosed between '}}' and '{{'
            if (string_part) {
                length = parser->previous.length - 4;
            }
            // enclosed between '}}' and '"'
            else if (string_end) {
                length = parser->previous.length - 3;
            }

            if (length != 0) {
                RavString *part = object_string(allocator, chars, length);
                emit_constant(parser, Obj_Value(part));
                emit_byte(parser, OP_CONCAT);
            }
        } else {
            error_current(parser, "ill-formed interpolated string");
            break;
        }
    }

    Debug_Exit(parser);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
addq $0x1, %rsi
movq -0x8(%rbp), %rax
movl 0x40(%rax), %edx
subl $0x3, %edx
callq 0x7880
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movabsq $-0x4000000000000, %rax # imm = 0xFFFC000000000000
orq %rax, %rsi
callq 0xb5c0
movq -0x8(%rbp), %rax
cmpl $0x34, 0x30(%rax)
je 0xab7c
movq -0x8(%rbp), %rdi
callq 0x8fe0
movq -0x8(%rbp), %rdi
movl $0x24, %esi
callq 0x9000
movq -0x8(%rbp), %rdi
movl $0x33, %esi
callq 0x8c60
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rdi
movl $0x34, %esi
callq 0x8c60
andb $0x1, %al
movb %al, -0x1a(%rbp)
testb $0x1, -0x19(%rbp)
jne 0xaae0
testb $0x1, -0x1a(%rbp)
je 0xab65
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
testb $0x1, -0x19(%rbp)
je 0xab0c
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
subl $0x4, %eax
movl %eax, -0x2c(%rbp)
jmp 0xab21
testb $0x1, -0x1a(%rbp)
je 0xab1f
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
subl $0x3, %eax
movl %eax, -0x2c(%rbp)
jmp 0xab21
cmpl $0x0, -0x2c(%rbp)
je 0xab63
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x7880
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movabsq $-0x4000000000000, %rax # imm = 0xFFFC000000000000
orq %rax, %rsi
callq 0xb5c0
movq -0x8(%rbp), %rdi
movl $0x24, %esi
callq 0x9000
jmp 0xab77
movq -0x8(%rbp), %rdi
leaq 0x42af(%rip), %rsi      # 0xee1f
callq 0x9420
jmp 0xab7c
jmp 0xaa85
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)