a***@spenarnc.xs4all.nl
2024-06-20 10:10:40 UTC
There was a lecture on interpreted control structure in Zeptoforth.
That was in the forth2020 conference of april 2024
I was surprised. In particular it doesnot work for looping
building up the dictionary, e.g.
CREATE CRCTable
100 0 DO I 8 0 DO
DUP >R 1 RSHIFT R> 1 AND IF CRC64_POLYNOMIAL XOR THEN
LOOP , LOOP
This IMO is the most useful application.
Other disadvantage of this implementation was that an error leads
to a restart.
The following simple mechanism is in ciforth, and a small
adaptation runs on gforth 7.3, presumably portably, or at least
quasi portably.
It compiles temporarily to a kind of far PAD, then abandons the code
after executing it.
I commented the word TRIM out, this isn't portable (but instrumental
to ciforth classes.)
---------
( SWAP-DP T] T[ scratch_dictionary_area ) \ AvdH A9mar31
VARIABLE FAR-DP \ Alternative DP
HERE 10000 CELLS ALLOT FAR-DP !
\ Use alternative dictionary area or back.
: SWAP-DP DP @ FAR-DP @ DP ! FAR-DP ! ;
\ \ Remove all words from the scratch area.
\ : TRIM HERE 'FORGET-VOC FOR-VOCS DROP ;
\ While compiling, T[ just throws away the state pushed by T].
\ Interpreting:
\ Start compiling at temporary place : return START and STATE.
: T] STATE @ 0= IF SWAP-DP HERE THEN STATE @ ] ;
\ Execute code at START dropping STATE, restore dictionary.
: T[ 0= IF POSTPONE EXIT SWAP-DP POSTPONE [ >R THEN ; IMMEDIATE
( NEW-IF -scripting- ) \ AvdH B2sep21
: IF T] POSTPONE IF ; IMMEDIATE
: DO T] POSTPONE DO ; IMMEDIATE
: ?DO T] POSTPONE ?DO ; IMMEDIATE
: BEGIN T] POSTPONE BEGIN ; IMMEDIATE
: THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
: LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
: +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
: REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
: UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
: AGAIN POSTPONE AGAIN POSTPONE T[ ; IMMEDIATE
\ Last scripting block!
---------
With the above code you could go on after and error, forfeiting 10000
CELLS of the dictionary, or just use SWAP-DP .
Scripting is since time immemorial in ciforth library.
Example for gforth:
~/PROJECT/ciforths/ciforth: gforth
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
INCLUDE script.frt redefined IF redefined DO redefined ?DO redefined BEGIN redefined THEN redefined LOOP redefined +LOOP redefined REPEAT redefined UNTIL redefined AGAIN ok
10 0 DO I . LOOP 0 1 2 3 4 5 6 7 8 9 ok
BEGIN FOOBAR REPEAT
:3: Undefined word
BEGIN >>>FOOBAR<<< REPEAT
Backtrace:
$7F73F67DAA68 throw
$7F73F67F0D58 no.extensions
$7F73F67DE3A0 compiler-notfound1
HERE . 140136033719632 ok
SWAP-DP ok
HERE . 140136033800808 ok
10 0 DO I . LOOP 0 1 2 3 4 5 6 7 8 9 ok
In this example you see that gforth restores HERE after
an error,sometimes. (But not in all cases.)
Hopes this helps.
Groetjes Albert
That was in the forth2020 conference of april 2024
I was surprised. In particular it doesnot work for looping
building up the dictionary, e.g.
CREATE CRCTable
100 0 DO I 8 0 DO
DUP >R 1 RSHIFT R> 1 AND IF CRC64_POLYNOMIAL XOR THEN
LOOP , LOOP
This IMO is the most useful application.
Other disadvantage of this implementation was that an error leads
to a restart.
The following simple mechanism is in ciforth, and a small
adaptation runs on gforth 7.3, presumably portably, or at least
quasi portably.
It compiles temporarily to a kind of far PAD, then abandons the code
after executing it.
I commented the word TRIM out, this isn't portable (but instrumental
to ciforth classes.)
---------
( SWAP-DP T] T[ scratch_dictionary_area ) \ AvdH A9mar31
VARIABLE FAR-DP \ Alternative DP
HERE 10000 CELLS ALLOT FAR-DP !
\ Use alternative dictionary area or back.
: SWAP-DP DP @ FAR-DP @ DP ! FAR-DP ! ;
\ \ Remove all words from the scratch area.
\ : TRIM HERE 'FORGET-VOC FOR-VOCS DROP ;
\ While compiling, T[ just throws away the state pushed by T].
\ Interpreting:
\ Start compiling at temporary place : return START and STATE.
: T] STATE @ 0= IF SWAP-DP HERE THEN STATE @ ] ;
\ Execute code at START dropping STATE, restore dictionary.
: T[ 0= IF POSTPONE EXIT SWAP-DP POSTPONE [ >R THEN ; IMMEDIATE
( NEW-IF -scripting- ) \ AvdH B2sep21
: IF T] POSTPONE IF ; IMMEDIATE
: DO T] POSTPONE DO ; IMMEDIATE
: ?DO T] POSTPONE ?DO ; IMMEDIATE
: BEGIN T] POSTPONE BEGIN ; IMMEDIATE
: THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
: LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
: +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
: REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
: UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
: AGAIN POSTPONE AGAIN POSTPONE T[ ; IMMEDIATE
\ Last scripting block!
---------
With the above code you could go on after and error, forfeiting 10000
CELLS of the dictionary, or just use SWAP-DP .
Scripting is since time immemorial in ciforth library.
Example for gforth:
~/PROJECT/ciforths/ciforth: gforth
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
INCLUDE script.frt redefined IF redefined DO redefined ?DO redefined BEGIN redefined THEN redefined LOOP redefined +LOOP redefined REPEAT redefined UNTIL redefined AGAIN ok
10 0 DO I . LOOP 0 1 2 3 4 5 6 7 8 9 ok
BEGIN FOOBAR REPEAT
:3: Undefined word
BEGIN >>>FOOBAR<<< REPEAT
Backtrace:
$7F73F67DAA68 throw
$7F73F67F0D58 no.extensions
$7F73F67DE3A0 compiler-notfound1
HERE . 140136033719632 ok
SWAP-DP ok
HERE . 140136033800808 ok
10 0 DO I . LOOP 0 1 2 3 4 5 6 7 8 9 ok
In this example you see that gforth restores HERE after
an error,sometimes. (But not in all cases.)
Hopes this helps.
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -