Compare commits

...

2 Commits

Author SHA1 Message Date
iko
9054a6736b
Added labels 2024-05-17 16:43:43 +03:00
iko
381302386b
Got hex floats working 2024-05-17 15:07:35 +03:00
2 changed files with 82 additions and 3 deletions

View File

@ -319,7 +319,10 @@
;~ pose
%+ cook
|= x=@rd [%float x]
parse-float
;~ pose
parse-float
parse-hex-float
==
::
%+ cook
|= x=@u [%int x]
@ -461,6 +464,7 @@
$%
[%blok blok]
[%asmnt varlist exprlist]
[%label label]
[%empty ~]
==
++ parse-stat
@ -469,6 +473,10 @@
;~ pose
(cold [%empty ~] (just ';'))
::
%+ cook
|= =label [%label label]
parse-label
::
%+ cook
|=([* =blok *] [%blok blok])
;~ (glue wss)
@ -498,6 +506,29 @@
"="
(commaed (turn +>.stat print-expr))
==
%label (print-label +.stat)
==
:: label
::
+$ label name
++ print-label
|= =label
^- tape
%- zing
:~
"::"
(trip label)
"::"
==
++ parse-label
%+ knee *label
|.
%+ cook
|= [* =label *] label
;~ (glue ws)
(jest '::')
parse-name
(jest '::')
==
:: Blok
::
@ -585,6 +616,52 @@
==
==
==
++ parse-hex-float
%+ knee *@rd
|.
=<
%+ sear
|= [* * int=tape frac=(unit tape) exp=(unit [exp-sign=? exp=@])]
?: ?=([~ ~] [frac exp]) ~
%- some
=/ frac (fall frac "")
=/ whole=@rd (sun:rd (scan (weld int frac) hex))
=/ frac-exp=@rd (sun:rd (pow 16 (lent frac)))
=/ without-exp (div:rd whole frac-exp)
?~ exp without-exp
=/ exp-exp (sun:rd (pow 2 exp.u.exp))
?: exp-sign.u.exp
(mul:rd without-exp exp-exp)
(div:rd without-exp exp-exp)
;~ plug
(just '0')
::
(mask "xX")
::
(plus hex-digit)
::
%- punt
;~ pfix
dot
(plus hex-digit)
==
::
%- punt
;~ pfix
(mask "pP")
;~(plug ;~(pose (cold | hep) (cold & lus) (easy &)) dim:ag)
==
==
|%
++ hex-digit
%+ knee *char
|.
;~ pose
(shim '0' '9')
(shim 'a' 'f')
(shim 'A' 'F')
==
--
++ show-float
|= x=@rd
^- tape

View File

@ -37,8 +37,10 @@ test_cases = {
{ 0x800000000000, "1.4073748835533e+14" },
{ 140737488355328, "1.4073748835533e+14" },
}
::
helli
::
foo = {
3.0, 3.1416, 314.16e-2, 0.31416E1, 34e1,
0x0.1E, 0xA23p-4, 0X1.921FB54442D18P+1
0x0.1E, 0xA23p-4, 0xA23p-4, 0X1.921FB54442D18P+1, 0x1.fp10
}