// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x50(%rcx), %rdx
movq %rdx, 0x30(%rax)
movq 0x58(%rcx), %rdx
movq %rdx, 0x38(%rax)
movq 0x60(%rcx), %rdx
movq %rdx, 0x40(%rax)
movq 0x68(%rcx), %rcx
movq %rcx, 0x48(%rax)
movq 0x20(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x70(%rcx), %rdx
movq %rdx, 0x50(%rax)
movq 0x78(%rcx), %rdx
movq %rdx, 0x58(%rax)
movq 0x80(%rcx), %rdx
movq %rdx, 0x60(%rax)
movq 0x88(%rcx), %rcx
movq %rcx, 0x68(%rax)
movq 0x20(%rsp), %rax
cmpl $0x1, 0x50(%rax)
jne 0x15a03
jmp 0x15f3b
jmp 0x15a05
movq 0x20(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x0, %eax
je 0x15f1a
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rdi
callq 0x187c0
movb %al, 0x1f(%rsp)
movsbl 0x1f(%rsp), %eax
addl $-0x9, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x75, %eax
ja 0x15e87
movq 0x10(%rsp), %rax
leaq 0x152b6(%rip), %rcx     # 0x2ad10
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rdi
movl $0x5, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x6, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x7, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
callq 0x18890
jmp 0x15f15
movq 0x20(%rsp), %rdi
movl $0x9, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0xa, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0xb, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0xc, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0xd, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0xe, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0xf, %edx
movl $0x25, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x10, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x11, %edx
movl $0x26, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x12, %edx
movl $0x27, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x13, %edx
movl $0x28, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x18810
jmp 0x15f3b
movq 0x20(%rsp), %rdi
callq 0x187a0
movb %al, 0x1f(%rsp)
movsbl 0x1f(%rsp), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, 0xf(%rsp)
je 0x15c03
movsbl 0x1f(%rsp), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, 0xf(%rsp)
je 0x15c03
movsbl 0x1f(%rsp), %eax
cmpl $0xd, %eax
sete %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x15c0d
jmp 0x15c27
movq 0x20(%rsp), %rdi
callq 0x187c0
movq 0x20(%rsp), %rdi
callq 0x187a0
movb %al, 0x1f(%rsp)
jmp 0x15bd4
jmp 0x15f15
movq 0x20(%rsp), %rdi
movl $0x2e, %esi
callq 0x18920
testb $0x1, %al
jne 0x15c41
jmp 0x15c52
movq 0x20(%rsp), %rdi
movl $0x4, %esi
callq 0x18810
jmp 0x15c91
movq 0x20(%rsp), %rdi
callq 0x187a0
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x15c6a
jmp 0x15c80
movq 0x20(%rsp), %rdi
callq 0x187c0
movq 0x20(%rsp), %rdi
callq 0x18970
jmp 0x15c8f
movq 0x20(%rsp), %rdi
movl $0x3, %esi
callq 0x18810
jmp 0x15c91
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x1a, %edx
movl $0x1d, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x3a, %edx
movl $0x1e, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3e, %esi
callq 0x18920
testb $0x1, %al
jne 0x15ce7
jmp 0x15d1e
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
callq 0x18920
testb $0x1, %al
jne 0x15cfc
jmp 0x15d0d
movq 0x20(%rsp), %rdi
movl $0x2b, %esi
callq 0x18810
jmp 0x15d1c
movq 0x20(%rsp), %rdi
movl $0x29, %esi
callq 0x18810
jmp 0x15d37
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x1b, %edx
movl $0x1f, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3c, %esi
callq 0x18920
testb $0x1, %al
jne 0x15d51
jmp 0x15d88
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
callq 0x18920
testb $0x1, %al
jne 0x15d66
jmp 0x15d77
movq 0x20(%rsp), %rdi
movl $0x2c, %esi
callq 0x18810
jmp 0x15d86
movq 0x20(%rsp), %rdi
movl $0x2a, %esi
callq 0x18810
jmp 0x15da1
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x1c, %edx
movl $0x20, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x15, %edx
movl $0x21, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
callq 0x18920
testb $0x1, %al
jne 0x15dd9
jmp 0x15dea
movq 0x20(%rsp), %rdi
movl $0x22, %esi
callq 0x18810
jmp 0x15e21
movq 0x20(%rsp), %rdi
movl $0x3e, %esi
callq 0x18920
testb $0x1, %al
jne 0x15dff
jmp 0x15e10
movq 0x20(%rsp), %rdi
movl $0x14, %esi
callq 0x18810
jmp 0x15e1f
movq 0x20(%rsp), %rdi
movl $0x16, %esi
callq 0x18810
jmp 0x15e21
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x17, %edx
movl $0x23, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x3d, %esi
movl $0x18, %edx
movl $0x24, %ecx
callq 0x188d0
jmp 0x15f3b
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x18e40
jmp 0x15f3b
movq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x18e40
jmp 0x15f3b
movsbl 0x1f(%rsp), %edi
callq 0x13f90
testb $0x1, %al
jne 0x15e97
jmp 0x15ea3
movq 0x20(%rsp), %rdi
callq 0x18970
jmp 0x15f13
movsbl 0x1f(%rsp), %edi
callq 0x13f30
testb $0x1, %al
jne 0x15eb3
jmp 0x15ebf
movq 0x20(%rsp), %rdi
callq 0x19050
jmp 0x15f11
movsbl 0x1f(%rsp), %eax
cmpl $0x20, %eax
jl 0x15eed
movsbl 0x1f(%rsp), %eax
cmpl $0x7e, %eax
jg 0x15eed
movq 0x20(%rsp), %rdi
movsbl 0x1f(%rsp), %edx
leaq 0x15651(%rip), %rsi     # 0x2b535
movb $0x0, %al
callq 0x19190
jmp 0x15f05
movq 0x20(%rsp), %rdi
movzbl 0x1f(%rsp), %edx
leaq 0x1564e(%rip), %rsi     # 0x2b54c
movb $0x0, %al
callq 0x19190
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x18810
jmp 0x15f13
jmp 0x15f3b
jmp 0x15a05
movq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x18810
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x78(%rax)
addq $0x28, %rsp
retq