// File: /workspace/github_c_makefile_star2_O1/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 0x10ed8
movq %rdi, %rbx
movq 0x20(%rdi), %rax
cmpb $0x0, (%rax)
je 0x10c39
leaq 0xd0af(%rip), %rdx      # 0x1dc70
movabsq $0x100002200, %rsi      # imm = 0x100002200
movq %rax, 0x18(%rbx)
movsbl (%rax), %r14d
movzbl %r14b, %r15d
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
cmpl $0x5c, %r15d
jg 0x10c62
leal -0x9(%r15), %edi
cmpl $0x35, %edi
ja 0x10ca5
movslq (%rdx,%rdi,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
movzbl (%rcx), %eax
cmpq $0x20, %rax
ja 0x10c2f
btq %rax, %rsi
jae 0x10c2f
movb (%rcx), %al
incq %rcx
movq %rcx, 0x20(%rbx)
cmpb $0xa, %al
jne 0x10bfb
incl 0x28(%rbx)
jmp 0x10bfb
incq %rcx
movq %rcx, 0x20(%rbx)
movzbl (%rcx), %eax
testl %eax, %eax
je 0x10c2f
cmpl $0xa, %eax
jne 0x10c1c
cmpb $0x0, (%rcx)
movq %rcx, %rax
jne 0x10bcb
jmp 0x10c3c
movq %rax, %rcx
movl $0x1, 0x70(%rbx)
movl 0x18(%rbx), %eax
movl %ecx, %edx
subl %eax, %edx
movl %edx, 0x80(%rbx)
movl 0x28(%rbx), %eax
movl %eax, 0x84(%rbx)
movq %rcx, 0x78(%rbx)
jmp 0x10ed8
leal -0x7b(%r15), %ecx
cmpl $0x3, %ecx
ja 0x10c87
leaq 0xd0d6(%rip), %rdx      # 0x1dd48
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0xd, 0x70(%rbx)
jmp 0x10ec1
cmpl $0x5d, %r15d
je 0x10d0a
cmpl $0x5e, %r15d
jne 0x10cb7
movq %rbx, %rdi
movl $0x13, %esi
movl $0x28, %edx
jmp 0x10fa8
cmpl $0x5b, %r15d
jne 0x10cb7
movl $0xb, 0x70(%rbx)
jmp 0x10ec1
movsbl %r14b, %ebp
movl %ebp, %edi
callq 0xf385
testb %al, %al
je 0x10ee7
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12568
movl $0xe, 0x70(%rbx)
jmp 0x10ec1
movl $0x10, 0x70(%rbx)
jmp 0x10ec1
movq %rbx, %rdi
movl $0x12, %esi
movl $0x27, %edx
jmp 0x10fa8
movl $0xc, 0x70(%rbx)
jmp 0x10ec1
cmpb $0x2e, (%rcx)
jne 0x10f2e
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x4, 0x70(%rbx)
jmp 0x10de3
cmpb $0x3c, (%rcx)
jne 0x10f60
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
cmpb $0x3d, 0x2(%rax)
jne 0x11037
leaq 0x3(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x2c, 0x70(%rbx)
jmp 0x10e74
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x10db8
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 0x10ed8
movl $0x5, 0x70(%rbx)
jmp 0x10ec1
movq %rbx, %rdi
movl $0x11, %esi
movl $0x26, %edx
jmp 0x10fa8
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12866
cmpb $0x3d, (%rcx)
jne 0x10f6f
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x22, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x2, 0x80(%rbx)
jmp 0x10ecf
movq %rbx, %rdi
movl $0x1a, %esi
movl $0x1d, %edx
jmp 0x10fa8
movq %rbx, %rdi
movl $0x18, %esi
movl $0x24, %edx
jmp 0x10fa8
movq %rbx, %rdi
movl $0x15, %esi
movl $0x21, %edx
jmp 0x10fa8
movl $0xa, 0x70(%rbx)
jmp 0x10ec1
movq %rbx, %rdi
movl $0x3a, %esi
movl $0x1e, %edx
jmp 0x10fa8
cmpb $0x3e, (%rcx)
jne 0x10f9b
leaq 0x2(%rax), %rcx
movq %rcx, 0x20(%rbx)
cmpb $0x3d, 0x2(%rax)
jne 0x11049
leaq 0x3(%rax), %rcx
movq %rcx, 0x20(%rbx)
movl $0x2b, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x3, 0x80(%rbx)
jmp 0x10ecf
movq %rbx, %rdi
movl $0x17, %esi
movl $0x23, %edx
jmp 0x10fa8
movl $0x7, 0x70(%rbx)
jmp 0x10ec1
movq %rbx, %rdi
movl $0xf, %esi
movl $0x25, %edx
jmp 0x10fa8
movl $0x9, 0x70(%rbx)
jmp 0x10ec1
movl $0x6, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x1, 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 %ebp, %edi
callq 0xf370
testb %al, %al
je 0x10fbb
movq 0x20(%rbx), %rax
movsbl (%rax), %ebp
movl %ebp, %edi
callq 0xf370
testb %al, %al
jne 0x10f17
movl %ebp, %edi
callq 0xf385
testb %al, %al
je 0x10fd9
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x10efa
incl 0x28(%rbx)
jmp 0x10efa
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xf385
testb %al, %al
je 0x1102e
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x10cca
incl 0x28(%rbx)
jmp 0x10cca
movq %rbx, %rdi
movl $0x1c, %esi
movl $0x20, %edx
jmp 0x10fa8
movq 0x20(%rbx), %rcx
cmpb $0x3e, (%rcx)
jne 0x11040
incq %rcx
movq %rcx, 0x20(%rbx)
movl $0x14, 0x70(%rbx)
movq %rax, 0x78(%rbx)
subl %eax, %ecx
movl %ecx, 0x80(%rbx)
jmp 0x10ecf
movq %rbx, %rdi
movl $0x1b, %esi
movl $0x1f, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1252c
leal -0x20(%r14), %eax
cmpb $0x5e, %al
ja 0x1106d
leaq 0xd3ce(%rip), %rsi      # 0x1e39c
movq %rbx, %rdi
movl %r14d, %edx
jmp 0x1107a
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %r12
subq %r14, %r12
movslq %r12d, %r15
leaq 0xce81(%rip), %rsi      # 0x1de6f
movl $0x10, %r13d
leaq 0x18be5(%rip), %rbp     # 0x29be0
cmpl %r12d, -0x8(%r13,%rbp)
jne 0x11015
movq %r14, %rdi
movq %r15, %rdx
callq 0x2090
testl %eax, %eax
je 0x110a0
movq (%r13,%rbp), %rsi
addq $0x10, %r13
cmpq $0x1b0, %r13            # imm = 0x1B0
jne 0x10ffb
movl $0x47, %eax
jmp 0x110a5
movl $0x3, 0x70(%rbx)
jmp 0x11088
movl $0x2a, 0x70(%rbx)
jmp 0x11050
movl $0x16, 0x70(%rbx)
jmp 0x11050
movl $0x29, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl 0x20(%rbx), %ecx
movl 0x28(%rbx), %edx
subl %eax, %ecx
movl %ecx, 0x80(%rbx)
movl %edx, 0x84(%rbx)
jmp 0x10ed8
leaq 0xd33f(%rip), %rsi      # 0x1e3b3
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x12a0e
movl $0x0, 0x70(%rbx)
movq 0x18(%rbx), %rax
movq %rax, 0x78(%rbx)
movl 0x20(%rbx), %ecx
subl %eax, %ecx
movl %ecx, 0x80(%rbx)
jmp 0x10ecf
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 0x10ed8