From: Aaron Taylor Date: Fri, 13 Mar 2020 04:50:16 +0000 (-0700) Subject: Added 'isdigit' function to stdlib. X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/commitdiff_plain/0e0d0a4a1058f9d75cea563a76c1113a0da87fc2 Added 'isdigit' function to stdlib. --- diff --git a/stdlib/README.md b/stdlib/README.md index 8427f53..40b9f4a 100644 --- a/stdlib/README.md +++ b/stdlib/README.md @@ -54,6 +54,7 @@ header comment for each function to learn the call and return stack. 11111 ----- spew (heap.pvvs) 100xxx - string functions 100000 ----- strlen (string.pvvs) + 100001 ----- isdigit (string.pvvs) 101xxx - logic functions 101000 ----- not (logic.pvvs) 101001 ----- and (logic.pvvs) diff --git a/stdlib/string.pvvs b/stdlib/string.pvvs index 5571349..8b68e22 100644 --- a/stdlib/string.pvvs +++ b/stdlib/string.pvvs @@ -36,4 +36,36 @@ NSSVSSTSSSSSSSSSSSSTN | Mark: 00100000 00000001 SNN | DROP NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ isdigit (100001) +@ Description: +@ Tests 'character' on stack. Is it an ASCII number? +@ Returns 1 or 0 representing True/False. +@ Call Stack: +@ character <-- TOS +@ Return Stack: +@ 1 or 0 <-- TOS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTSSSSTN | Mark: 100001 (isdigit) + +SSSSSTTSSSSN | PUSH 48 (ASCII '0') +TSST | SUBTRACT +SNS | DUP +NTTSSTSSSSTSSSSSSSSN | BMI > 00100001 00000000 (not digit) +SNS | DUP +SSSTSTSN | PUSH 10 +TSST | SUBTRACT +NTTSSTSSSSTSSSSSSSTN | BMI > 00100001 00000001 (is digit) + +NSSVSSTSSSSTSSSSSSSSN | Mark: 00100001 00000000 (not digit) +SNN | DROP +SSSSN | PUSH 0 +NTN | RTS + +NSSVSSTSSSSTSSSSSSSTN | Mark: 00100001 00000001 (is digit) +SNN | DROP +SSSTN | PUSH 1 +NTN | RTS + #endif diff --git a/stdlib_tests/4002_isdigit.pvvs b/stdlib_tests/4002_isdigit.pvvs new file mode 100644 index 0000000..e148e1a --- /dev/null +++ b/stdlib_tests/4002_isdigit.pvvs @@ -0,0 +1,20 @@ +SSSSSTSTTTTN | PUSH 47 (ASCII '/') +NSTTSSSSTN | JSR > 100001 (isdigit) +NSTTTTTSTN | JSR > 111101 (debug:printsignednumber) + +SSSSSTTSSSSN | PUSH 48 (ASCII '0') +NSTTSSSSTN | JSR > 100001 (isdigit) +NSTTTTTSTN | JSR > 111101 (debug:printsignednumber) + +SSSSSTTTSSTN | PUSH 57 (ASCII '9') +NSTTSSSSTN | JSR > 100001 (isdigit) +NSTTTTTSTN | JSR > 111101 (debug:printsignednumber) + +SSSSSTTTSTSN | PUSH 58 (ASCII ':') +NSTTSSSSTN | JSR > 100001 (isdigit) +NSTTTTTSTN | JSR > 111101 (debug:printsignednumber) + +NNN | DIE + +#include +#include diff --git a/stdlib_tests/vv_test.py b/stdlib_tests/vv_test.py index b4f0cd0..4ec6a81 100755 --- a/stdlib_tests/vv_test.py +++ b/stdlib_tests/vv_test.py @@ -37,6 +37,7 @@ tests = [ ['3005_or', '', '+0+1+1-1-1'], ['3006_xor', '', '+0+1+0-2-1'], ['4001_strlen', '', '+11'], + ['4002_isdigit', '', '+0+1+1+0'], ['5001_abs', '', '+1+1+0+0'], ['5002_random', '', ''], ['5003_gcd', '', '+0+4+4+3+3+3'],