Skip to content

Commit 74543b0

Browse files
committed
Add +TO and ADDR
1 parent 18f1549 commit 74543b0

File tree

4 files changed

+66
-31
lines changed

4 files changed

+66
-31
lines changed

Diff for: float.fs

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@
7070
DOES> ( -- r )
7171
f@ ;
7272

73+
: f+! ( r addr -- ) dup f@ f+ f! ;
74+
75+
Create f!-table ' f! , ' f+! ,
76+
7377
: fvalue! ( xt xt-deferred -- ) \ gforth defer-store
74-
>body f! ;
75-
opt: drop >body postpone ALiteral postpone f! ;
78+
>body f!-table to-!exec ;
79+
opt: drop >body postpone ALiteral f!-table to-!, ;
7680

7781
: fvalue ( r "name" -- ) \ float-ext f-value
7882
fconstant ['] fvalue! set-to ['] comp-fval set-optimizer ;

Diff for: glocals.fs

+13-10
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,19 @@ variable locals-dp \ so here's the special dp for locals.
341341
\ adds it as inline argument to a preceding locals primitive
342342
lp-offset , ;
343343

344-
[IFDEF] set-to
345-
: to-w: ( -- ) -14 throw ;
346-
comp: drop POSTPONE laddr# >body @ lp-offset, POSTPONE ! ;
347-
: to-d: ( -- ) -14 throw ;
348-
comp: drop POSTPONE laddr# >body @ lp-offset, POSTPONE 2! ;
349-
: to-c: ( -- ) -14 throw ;
350-
comp: drop POSTPONE laddr# >body @ lp-offset, POSTPONE c! ;
351-
: to-f: ( -- ) -14 throw ;
352-
comp: drop POSTPONE laddr# >body @ lp-offset, POSTPONE f! ;
353-
[THEN]
344+
: c+! ( c addr -- ) dup >r c@ + r> c! ;
345+
: 2+! ( d addr -- ) dup >r 2@ d+ r> 2! ;
346+
347+
Create 2!-table ' 2! , ' 2+! ,
348+
Create c!-table ' c! , ' c+! ,
349+
: to-w: ( -- ) -14 throw ;
350+
comp: drop POSTPONE laddr# >body @ lp-offset, !-table to-!, ;
351+
: to-d: ( -- ) -14 throw ;
352+
comp: drop POSTPONE laddr# >body @ lp-offset, 2!-table to-!, ;
353+
: to-c: ( -- ) -14 throw ;
354+
comp: drop POSTPONE laddr# >body @ lp-offset, c!-table to-!, ;
355+
: to-f: ( -- ) -14 throw ;
356+
comp: drop POSTPONE laddr# >body @ lp-offset, f!-table to-!, ;
354357

355358
: val-part-off ( -- ) val-part off ;
356359

Diff for: kernel/comp.fs

+22-5
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,17 @@ opt: drop @ (comp-to) ;
449449
: AValue ( w "name" -- ) \ core-ext
450450
(Value) A, ;
451451

452-
: u-to ( n uvalue-xt -- ) >body @ next-task + ! ;
452+
Create !-table ' ! A, ' +! A,
453+
Variable to-style# 0 to-style# !
454+
455+
: to-!, ( table -- )
456+
0 to-style# !@ dup 2 u< IF cells + @ compile, ELSE drop THEN ;
457+
: to-!exec ( table -- )
458+
0 to-style# !@ dup 2 u< IF cells + perform ELSE drop THEN ;
459+
460+
: u-to ( n uvalue-xt -- ) >body @ next-task + !-table to-!exec ;
453461
opt: ( uvalue-xt to-xt -- )
454-
drop >body @ postpone useraddr , postpone ! ;
462+
drop >body @ postpone useraddr , !-table to-!, ;
455463
\g u-to is the to-method for user values; it's xt is only
456464
\g there to be consumed by @code{set-to}.
457465
: u-compile, ( xt -- ) >body @ postpone useraddr , postpone @ ;
@@ -611,10 +619,10 @@ interpret/compile: lit,:
611619
: value! ( n value-xt -- ) \ gforth value-store
612620
\g this is the TO-method for normal values; it's tickable, but
613621
\g the only purpose of its xt is to be consumed by @code{set-to}.
614-
>body ! ;
622+
>body !-table to-!exec ;
615623
opt: ( value-xt to-xt -- )
616-
drop >body postpone ALiteral postpone ! ;
617-
624+
drop >body postpone ALiteral !-table to-!, ;
625+
618626
: <IS> ( "name" xt -- ) \ gforth
619627
\g Changes the @code{defer}red word @var{name} to execute @var{xt}.
620628
record-name (') (name>x) drop (int-to) ;
@@ -627,6 +635,15 @@ opt: ( value-xt to-xt -- )
627635
' <IS> ' [IS] interpret/compile: TO ( value "name" -- )
628636
' <IS> ' [IS] interpret/compile: IS ( value "name" -- )
629637

638+
: <+TO> 1 to-style# ! <IS> ;
639+
: <addr> 2 to-style# ! <IS> ;
640+
641+
: [+TO] 1 to-style# ! postpone [IS] ; immediate restrict
642+
: [addr] 2 to-style# ! postpone [IS] ; immediate restrict
643+
644+
' <+TO> ' [+TO] interpret/compile: +TO ( value "name" -- )
645+
' <addr> ' [addr] interpret/compile: addr ( "name" -- addr )
646+
630647
\ \ : ; 24feb93py
631648

632649
defer :-hook ( sys1 -- sys2 )

Diff for: struct-val.fs

+25-14
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,44 @@ warnings !
3030

3131
standard:field
3232

33-
: vfield-int, ( addr body -- offset ) dup cell+ @ execute ;
34-
: vfield-comp, ( body -- ) dup cell+ @ compile, ;
33+
: vfield-int, ( addr body -- offset ) dup cell+ @ to-!exec ;
34+
: vfield-comp, ( body -- ) dup cell+ @ to-!, ;
3535

3636
: create+value ( n1 addr "name" -- n3 )
3737
>r r@ cell+ cell+ 2@ r> 2@
3838
2>r >r Create over , + action-of +field, ,
3939
r> set-does> 2r> set-to set-optimizer ;
4040

41-
: wrap+value: ( n2 xt-align xt@ xt! "name" -- ) { xt-align xt@ xt! }
41+
: wrap+value: ( n2 xt-align xt@ xt!-table "name" -- ) { xt-align xt@ xt! }
4242
:noname ]] vfield-int, [[ xt@ compile, postpone ; \ xt-does
4343
:noname ]] >body vfield-comp, [[ xt@ ]]L compile, ; [[ \ xt-comp,
4444
:noname ]] drop >body vfield-comp, [[ xt! ]]L compile, ; [[ \ xt-to-comp,
4545
:noname ]] >body vfield-int, [[ xt! compile, postpone ; swap set-optimizer \ xt-to
4646
:noname ]] >r [[ xt-align compile, ]] r> create+value ; [[
4747
Create set-does> , , , , ;
4848

49-
cell ' aligned ' @ ' ! wrap+value: value: ( u1 "name" -- u2 )
50-
1 ' noop ' c@ ' c! wrap+value: cvalue: ( u1 "name" -- u2 )
51-
2 ' waligned ' w@ ' w! wrap+value: wvalue: ( u1 "name" -- u2 )
52-
2 ' waligned ' sw@ ' w! wrap+value: swvalue: ( u1 "name" -- u2 )
53-
4 ' laligned ' l@ ' l! wrap+value: lvalue: ( u1 "name" -- u2 )
54-
4 ' laligned ' sl@ ' l! wrap+value: slvalue: ( u1 "name" -- u2 )
55-
2 cells ' aligned ' 2@ ' 2! wrap+value: 2value: ( u1 "name" -- u2 )
56-
1 floats ' faligned ' f@ ' f! wrap+value: fvalue: ( u1 "name" -- u2 )
57-
1 sfloats ' sfaligned ' sf@ ' sf! wrap+value: sfvalue: ( u1 "name" -- u2 )
58-
1 dfloats ' dfaligned ' df@ ' df! wrap+value: dfvalue: ( u1 "name" -- u2 )
59-
cell ' aligned ' $@ ' $! wrap+value: $value: ( u1 "name" -- u2 )
49+
: w+! ( w addr -- ) dup >r w@ + r> w! ;
50+
: l+! ( w addr -- ) dup >r l@ + r> l! ;
51+
: sf+! ( w addr -- ) dup >r sf@ f+ r> sf! ;
52+
: df+! ( w addr -- ) dup >r df@ f+ r> df! ;
53+
54+
Create w!-table ' w! , ' w+! ,
55+
Create l!-table ' l! , ' l+! ,
56+
Create sf!-table ' sf! , ' sf+! ,
57+
Create df!-table ' df! , ' df+! ,
58+
Create $!-table ' $! , ' $+! ,
59+
60+
cell ' aligned ' @ ' !-table wrap+value: value: ( u1 "name" -- u2 )
61+
1 ' noop ' c@ ' c!-table wrap+value: cvalue: ( u1 "name" -- u2 )
62+
2 ' waligned ' w@ ' w!-table wrap+value: wvalue: ( u1 "name" -- u2 )
63+
2 ' waligned ' sw@ ' w!-table wrap+value: swvalue: ( u1 "name" -- u2 )
64+
4 ' laligned ' l@ ' l!-table wrap+value: lvalue: ( u1 "name" -- u2 )
65+
4 ' laligned ' sl@ ' l!-table wrap+value: slvalue: ( u1 "name" -- u2 )
66+
2 cells ' aligned ' 2@ ' 2!-table wrap+value: 2value: ( u1 "name" -- u2 )
67+
1 floats ' faligned ' f@ ' f!-table wrap+value: fvalue: ( u1 "name" -- u2 )
68+
1 sfloats ' sfaligned ' sf@ ' sf!-table wrap+value: sfvalue: ( u1 "name" -- u2 )
69+
1 dfloats ' dfaligned ' df@ ' df!-table wrap+value: dfvalue: ( u1 "name" -- u2 )
70+
cell ' aligned ' $@ ' $!-table wrap+value: $value: ( u1 "name" -- u2 )
6071

6172
0 [IF] \ test
6273
begin-structure foo

0 commit comments

Comments
 (0)