is_number
This commit is contained in:
parent
82104cfe0d
commit
44ee13246e
|
|
@ -365,8 +365,56 @@ is_ident:
|
||||||
pop rbp
|
pop rbp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;; Numbers are sequences of numeric characters, interspersed with underscores
|
||||||
|
;; The leading character must be numeric
|
||||||
|
;; In the future, numbers may be prefixed with '0x' for hexadecimal or '0b' for binary.
|
||||||
is_number:
|
is_number:
|
||||||
|
push rbp
|
||||||
|
mov rbp, rsp
|
||||||
|
push r12
|
||||||
|
push r13
|
||||||
|
push r14
|
||||||
|
|
||||||
|
mov rax, [rel cursor]
|
||||||
|
mov r12, [rel buffer]
|
||||||
|
mov r13, [rel buffer_len]
|
||||||
|
add r12, rax
|
||||||
|
sub r13, rax
|
||||||
|
|
||||||
|
mov dil, [r12]
|
||||||
|
call is_numeric
|
||||||
|
test rax, rax
|
||||||
|
je .not_number
|
||||||
|
|
||||||
|
mov r14, 1
|
||||||
|
.loop:
|
||||||
|
cmp r14, r13
|
||||||
|
jge .number
|
||||||
|
mov dil, [r12 + r14]
|
||||||
|
call is_whitespace
|
||||||
|
test rax, rax
|
||||||
|
je .number
|
||||||
|
cmp dil, '_'
|
||||||
|
je .loop_next
|
||||||
|
call is_numeric
|
||||||
|
test rax, rax
|
||||||
|
je .not_number
|
||||||
|
.loop_next:
|
||||||
|
inc r14
|
||||||
|
jmp .loop
|
||||||
|
.number:
|
||||||
|
mov rax, [rel cursor]
|
||||||
|
add rax, r14
|
||||||
|
mov [rel cursor], rax
|
||||||
|
mov rax, r14
|
||||||
|
jmp .epilogue
|
||||||
|
.not_number:
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
|
.epilogue:
|
||||||
|
pop r14
|
||||||
|
pop r13
|
||||||
|
pop r12
|
||||||
|
pop rbp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
skip_whitespaces:
|
skip_whitespaces:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue