// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x18, %rsp
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x84c3
leal (%r15,%r15,4), %ebp
addl $0x22, %ebp
leaq 0xb155(%rip), %r15      # 0x1d4b6
movq 0x20(%rbx), %rcx
movsbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
cmpl $0xa, %eax
jne 0x12378
incl 0x28(%rbx)
cmpl %eax, %ebp
je 0x1247d
cmpb $0x5c, %al
je 0x1239f
movzbl %al, %ecx
testl %ecx, %ecx
je 0x12468
movq (%rbx), %rsi
movzbl %al, %edx
movq %r14, %rdi
callq 0x8562
jmp 0x12361
movzbl 0x1(%rcx), %eax
addq $0x2, %rcx
movq %rcx, 0x20(%rbx)
cmpl $0x5b, %eax
jle 0x123d1
cmpl $0x71, %eax
jg 0x123f5
cmpl $0x5c, %eax
je 0x12429
cmpl $0x6e, %eax
jne 0x12417
movq (%rbx), %rsi
movq %r14, %rdi
movl $0xa, %edx
callq 0x8562
jmp 0x12361
cmpl $0xa, %eax
je 0x12414
cmpl $0x22, %eax
je 0x12453
cmpl $0x27, %eax
jne 0x12417
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x27, %edx
callq 0x8562
jmp 0x12361
cmpl $0x72, %eax
je 0x1243e
cmpl $0x74, %eax
jne 0x12417
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x9, %edx
callq 0x8562
jmp 0x12361
incl 0x28(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x124de
jmp 0x12361
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x5c, %edx
callq 0x8562
jmp 0x12361
movq (%rbx), %rsi
movq %r14, %rdi
movl $0xd, %edx
callq 0x8562
jmp 0x12361
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x22, %edx
callq 0x8562
jmp 0x12361
leaq 0xb030(%rip), %rsi      # 0x1d49f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x124de
decq 0x20(%rbx)
movq (%rbx), %rdi
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
movl 0x8(%r14), %edx
callq 0x7f0c
movabsq $-0x4000000000000, %r15 # imm = 0xFFFC000000000000
orq %rax, %r15
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x84ca
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 %r14
popq %r15
popq %rbp
retq