On Monday, September 13, 2021 at 12:20:30 AM UTC-7,
jpit...@gmail.com wrote:
> I spent quite a bit of time listening in to the Standards meeting,
> and can appreciate a lot more now the time and effort people invest in their spare time.
My rquotations are more important to the future of Forth than the Forth-200x committee is.
My rquotations support general-purpose data-structures, which are necessary for Forth
to have a future. The Forth-200x committee have failed to implement any
general-purpose data-structures --- this is because Elizabeth Rather hates
general-purpose data-structures, and she appoints the Forth-200x committee members,
so general-purpose data-structures have become absolutely taboo for the Forth-200x committee.
Here is code that is absolutely banned from EuroForth:
--------------------------------------------------------------------------------------
\ ******
\ ****** R[ ]R quotations.
\ ******
https://groups.google.com/forum/#!topic/comp.lang.forth/3LSqmBIZuzY
\ ****** This is highly non-standard! ANS-Forth (section 3.2.3.3.) says:
\ ****** A program shall not access values on the return stack (using R@, R>, 2R@ or 2R>) that it did not place there using >R or 2>R;
\ ****** There is also an enhanced version that is also non-standard because it depends upon HERE pointing into code.
\ ******
\ In the stack-picture comments, RQ is a continuation (a vector to a quotation).
\ HumptyDumpty invented rquotations --- this was very good programming --- I hadn't thought of it.
\ What I call REX0 he called RCALL --- also, he didn't have REX which I invented (this only works in VFX and SwiftForth).
\ If only REX0 is used, rquotations can be used under any ANS-Forth system (theoretically non-standard though).
\ REX is a lot more useful though because the HOF almost always needs to have locals.
\ My improved version for VFX or SwiftForth should be easy to port to other ANS-Forth systems --- any Forth system with locals.
\ Some assembly-language is required, but it is pretty straight forward.
VFX? 0= SwiftForth? 0= and [if] \ this is the generic version (HumptyDumpty's code; not ANS-Forth, but usually works)
\ this was written by HumptyDumpty and works on gForth, SwiftForth and VFX
: rexit ( -- ) RDROP ;
: (r:) ( -- rq ) R@ false ;
: r[ ( -- rq ) postpone (r:) postpone IF ; immediate
: ]r ( -- ) postpone REXIT postpone THEN ; immediate
: rex0 ( rq -- ) >R true ; \ requires the HOF to not have locals
\ REX is not supported in HumptyDumpty's code.
[then]
VFX? [if]
\ This version depends upon HERE pointing into the code. This is not ANS-Forth. This doesn't work under SwiftForth.
code rex ( rq -- ) \ requires the HOF to have locals
push edi \ this is the HOF's LF which won't be used by the quotation
mov edi, 0 [edi] \ this is the parent's LF which will be used by the quotation
mov eax, ebx
mov ebx, 0 [ebp] lea ebp, w [ebp]
call eax
pop edi \ restore HOF's LF
next, end-code
item last-rq \ this should only be used at compile-time
: rexit ( -- ) rdrop ;
: r[ ( -- rq ) postpone ahead here to last-rq ; immediate
: ]r ( -- ) postpone rexit postpone then last-rq lit, ; immediate
: rex0 ( rq -- ) >r ; \ requires the HOF to not have locals
\ The user can use LAST-RQ after an rquotation at compile-time to obtain the RQ (actually an XT) for it.
[then]
SwiftForth? [if]
\ This version depends upon R@ being the return-address. This is not ANS-Forth. This also works under VFX (I originally used this for both).
code rex ( rq -- ) \ requires the HOF to have locals
'LF [u] edx mov
edx push \ this is the HOF's LF which won't be used by the quotation
-4 [edx] eax mov \ this is the old ESP
0 [eax] eax mov \ this is the parent's LF which will be used by the quotation
eax 'LF [u] mov
ebx eax mov [drop]
eax call
'LF [u] pop \ restore HOF's LF
ret end-code
: rexit ( -- ) rdrop ;
: (r:) ( -- rq ) r@ 5 + ; \ 5 is the size of a JMP instruction in 32-bit x86
: r[ ( -- rq ) postpone (r:) postpone ahead ; immediate
: ]r ( -- ) postpone rexit postpone then ; immediate
: rex0 ( rq -- ) >r ; \ requires the HOF to not have locals
\ LAST-RQ is not supported in the SwiftForth version. The RQ is not known at compile-time.
[then]
\ REX0 does the same as EXECUTE in VFX. In SwiftForth, EXECUTE assumes an offset from EDI so it is different.
\ This is also why the version above that assumes HERE ponts to code doesn't work in SwiftForth.
\ It is possible to rewrite REX0 and REX in assembly-language to work under SwiftForth. I didn't bother to do so.
\ SwiftForth is over-complicated in weird ways. Most likely it was a port from an old multi-user Forth by Charles Moore
\ which is why it uses user-variables and this EDI offset, although it is not multi-user so this was meaningless.
\ Note that in HumptyDumpty's prototype, REX0 was completely different from EXECUTE .
\ REX is used in a HOF that has local variables.
\ REX0 is used in a HOF that does not have local variables.
\ REX0 is also used in the parent function itself, when there is no HOF used.
--------------------------------------------------------------------------------------