// File: /workspace/github_c_makefile_star2_O2/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 0xc41f
movq %rdi, %rbx
movq 0x20(%rdi), %rax
movb (%rax), %cl
leaq 0xcc57(%rip), %r15      # 0x18c88
movabsq $0x100002200, %r12      # imm = 0x100002200
testb %cl, %cl
je 0xc0cb
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
callq 0xd8a3
movl %eax, %ebp
movzbl %al, %r14d
leal -0x9(%r14), %eax
cmpl $0x35, %eax
ja 0xc09e
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0x20(%rbx), %rax
movzbl (%rax), %ecx
cmpq $0x20, %rcx
ja 0xc03b
btq %rcx, %r12
jae 0xc03b
movq %rbx, %rdi
callq 0xd8a3
jmp 0xc067
movq %rbx, %rdi
callq 0xd8a3
movq 0x20(%rbx), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0xc03b
cmpl $0xa, %ecx
jne 0xc084
jmp 0xc03b
leal -0x7b(%r14), %eax
cmpl $0x3, %eax
jbe 0xc0f1
cmpl $0x5b, %r14d
je 0xc2d1
cmpl $0x5d, %r14d
je 0xc2b9
cmpl $0x5e, %r14d
jne 0xc10d
pushq $0x13
popq %rsi
pushq $0x28
jmp 0xc32e
movl $0x1, 0x70(%rbx)
movl 0x18(%rbx), %ecx
movl %eax, %edx
subl %ecx, %edx
movl %edx, 0x80(%rbx)
movl 0x28(%rbx), %ecx
movl %ecx, 0x84(%rbx)
movq %rax, 0x78(%rbx)
jmp 0xc41f
leaq 0xcc68(%rip), %rcx      # 0x18d60
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xd, 0x70(%rbx)
jmp 0xc403
movsbl %bpl, %r15d
movl %r15d, %edi
callq 0xab7d
testb %al, %al
jne 0xc30c
movl %r15d, %edi
callq 0xab68
testb %al, %al
je 0xc364
movq 0x20(%rbx), %rax
movsbl (%rax), %ebp
movl %ebp, %edi
callq 0xab68
testb %al, %al
jne 0xc152
movl %ebp, %edi
callq 0xab7d
testb %al, %al
je 0xc37d
movq %rbx, %rdi
callq 0xd8a3
jmp 0xc131
pushq $0xf
popq %rsi
pushq $0x25
jmp 0xc32e
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc2f0
movl $0x4, 0x70(%rbx)
jmp 0xc403
pushq $0x11
popq %rsi
pushq $0x26
jmp 0xc32e
movl $0x7, 0x70(%rbx)
jmp 0xc403
pushq $0x1a
popq %rsi
pushq $0x1d
jmp 0xc32e
pushq $0x3e
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc322
pushq $0x3d
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc3c9
movl $0x2b, 0x70(%rbx)
jmp 0xc403
pushq $0x3c
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc329
pushq $0x3d
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc3d2
movl $0x2c, 0x70(%rbx)
jmp 0xc403
movl $0x6, 0x70(%rbx)
jmp 0xc403
pushq $0x2
popq %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd8b8
movq %rbx, %rdi
xorl %esi, %esi
jmp 0xc2a6
pushq $0x3a
popq %rsi
pushq $0x1e
jmp 0xc32e
pushq $0x15
popq %rsi
pushq $0x21
jmp 0xc32e
movl $0x9, 0x70(%rbx)
jmp 0xc403
pushq $0x17
popq %rsi
pushq $0x23
jmp 0xc32e
pushq $0x18
popq %rsi
pushq $0x24
jmp 0xc32e
movl $0x5, 0x70(%rbx)
jmp 0xc403
movl $0xa, 0x70(%rbx)
jmp 0xc403
pushq $0x3d
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc345
movl $0x22, 0x70(%rbx)
jmp 0xc403
pushq $0x1
popq %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdbe1
movl $0xc, 0x70(%rbx)
jmp 0xc403
movl $0xe, 0x70(%rbx)
jmp 0xc403
movl $0xb, 0x70(%rbx)
jmp 0xc403
movl $0x10, 0x70(%rbx)
jmp 0xc403
pushq $0x12
popq %rsi
pushq $0x27
jmp 0xc32e
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xab7d
testb %al, %al
je 0xc3c0
movq %rbx, %rdi
callq 0xd8a3
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd928
pushq $0x1b
popq %rsi
pushq $0x1f
jmp 0xc32e
pushq $0x1c
popq %rsi
pushq $0x20
popq %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd8e2
pushq $0x3e
popq %rsi
movq %rbx, %rdi
callq 0xd905
testb %al, %al
je 0xc3db
movl $0x14, 0x70(%rbx)
jmp 0xc403
addb $-0x20, %bpl
cmpb $0x5e, %bpl
ja 0xc3eb
leaq 0xd043(%rip), %rsi      # 0x193b8
movq %rbx, %rdi
movl %r15d, %edx
jmp 0xc3f8
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %r12
subq %r14, %r12
movslq %r12d, %r15
pushq $0xc
popq %r13
leaq 0x1684a(%rip), %rbp     # 0x22be0
cmpq $0x1ac, %r13            # imm = 0x1AC
je 0xc3e4
cmpl %r12d, -0x4(%r13,%rbp)
jne 0xc3ba
movq -0xc(%r13,%rbp), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2090
testl %eax, %eax
je 0xc42e
addq $0x10, %r13
jmp 0xc396
movl $0x3, 0x70(%rbx)
jmp 0xc403
movl $0x29, 0x70(%rbx)
jmp 0xc403
movl $0x2a, 0x70(%rbx)
jmp 0xc403
movl $0x16, 0x70(%rbx)
jmp 0xc403
pushq $0x47
jmp 0xc217
leaq 0xcfdd(%rip), %rsi      # 0x193cf
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xdd6b
andl $0x0, 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)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r13,%rbp), %esi
jmp 0xc218