// File: /workspace/github_c_makefile_star2_O1/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 0x8585
leal (%r15,%r15,4), %ebp
addl $0x22, %ebp
leaq 0xbbe9(%rip), %r15      # 0x1e47a
movq 0x20(%rbx), %rcx
movsbl (%rcx), %eax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
cmpl $0xa, %eax
jne 0x128a8
incl 0x28(%rbx)
cmpl %eax, %ebp
je 0x129ad
cmpb $0x5c, %al
je 0x128cf
movzbl %al, %ecx
testl %ecx, %ecx
je 0x12998
movq (%rbx), %rsi
movzbl %al, %edx
movq %r14, %rdi
callq 0x8624
jmp 0x12891
movzbl 0x1(%rcx), %eax
addq $0x2, %rcx
movq %rcx, 0x20(%rbx)
cmpl $0x5b, %eax
jle 0x12901
cmpl $0x71, %eax
jg 0x12925
cmpl $0x5c, %eax
je 0x12959
cmpl $0x6e, %eax
jne 0x12947
movq (%rbx), %rsi
movq %r14, %rdi
movl $0xa, %edx
callq 0x8624
jmp 0x12891
cmpl $0xa, %eax
je 0x12944
cmpl $0x22, %eax
je 0x12983
cmpl $0x27, %eax
jne 0x12947
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x27, %edx
callq 0x8624
jmp 0x12891
cmpl $0x72, %eax
je 0x1296e
cmpl $0x74, %eax
jne 0x12947
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x9, %edx
callq 0x8624
jmp 0x12891
incl 0x28(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x12a0e
jmp 0x12891
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x5c, %edx
callq 0x8624
jmp 0x12891
movq (%rbx), %rsi
movq %r14, %rdi
movl $0xd, %edx
callq 0x8624
jmp 0x12891
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x22, %edx
callq 0x8624
jmp 0x12891
leaq 0xbac4(%rip), %rsi      # 0x1e463
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12a0e
decq 0x20(%rbx)
movq (%rbx), %rdi
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
movl 0x8(%r14), %edx
callq 0x7fc8
movabsq $-0x4000000000000, %r15 # imm = 0xFFFC000000000000
orq %rax, %r15
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x858c
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