// File: /workspace/github_c_makefile_star2_O1/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x18(%rdi), %rax
cmpb $0x30, (%rax)
jne 0x1261e
movq 0x20(%rbx), %rax
movzbl (%rax), %ecx
cmpl $0x78, %ecx
je 0x12744
cmpl $0x62, %ecx
jne 0x1261e
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movb 0x1(%rax), %al
andb $-0x2, %al
cmpb $0x30, %al
jne 0x12833
leaq 0xbe28(%rip), %r14      # 0x1e3dd
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
movb (%r12), %al
movl %eax, %ecx
andb $-0x2, %cl
cmpb $0x30, %cl
jne 0x127d7
incq %r12
movq %r12, 0x20(%rbx)
cmpb $0xa, %al
jne 0x125dc
incl 0x28(%rbx)
subl 0x18(%rbx), %r12d
cmpl $0x43, %r12d
jge 0x125f1
addb $-0x30, %al
movzbl %al, %eax
leaq (%rax,%r15,2), %r15
jmp 0x125fe
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x12a0e
cmpl $0x43, %r12d
jl 0x125b8
jmp 0x127d7
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x1261e
incl 0x28(%rbx)
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xf385
testb %al, %al
jne 0x12609
movq 0x20(%rbx), %rax
cmpb $0x2e, (%rax)
jne 0x1267b
movsbl 0x1(%rax), %edi
callq 0xf385
testb %al, %al
je 0x1267b
movq 0x20(%rbx), %rax
cmpb $0x2e, (%rax)
jne 0x1266b
incq %rax
movq %rax, 0x20(%rbx)
jmp 0x1266b
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x1266b
incl 0x28(%rbx)
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xf385
testb %al, %al
jne 0x12656
movq 0x20(%rbx), %rax
cmpb $0x65, (%rax)
je 0x1268d
movq 0x20(%rbx), %rax
cmpb $0x45, (%rax)
jne 0x126fb
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movzbl 0x1(%rax), %ecx
cmpl $0x2d, %ecx
je 0x126a3
cmpl $0x2b, %ecx
jne 0x126b3
addq $0x2, %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x126b3
incl 0x28(%rbx)
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xf385
testb %al, %al
je 0x126ea
movq 0x20(%rbx), %rax
movsbl (%rax), %edi
callq 0xf385
testb %al, %al
je 0x126fb
movq 0x20(%rbx), %rax
movb (%rax), %cl
incq %rax
movq %rax, 0x20(%rbx)
cmpb $0xa, %cl
jne 0x126c3
incl 0x28(%rbx)
jmp 0x126c3
leaq 0xbd36(%rip), %rsi      # 0x1e427
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12a0e
callq 0x2060
movq %rax, %r14
movl $0x0, (%rax)
movq 0x18(%rbx), %rdi
callq 0x20e0
callq 0x905b
cmpl $0x22, (%r14)
jne 0x127fd
movq 0x18(%rbx), %rcx
movl 0x20(%rbx), %edx
subl %ecx, %edx
leaq 0xbd0e(%rip), %rsi      # 0x1e43f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12a0e
xorpd %xmm0, %xmm0
jmp 0x127f8
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movb 0x1(%rax), %al
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
setae %cl
addb $-0x61, %al
cmpb $0x6, %al
setae %al
testb %al, %cl
jne 0x12849
leaq 0xbca0(%rip), %r14      # 0x1e40e
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
movb (%r12), %al
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
setae %dl
leal -0x61(%rax), %esi
cmpb $0x6, %sil
setae %sil
testb %sil, %dl
jne 0x127d7
incq %r12
movq %r12, 0x20(%rbx)
cmpb $0xa, %al
jne 0x127a0
incl 0x28(%rbx)
subl 0x18(%rbx), %r12d
cmpl $0x13, %r12d
jge 0x127c4
addb $-0x57, %al
cmpb $0xa, %cl
movzbl %cl, %ecx
movzbl %al, %eax
cmovbl %ecx, %eax
shlq $0x4, %r15
movzbl %al, %eax
orq %rax, %r15
jmp 0x127d1
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x12a0e
cmpl $0x13, %r12d
jl 0x12771
movq %r15, %xmm1
punpckldq 0xb5bc(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb5c4(%rip), %xmm1     # 0x1ddb0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0x905b
movl $0x48, 0x70(%rbx)
movq 0x18(%rbx), %rcx
movq %rcx, 0x78(%rbx)
movl 0x20(%rbx), %edx
subl %ecx, %edx
movl %edx, 0x80(%rbx)
movl 0x28(%rbx), %ecx
movl %ecx, 0x84(%rbx)
movq %rax, 0x88(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0xbb8b(%rip), %rsi      # 0x1e3c5
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12a0e
jmp 0x1273b
leaq 0xbba9(%rip), %rsi      # 0x1e3f9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12a0e
movabsq $0x7ffc000000000000, %rax # imm = 0x7FFC000000000000
jmp 0x127fd