From 3ce87ef53ec4563724e5f8c91cf870b313f31e3d Mon Sep 17 00:00:00 2001 From: d_m Date: Thu, 20 Feb 2025 22:24:36 -0500 Subject: [PATCH] parser seems to work --- fix32.tal | 72 ++++++++++++++++++++++++-------------------------- test-fix32.tal | 21 +++++++++++++++ 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/fix32.tal b/fix32.tal index e994f23..570f941 100644 --- a/fix32.tal +++ b/fix32.tal @@ -233,53 +233,51 @@ POP JMP2r ( ) ( returns nan [8000 0000] on error ) -@x32-parse ( s* -> x/** ) +@x32-parse ( pos* -> x/** ) ( negate leading - ; ignore leading + ) - LDAk LIT "- NEQ ?{ INC2 x32-parse !x32-negate } - LDAk LIT "+ NEQ ?{ INC2 !x32-parse } + LDAk LIT "- NEQ ?{ INC2 x32-parse !x32-negate } ( pos* ) + LDAk LIT "+ NEQ ?{ INC2 !x32-parse } ( pos* ) ( accumulate on rst ; reverse shorts ) LIT2r 0000 LIT2r 0000 ( pos* [lo* hi*] ) ( trim leading zeros ) - &trim LDAk LIT "0 NEQ ?&whole INC2 !&trim + &trim LDAk LIT "0 NEQ ?&whole INC2 !&trim ( pos* [lo* hi*] ) ( accumulate whole part ) - &whole ( pos* [lo* hi*] ) - LDAk #00 EQU ?&whole-done ( pos* [lo* hi*] ) - LDAk #2e EQU ?&dot ( pos* [lo* hi*] ) - LDAk #30 LTH ?&error1 ( pos* [lo* hi*] ) - LDAk #39 GTH ?&error1 ( pos* [lo* hi*] ) - #30 SUB #00 SWP #0000 SWP2 ( pos* 0* digit* [lo *hi*] ) - STH2r STH2r u32-add STH2 STH2 ( pos* [lo2* hi2*] ) - INC2 !&whole ( pos+1* [lo2* hi2*] ) + &whole ( pos* [wlo* whi*] ) + LDAk #00 EQU ?&whole-done ( pos* [wlo* whi*] ) + LDAk #2e EQU ?&dot ( pos* [wlo* whi*] ) + LDAk #30 LTH ?&error1 ( pos* [wlo* whi*] ) + LDAk #39 GTH ?&error1 ( pos* [wlo* whi*] ) + LDAk #30 SUB ( pos* digit^ [wlo* whi*] ) + #00 SWP #0000 SWP2 STH2r STH2r ( pos* digit** w** ) + #0000 #000a u32-mul ( pos* digit** 10w** ) + u32-add STH2 STH2 INC2 !&whole ( pos+1* [wlo2* whi2*] ) &whole-done ( pos* [lo* hi*] ) POP2 STH2r STH2r !x32-from-u32 ( res/** ) &dot ( pos* [wlo* whi*] ) - DUP2 LIT2r 0000 LIT2r 0000 ( orig* pos* [wlo* whi* slo* shi*] ) - &fraction ( orig* pos* [wlo* whi* slo* shi*] ) - LDAk #00 EQU ?&dot-done ( orig* pos* [wlo* whi* slo* shi*] ) - LDAk #30 LTH ?&error2 ( orig* pos* [wlo* whi* slo* shi*] ) - LDAk #39 GTH ?&error2 ( orig* pos* [wlo* whi* slo* shi*] ) - #30 SUB #00 SWP #0000 SWP2 ( orig* pos* 0* digit* [wlo* whi* slo* shi*] ) - STH2r STH2r u32-add STH2 STH2 ( orig* pos* [wlo* whi* slo2* shi2*] ) - INC2 !&fraction ( pos+1* [wlo* whi* slo2* shi2*] ) - &dot-done ( orig* pos* [wlo* whi* slo* shi*] ) - SWP2 SUB2 ( count* [wlo* whi* slo* shi*] ) - DUP2 #0003 LTH2 ?&dot-inc ( count* [wlo* whi* slo* shi*] ) - DUP2 #0003 GTH2 ?&dot-dec ( count* [wlo* whi* slo* shi*] ) - &dot-equ ( [wlo* whi* slo* shi*] ) - POP2 STH2r STH2r STH2r STH2r ( s/** w** ) - x32-from-u32 !x32-add ( x/** ) - &dot-inc - ORA2k #0000 EQU2 ?&dot-equ - STH2r STH2r x32-ten x32-mul - STH2 STH2 #ffff ADD2 !dot-inc - &dot-dec - ( TODO: div? really??? ) - - &error2 POP2r POP2r POP2 - &error1 POP2r POP2r POP2 #8000 #0000 JMP2r - + DUP2 #0004 ADD2 SWP2 ( limit* pos* [wlo* whi*] ) + INC2 LIT2r 0000 ( limit* pos+1* [wlo* whi* s*] ) + &fraction ( limit* pos* [wlo* whi* s*] ) + LDAk #00 EQU ?&dotend ( limit* pos* [wlo* whi* s*] ) + LDAk #30 LTH ?&error2 ( limit* pos* [wlo* whi* s*] ) + LDAk #39 GTH ?&error2 ( limit* pos* [wlo* whi* s*] ) + LDAk #30 SUB #00 SWP ( limit* pos* digit* [wlo* whi* s*] ) + LIT2r 000a MUL2r STH2 ADD2r ( limit* pos* [wlo* whi* 10s+digit*] ) + INC2 GTH2k ?&fraction !&finish ( limit* pos+1 [wlo* whi* 10s+digit*] ) + &dotend ( limit* pos* [wlo* whi* s*] ) + LIT2r 000a MUL2r ( limit* pos* [wlo* whi* 10s*] ) + INC2 GTH2k ?&fraction !&dotend ( limit* pos+1* [wlo* whi* 10s*] ) + &finish ( limit* limit* [wlo* whi* s*] ) + POP2 POP2 #0000 STH2r ( s/** [wlo* whi*] ) + STH2r STH2r x32-from-u32 ( s/** w/** ) + !x32-add ( res/** ) + &error2 ( limit* pos* [wlo* whi* s*] ) + #010e DEO + POP2r POP2 ( limit* [wlo* whi*] ) + &error1 ( pos* [wlo* whi*] ) + POP2r POP2r POP2 #8000 #0000 ( 8000 0000 ) + JMP2r ( 8000 0000 ) ~math32.tal diff --git a/test-fix32.tal b/test-fix32.tal index 7647d3b..76d3f4f 100644 --- a/test-fix32.tal +++ b/test-fix32.tal @@ -68,6 +68,17 @@ #8000 #0001 x32-emit #0a18 DEO ( -2147483.647 ) #ffff #fc18 x32-emit #0a18 DEO ( -1.000 ) #ffff #ffff x32-emit #0a18 DEO ( -0.001 ) + + LIT "@ #18 DEO #0a18 DEO + ;data/str0 x32-parse x32-emit #0a18 DEO + ;data/str1 x32-parse x32-emit #0a18 DEO + ;data/str2 x32-parse x32-emit #0a18 DEO + ;data/str3 x32-parse x32-emit #0a18 DEO + ;data/str4 x32-parse x32-emit #0a18 DEO + ;data/str5 x32-parse x32-emit #0a18 DEO + ;data/str6 x32-parse x32-emit #0a18 DEO + ;data/str7 x32-parse x32-emit #0a18 DEO + #800f DEO BRK ~fix32.tal @@ -96,3 +107,13 @@ &byte DUP #04 SFT ,&char JSR &char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r + +@data + &str0 "0 00 + &str1 "1 00 + &str2 "-1 00 + &str3 "+1 00 + &str4 "123 00 + &str5 "-123 00 + &str6 "123.456 00 + &str7 "-123.456 00