From 44ee13246e6326eafe378a9b061f990fa392d901 Mon Sep 17 00:00:00 2001 From: janis Date: Tue, 28 Oct 2025 17:07:05 +0100 Subject: [PATCH] is_number --- lang/src/tokeniser.asm | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lang/src/tokeniser.asm b/lang/src/tokeniser.asm index 4341603..46fb908 100644 --- a/lang/src/tokeniser.asm +++ b/lang/src/tokeniser.asm @@ -365,8 +365,56 @@ is_ident: pop rbp 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: + 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 +.epilogue: + pop r14 + pop r13 + pop r12 + pop rbp ret skip_whitespaces: