// File: /workspace/github_c_makefile_star2_O0/atomlang[P]atomlang/src/pk_compiler.c
// Function: eatNumber
static void eatNumber(Compiler* compiler) {

#define IS_HEX_CHAR(c)            \
  (('0' <= (c) && (c) <= '9')  || \
   ('a' <= (c) && (c) <= 'f'))

#define IS_BIN_CHAR(c) (((c) == '0') || ((c) == '1'))

  Var value = VAR_NULL; // The number value.
  char c = *compiler->token_start;

  // Binary literal.
  if (c == '0' && peekChar(compiler) == 'b') {
    eatChar(compiler); // Consume '0b'

    uint64_t bin = 0;
    c = peekChar(compiler);
    if (!IS_BIN_CHAR(c)) {
      lexError(compiler, "Invalid binary literal.");

    } else {
      do {
        // Consume the next digit.
        c = peekChar(compiler);
        if (!IS_BIN_CHAR(c)) break;
        eatChar(compiler);

        // Check the length of the binary literal.
        int length = (int)(compiler->current_char - compiler->token_start);
        if (length > STR_BIN_BUFF_SIZE - 2) { // -2: '-\0' 0b is in both side.
          lexError(compiler, "Binary literal is too long.");
          break;
        }

        // "Append" the next digit at the end.
        bin = (bin << 1) | (c - '0');

      } while (true);
    }
    value = VAR_NUM((double)bin);

  } else if (c == '0' && peekChar(compiler) == 'x') {
    eatChar(compiler); // Consume '0x'

    uint64_t hex = 0;
    c = peekChar(compiler);

    // The first digit should be either hex digit.
    if (!IS_HEX_CHAR(c)) {
      lexError(compiler, "Invalid hex literal.");

    } else {
      do {
        // Consume the next digit.
        c = peekChar(compiler);
        if (!IS_HEX_CHAR(c)) break;
        eatChar(compiler);

        // Check the length of the binary literal.
        int length = (int)(compiler->current_char - compiler->token_start);
        if (length > STR_HEX_BUFF_SIZE - 2) { // -2: '-\0' 0x is in both side.
          lexError(compiler, "Hex literal is too long.");
          break;
        }

        // "Append" the next digit at the end.
        uint8_t append_val = ('0' <= c && c <= '9')
          ? (uint8_t)(c - '0')
          : (uint8_t)((c - 'a') + 10);
        hex = (hex << 4) | append_val;

      } while (true);

      value = VAR_NUM((double)hex);
    }

  } else { // Regular number literal.
    while (utilIsDigit(peekChar(compiler))) {
      eatChar(compiler);
    }

    if (peekChar(compiler) == '.' && utilIsDigit(peekNextChar(compiler))) {
      matchChar(compiler, '.');
      while (utilIsDigit(peekChar(compiler))) {
        eatChar(compiler);
      }
    }

    // Parse if in scientific notation format (MeN == M * 10 ** N).
    if (matchChar(compiler, 'e') || matchChar(compiler, 'E')) {

      if (peekChar(compiler) == '+' || peekChar(compiler) == '-') {
        eatChar(compiler);
      }

      if (!utilIsDigit(peekChar(compiler))) {
        lexError(compiler, "Invalid number literal.");

      } else { // Eat the exponent.
        while (utilIsDigit(peekChar(compiler))) eatChar(compiler);
      }
    }

    errno = 0;
    value = VAR_NUM(atof(compiler->token_start));
    if (errno == ERANGE) {
      const char* start = compiler->token_start;
      int len = (int)(compiler->current_char - start);
      lexError(compiler, "Number literal is too large (%.*s).", len, start);
      value = VAR_NUM(0);
    }
  }

  setNextValueToken(compiler, TK_NUMBER, value);
#undef IS_BIN_CHAR
#undef IS_HEX_CHAR
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movabsq $0x7ffc000000000000, %rax # imm = 0x7FFC000000000000
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movb (%rax), %al
movb %al, 0x37(%rsp)
movsbl 0x37(%rsp), %eax
cmpl $0x30, %eax
jne 0x18acd
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x62, %eax
jne 0x18acd
movq 0x40(%rsp), %rdi
callq 0x187c0
movq $0x0, 0x28(%rsp)
movq 0x40(%rsp), %rdi
callq 0x187a0
movb %al, 0x37(%rsp)
movsbl 0x37(%rsp), %eax
cmpl $0x30, %eax
je 0x18a08
movsbl 0x37(%rsp), %eax
cmpl $0x31, %eax
je 0x18a08
movq 0x40(%rsp), %rdi
leaq 0x12b62(%rip), %rsi     # 0x2b55e
movb $0x0, %al
callq 0x19190
jmp 0x18a96
jmp 0x18a0a
movq 0x40(%rsp), %rdi
callq 0x187a0
movb %al, 0x37(%rsp)
movsbl 0x37(%rsp), %eax
cmpl $0x30, %eax
je 0x18a2e
movsbl 0x37(%rsp), %eax
cmpl $0x31, %eax
je 0x18a2e
jmp 0x18a94
movq 0x40(%rsp), %rdi
callq 0x187c0
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl %eax, 0x24(%rsp)
cmpl $0x42, 0x24(%rsp)
jle 0x18a6d
movq 0x40(%rsp), %rdi
leaq 0x12b12(%rip), %rsi     # 0x2b576
movb $0x0, %al
callq 0x19190
jmp 0x18a94
movq 0x28(%rsp), %rax
shlq %rax
movsbl 0x37(%rsp), %ecx
subl $0x30, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
movq %rax, 0x28(%rsp)
movb $0x1, %al
testb $0x1, %al
jne 0x18a0a
jmp 0x18a94
jmp 0x18a96
movaps 0x12493(%rip), %xmm1    # 0x2af30
movq 0x28(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x12491(%rip), %xmm1    # 0x2af40
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x45b0
movq %rax, 0x38(%rsp)
jmp 0x18e27
movsbl 0x37(%rsp), %eax
cmpl $0x30, %eax
jne 0x18c77
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x78, %eax
jne 0x18c77
movq 0x40(%rsp), %rdi
callq 0x187c0
movq $0x0, 0x18(%rsp)
movq 0x40(%rsp), %rdi
callq 0x187a0
movb %al, 0x37(%rsp)
movsbl 0x37(%rsp), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x18b2a
movsbl 0x37(%rsp), %eax
cmpl $0x39, %eax
jle 0x18b5a
movsbl 0x37(%rsp), %ecx
movl $0x61, %eax
cmpl %ecx, %eax
jg 0x18b42
movsbl 0x37(%rsp), %eax
cmpl $0x66, %eax
jle 0x18b5a
movq 0x40(%rsp), %rdi
leaq 0x12a44(%rip), %rsi     # 0x2b592
movb $0x0, %al
callq 0x19190
jmp 0x18c72
jmp 0x18b5c
movq 0x40(%rsp), %rdi
callq 0x187a0
movb %al, 0x37(%rsp)
movsbl 0x37(%rsp), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x18b82
movsbl 0x37(%rsp), %eax
cmpl $0x39, %eax
jle 0x18b9f
movsbl 0x37(%rsp), %ecx
movl $0x61, %eax
cmpl %ecx, %eax
jg 0x18b9a
movsbl 0x37(%rsp), %eax
cmpl $0x66, %eax
jle 0x18b9f
jmp 0x18c40
movq 0x40(%rsp), %rdi
callq 0x187c0
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl %eax, 0x14(%rsp)
cmpl $0x12, 0x14(%rsp)
jle 0x18bde
movq 0x40(%rsp), %rdi
leaq 0x129d2(%rip), %rsi     # 0x2b5a7
movb $0x0, %al
callq 0x19190
jmp 0x18c40
movsbl 0x37(%rsp), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x18c06
movsbl 0x37(%rsp), %eax
cmpl $0x39, %eax
jg 0x18c06
movsbl 0x37(%rsp), %eax
subl $0x30, %eax
movzbl %al, %eax
movl %eax, (%rsp)
jmp 0x18c17
movsbl 0x37(%rsp), %eax
subl $0x61, %eax
addl $0xa, %eax
movzbl %al, %eax
movl %eax, (%rsp)
movl (%rsp), %eax
movb %al, 0x13(%rsp)
movq 0x18(%rsp), %rax
shlq $0x4, %rax
movzbl 0x13(%rsp), %ecx
orq %rcx, %rax
movq %rax, 0x18(%rsp)
movb $0x1, %al
testb $0x1, %al
jne 0x18b5c
jmp 0x18c40
movaps 0x122e9(%rip), %xmm1    # 0x2af30
movq 0x18(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x122e7(%rip), %xmm1    # 0x2af40
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x45b0
movq %rax, 0x38(%rsp)
jmp 0x18e25
jmp 0x18c79
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x18c91
jmp 0x18c9d
movq 0x40(%rsp), %rdi
callq 0x187c0
jmp 0x18c79
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x2e, %eax
jne 0x18cfc
movq 0x40(%rsp), %rdi
callq 0x19270
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x18cc7
jmp 0x18cfc
movq 0x40(%rsp), %rdi
movl $0x2e, %esi
callq 0x18920
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x18cee
jmp 0x18cfa
movq 0x40(%rsp), %rdi
callq 0x187c0
jmp 0x18cd6
jmp 0x18cfc
movq 0x40(%rsp), %rdi
movl $0x65, %esi
callq 0x18920
testb $0x1, %al
jne 0x18d27
movq 0x40(%rsp), %rdi
movl $0x45, %esi
callq 0x18920
testb $0x1, %al
jne 0x18d27
jmp 0x18daa
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x2b, %eax
je 0x18d4b
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %eax
cmpl $0x2d, %eax
jne 0x18d55
movq 0x40(%rsp), %rdi
callq 0x187c0
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x18d80
movq 0x40(%rsp), %rdi
leaq 0x12849(%rip), %rsi     # 0x2b5c0
movb $0x0, %al
callq 0x19190
jmp 0x18da8
jmp 0x18d82
movq 0x40(%rsp), %rdi
callq 0x187a0
movsbl %al, %edi
callq 0x13f90
testb $0x1, %al
jne 0x18d9a
jmp 0x18da6
movq 0x40(%rsp), %rdi
callq 0x187c0
jmp 0x18d82
jmp 0x18da8
jmp 0x18daa
callq 0x2050
movl $0x0, (%rax)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x20d0
callq 0x45b0
movq %rax, 0x38(%rsp)
callq 0x2050
cmpl $0x22, (%rax)
jne 0x18e23
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x4(%rsp)
movq 0x40(%rsp), %rdi
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
leaq 0x127c9(%rip), %rsi     # 0x2b5d8
movb $0x0, %al
callq 0x19190
xorps %xmm0, %xmm0
callq 0x45b0
movq %rax, 0x38(%rsp)
jmp 0x18e25
jmp 0x18e27
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rdx
movl $0x48, %esi
callq 0x192b0
addq $0x48, %rsp
retq