// File: /workspace/github_c_makefile_star2_O2/atomlang[P]atomlang/src/pk_compiler.c
// Function: eatString
static void eatString(Compiler* compiler, bool single_quote) {
  pkByteBuffer buff;
  pkByteBufferInit(&buff);

  char quote = (single_quote) ? '\'' : '"';

  while (true) {
    char c = eatChar(compiler);

    if (c == quote) break;

    if (c == '\0') {
      lexError(compiler, "Non terminated string.");

      // Null byte is required by TK_EOF.
      compiler->current_char--;
      break;
    }

    if (c == '\\') {
      switch (eatChar(compiler)) {
        case '"':  pkByteBufferWrite(&buff, compiler->vm, '"'); break;
        case '\'': pkByteBufferWrite(&buff, compiler->vm, '\''); break;
        case '\\': pkByteBufferWrite(&buff, compiler->vm, '\\'); break;
        case 'n':  pkByteBufferWrite(&buff, compiler->vm, '\n'); break;
        case 'r':  pkByteBufferWrite(&buff, compiler->vm, '\r'); break;
        case 't':  pkByteBufferWrite(&buff, compiler->vm, '\t'); break;

        default:
          lexError(compiler, "Error: invalid escape character");
          break;
      }
    } else {
      pkByteBufferWrite(&buff, compiler->vm, c);
    }
  }

  // '\0' will be added by varNewSring();
  Var string = VAR_OBJ(newStringLength(compiler->vm, (const char*)buff.data,
                       (uint32_t)buff.count));

  pkByteBufferClear(&buff, compiler->vm);

  setNextValueToken(compiler, TK_STRING, string);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x2b9a
leal (%r15,%r15,4), %r13d
addl $0x22, %r13d
pushq $0xd
popq %rbp
pushq $0x22
popq %r15
leaq 0xb87e(%rip), %r12      # 0x19496
movq %rbx, %rdi
callq 0xd8a3
movsbl %al, %ecx
cmpl %ecx, %r13d
je 0xdd06
cmpb $0x5c, %al
je 0xdc48
movzbl %al, %edx
testl %edx, %edx
je 0xdcf1
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2c3c
jmp 0xdc18
movq %rbx, %rdi
callq 0xd8a3
cmpb $0x74, %al
je 0xdcde
movzbl %al, %eax
cmpl $0x27, %eax
je 0xdccb
cmpl $0x5c, %eax
je 0xdc84
cmpl $0x6e, %eax
je 0xdca6
cmpl $0x72, %eax
je 0xdc94
cmpl $0x22, %eax
jne 0xdcb9
movq (%rbx), %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x2c3c
jmp 0xdc18
movq (%rbx), %rsi
movq %r14, %rdi
pushq $0x5c
popq %rdx
callq 0x2c3c
jmp 0xdc18
movq (%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x2c3c
jmp 0xdc18
movq (%rbx), %rsi
movq %r14, %rdi
pushq $0xa
popq %rdx
callq 0x2c3c
jmp 0xdc18
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xdd6b
jmp 0xdc18
movq (%rbx), %rsi
movq %r14, %rdi
pushq $0x27
popq %rdx
callq 0x2c3c
jmp 0xdc18
movq (%rbx), %rsi
movq %r14, %rdi
pushq $0x9
popq %rdx
callq 0x2c3c
jmp 0xdc18
leaq 0xb787(%rip), %rsi      # 0x1947f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdd6b
decq 0x20(%rbx)
movq (%rbx), %rdi
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
movl 0x8(%r14), %edx
callq 0x261f
movabsq $-0x4000000000000, %r15 # imm = 0xFFFC000000000000
orq %rax, %r15
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2ba1
movl $0x49, 0x70(%rbx)
movq 0x18(%rbx), %rax
movq %rax, 0x78(%rbx)
movl 0x20(%rbx), %ecx
subl %eax, %ecx
movl %ecx, 0x80(%rbx)
movl 0x28(%rbx), %eax
movl %eax, 0x84(%rbx)
movq %r15, 0x88(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq