// File: /workspace/github_c_makefile_star2_O3/atomlang[P]atomlang/src/pk_compiler.c
// Function: lexToken
static void lexToken(Compiler* compiler) {
  compiler->previous = compiler->current;
  compiler->current = compiler->next;

  if (compiler->current.type == TK_EOF) return;

  while (peekChar(compiler) != '\0') {
    compiler->token_start = compiler->current_char;
    char c = eatChar(compiler);

    switch (c) {
      case ',': setNextToken(compiler, TK_COMMA); return;
      case ':': setNextToken(compiler, TK_COLLON); return;
      case ';': setNextToken(compiler, TK_SEMICOLLON); return;
      case '#': skipLineComment(compiler); break;
      case '(': setNextToken(compiler, TK_LPARAN); return;
      case ')': setNextToken(compiler, TK_RPARAN); return;
      case '[': setNextToken(compiler, TK_LBRACKET); return;
      case ']': setNextToken(compiler, TK_RBRACKET); return;
      case '{': setNextToken(compiler, TK_LBRACE); return;
      case '}': setNextToken(compiler, TK_RBRACE); return;
      case '%':
        setNextTwoCharToken(compiler, '=', TK_PERCENT, TK_MODEQ);
        return;

      case '~': setNextToken(compiler, TK_TILD); return;

      case '&':
        setNextTwoCharToken(compiler, '=', TK_AMP, TK_ANDEQ);
        return;

      case '|':
        setNextTwoCharToken(compiler, '=', TK_PIPE, TK_OREQ);
        return;

      case '^':
        setNextTwoCharToken(compiler, '=', TK_CARET, TK_XOREQ);
        return;

      case '\n': setNextToken(compiler, TK_LINE); return;

      case ' ':
      case '\t':
      case '\r': {
        c = peekChar(compiler);
        while (c == ' ' || c == '\t' || c == '\r') {
          eatChar(compiler);
          c = peekChar(compiler);
        }
        break;
      }

      case '.':
        if (matchChar(compiler, '.')) {
          setNextToken(compiler, TK_DOTDOT); // '..'
        } else if (utilIsDigit(peekChar(compiler))) {
          eatChar(compiler);   // Consume the decimal point.
          eatNumber(compiler); // Consume the rest of the number
        } else {
          setNextToken(compiler, TK_DOT);    // '.'
        }
        return;

      case '=':
        setNextTwoCharToken(compiler, '=', TK_EQ, TK_EQEQ);
        return;

      case '!':
        setNextTwoCharToken(compiler, '=', TK_NOT, TK_NOTEQ);
        return;

      case '>':
        if (matchChar(compiler, '>')) {
          if (matchChar(compiler, '=')) {
            setNextToken(compiler, TK_SRIGHTEQ);
          } else {
            setNextToken(compiler, TK_SRIGHT);
          }
        } else {
          setNextTwoCharToken(compiler, '=', TK_GT, TK_GTEQ);
        }
        return;

      case '<':
        if (matchChar(compiler, '<')) {
          if (matchChar(compiler, '=')) {
            setNextToken(compiler, TK_SLEFTEQ);
          } else {
            setNextToken(compiler, TK_SLEFT);
          }
        } else {
          setNextTwoCharToken(compiler, '=', TK_LT, TK_LTEQ);
        }
        return;

      case '+':
        setNextTwoCharToken(compiler, '=', TK_PLUS, TK_PLUSEQ);
        return;

      case '-':
        if (matchChar(compiler, '=')) {
          setNextToken(compiler, TK_MINUSEQ);  // '-='
        } else if (matchChar(compiler, '>')) {
          setNextToken(compiler, TK_ARROW);    // '->'
        } else {
          setNextToken(compiler, TK_MINUS);    // '-'
        }
        return;

      case '*':
        setNextTwoCharToken(compiler, '=', TK_STAR, TK_STAREQ);
        return;

      case '/':
        setNextTwoCharToken(compiler, '=', TK_FSLASH, TK_DIVEQ);
        return;

      case '"': eatString(compiler, false); return;

      case '\'': eatString(compiler, true); return;

      default: {

        if (utilIsDigit(c)) {
          eatNumber(compiler);

        } else if (utilIsName(c)) {
          eatName(compiler);

        } else {
          if (c >= 32 && c <= 126) {
            lexError(compiler, "Invalid character '%c'", c);
          } else {
            lexError(compiler, "Invalid byte 0x%x", (uint8_t)c);
          }
          setNextToken(compiler, TK_ERROR);
        }
        return;
      }
    }
  }

  setNextToken(compiler, TK_EOF);
  compiler->next.start = compiler->current_char;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movups 0x50(%rdi), %xmm0
movups 0x60(%rdi), %xmm1
movups 0x70(%rdi), %xmm2
movups 0x80(%rdi), %xmm3
movups %xmm1, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm2, 0x50(%rdi)
movups %xmm3, 0x60(%rdi)
cmpl $0x1, 0x50(%rdi)
je 0x10c47
movq %rdi, %rbx
movq 0x20(%rdi), %rcx
cmpb $0x0, (%rcx)
je 0x10833
leaq 0xc4d0(%rip), %rdx      # 0x1cc8c
movabsq $0x100002200, %rsi      # imm = 0x100002200
movq %rcx, %rax
movq %rcx, 0x18(%rbx)
movsbl (%rcx), %r14d
movzbl %r14b, %r15d
incq %rcx
movq %rcx, 0x20(%rbx)
cmpl $0x5c, %r15d
jg 0x1085a
leal -0x9(%r15), %edi
cmpl $0x35, %edi
ja 0x108af
movslq (%rdx,%rdi,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
movzbl (%rcx), %edi
cmpq $0x20, %rdi
ja 0x1082c
btq %rdi, %rsi
jae 0x1082c
incq %rcx
movq %rcx, 0x20(%rbx)
cmpb $0xa, %dil
jne 0x107f8
incl 0x28(%rbx)
jmp 0x107f8
incq %rcx
movq %rcx, 0x20(%rbx)
movzbl (%rcx), %edi
testl %edi, %edi
je 0x1082c
cmpl $0xa, %edi
jne 0x10819
testb %dil, %dil
jne 0x107c6
jmp 0x10837
movq 0x18(%rbx), %rax
movl $0x1, 0x70(%rbx)
movl %ecx, %edx
subl %eax, %edx
movl %edx, 0x80(%rbx)
movl 0x28(%rbx), %eax
movl %eax, 0x84(%rbx)
movq %rcx, 0x78(%rbx)
jmp 0x10c47
leal -0x7b(%r15), %edx
cmpl $0x3, %edx
ja 0x1087f
leaq 0xc4fa(%rip), %rsi      # 0x1cd64
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0xd, 0x70(%rbx)
jmp 0x10c09
cmpl $0x5d, %r15d
je 0x1091f
cmpl $0x5e, %r15d
jne 0x108c1
movl $0x13, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x28, %edx
jmp 0x10c2f
cmpl $0x5b, %r15d
jne 0x108c1
movl $0xb, 0x70(%rbx)
jmp 0x10c09
movl %r14d, %edi
callq 0xef1d
testb %al, %al
je 0x10b68
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1206c
movl $0xe, 0x70(%rbx)
jmp 0x10c09
movl $0x10, 0x70(%rbx)
jmp 0x10c09
movl $0x12, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x27, %edx
jmp 0x10c2f
movl $0xc, 0x70(%rbx)
jmp 0x10c09
movb (%rcx), %cl
cmpb $0x2e, %cl
jne 0x10bb1
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x4, 0x70(%rbx)
jmp 0x10cde
movzbl (%rcx), %esi
cmpl $0x3d, %esi
je 0x10bdf
movl $0x1c, %edx
cmpl $0x3c, %esi
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
cmpb $0x3d, 0x2(%rax)
jne 0x10cce
leaq 0x3(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x2c, 0x70(%rbx)
jmp 0x10af1
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x109ee
movl 0x28(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x28(%rbx)
movl $0x2, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x1, 0x80(%rbx)
movl %ecx, 0x84(%rbx)
jmp 0x10c47
movl $0x5, 0x70(%rbx)
jmp 0x10c09
movl $0x11, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x26, %edx
jmp 0x10c2f
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12336
movzbl (%rcx), %ecx
cmpl $0x3e, %ecx
je 0x10bee
cmpl $0x3d, %ecx
jne 0x10c02
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x22, 0x70(%rbx)
jmp 0x10cde
movl $0x1a, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x1d, %edx
jmp 0x10c2f
movl $0x18, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x24, %edx
jmp 0x10c2f
movl $0x15, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x21, %edx
jmp 0x10c2f
movl $0xa, 0x70(%rbx)
jmp 0x10c09
movl $0x3a, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x1e, %edx
jmp 0x10c2f
movzbl (%rcx), %esi
cmpl $0x3d, %esi
je 0x10c22
movl $0x1b, %edx
cmpl $0x3e, %esi
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
cmpb $0x3d, 0x2(%rax)
jne 0x10cd7
leaq 0x3(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x2b, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x3, 0x80(%rbx)
jmp 0x10c17
movl $0x17, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x23, %edx
jmp 0x10c2f
movl $0x7, 0x70(%rbx)
jmp 0x10c09
movl $0xf, %edx
cmpb $0x3d, (%rcx)
jne 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x25, %edx
jmp 0x10c2f
movl $0x9, 0x70(%rbx)
jmp 0x10c09
movl $0x6, 0x70(%rbx)
jmp 0x10c09
movsbl %r14b, %edi
callq 0xef08
testb %al, %al
je 0x10c56
movq 0x20(%rbx), %rax
movsbl (%rax), %ebp
movl %ebp, %edi
callq 0xef08
testb %al, %al
jne 0x10b9a
movl %ebp, %edi
callq 0xef1d
testb %al, %al
je 0x10c74
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x10b7d
incl 0x28(%rbx)
jmp 0x10b7d
movsbl %cl, %edi
callq 0xef1d
testb %al, %al
je 0x10cc5
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x108d1
incl 0x28(%rbx)
jmp 0x108d1
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x20, %edx
jmp 0x10c2f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x14, 0x70(%rbx)
jmp 0x10cde
movl $0x16, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x1, 0x80(%rbx)
movl 0x28(%rbx), %eax
movl %eax, 0x84(%rbx)
jmp 0x10c47
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x1f, %edx
subl %eax, %ecx
movl 0x28(%rbx), %esi
movl %edx, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl %ecx, 0x80(%rbx)
movl %esi, 0x84(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal -0x20(%r14), %eax
cmpb $0x5e, %al
ja 0x10cf1
leaq 0xc76f(%rip), %rsi      # 0x1d3d8
movq %rbx, %rdi
movl %r14d, %edx
jmp 0x10cfe
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %r12
subq %r14, %r12
movslq %r12d, %r15
leaq 0xc222(%rip), %rsi      # 0x1ceab
movl $0x10, %r13d
leaq 0x17f4a(%rip), %rbp     # 0x28be0
cmpl %r12d, -0x8(%r13,%rbp)
jne 0x10cac
movq %r14, %rdi
movq %r15, %rdx
callq 0x2090
testl %eax, %eax
je 0x10d24
movq (%r13,%rbp), %rsi
addq $0x10, %r13
cmpq $0x1b0, %r13            # imm = 0x1B0
jne 0x10c96
movl $0x47, %eax
jmp 0x10d29
movl $0x3, 0x70(%rbx)
jmp 0x10d0c
movl $0x2a, 0x70(%rbx)
jmp 0x10cde
movl $0x29, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x2, 0x80(%rbx)
jmp 0x10c17
leaq 0xc6f7(%rip), %rsi      # 0x1d3ef
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x124de
movl $0x0, 0x70(%rbx)
movq 0x18(%rbx), %rax
movq %rax, 0x78(%rbx)
movl 0x20(%rbx), %ecx
subl %eax, %ecx
movl %ecx, 0x80(%rbx)
jmp 0x10c17
movl -0x4(%r13,%rbp), %eax
movl %eax, 0x70(%rbx)
movq %r14, 0x78(%rbx)
movl %r12d, 0x80(%rbx)
movl 0x28(%rbx), %ecx
xorl %edx, %edx
cmpl $0x2, %eax
sete %dl
subl %edx, %ecx
movl %ecx, 0x84(%rbx)
jmp 0x10c47