-- CHAIN words - compare with win32forth
Copyright (C) Tektronix, Inc. 1998 - 2001. All rights reserved.
description: This wordset implements CHAINs of words as seen in win32forth - unlike LINK-chains these chains will be watched by the system and referenced globabally via the chain-link variable. During FORGET we can prune these chains and keep them in the state they deserve to be at that point. In general, CHAINs are used as defer-chains which hold a series of of executions tokens in each chain item, and a call to `do-chain` will execute each one in that chain.
new-chain semicolon-chain : items are usually called resolve-* new-chain forget-chain : items are usually called trim-* new-chain unload-chain : items are usually called release-*
a chain-item is either a PRIMITIVE or a COLONWORD we simulate that it is part of a colonword - setting the IP to the address of the CHAIN-ITEM's body should make it callable. ITC: with XT: the XT at PRIM: HERE+1 | CODE* (simulating a prim XT) CTC: with XT: flatten XT being: CODE* | BODY* at PRIM CODE* STC variants: COLONWORDS are PRIMITIVES too, so just CODE*
WARNING: this wordset is not complete - it should hang on to the forget-routine to be able to prune chains given that their chain-heads are registered in a system-wide chainlist too. This has not been implemented.
The win32forth model has shown to be not directly usable within the pfe core parts - in win32forth each routine is itself just a forth routine while in pfe there is usually a difference between a colon-routine and a (C-made) primitive-routine so that they can not easily be universally referenced as XTs. It would be a rather complex endavour requiring quite some system runtime resources according to time and speed. Instead, the chain-wordlist system has been modelled at greater extents giving you largely the same functionality on different grounds.
EXTENSIONS
link,
( list -- )(
)
;
p4:"link-comma";
: link, here over @ a, swap ! ;
EXTENSIONS
chain-link
( .. )(
)
;
as:"chain-minus-link";
threadstate variable chain-link
chain_link (no special usage info)
EXTENSIONS
.chain
( chain* -- )(
)
;
p4:"dot-chain";
show chain - compare with WORDS
EXTENSIONS
.chains
( -- )(
)
;
p4:"dot-chains";
show all chains registered in the system - compare with VLIST
EXTENSIONS
chain-add
( chain* "word-to-add" -- )( | ) ; |
; |
add chain item, for normal setup, at end of do-chain
: chain-add ' >r begin dup @ while @ repeat here swap ! 0 , r> , ; ( chain-add begin dup @ while @ repeat here swap ! 0, ' , )
EXTENSIONS
chain-add-before
( chain* "word-to-add" -- )( | ) ; |
; |
add chain item, for reverse chain like BYE
: chain-add-before ' >r here over @ , r> , swap ! ; ( chain-add-before link, ' , )
EXTENSIONS
do-chain
( chain* -- )(
)
;
p4:"do-chain";
execute chain
: do-chain being @ ?dup while dup>r cell+ @execute r> repeat ;
EXTENSIONS
new-chain
( "name" -- )(
)
;
p4:"new-chain";
create a new chain and register in chain-link
: new-chain create: 0 , ['] noop , chain-link link, ;
layout of a chain: /cell field ->chain.link /cell field ->chain.exec /cell field ->chain.next
EXTENSIONS
xdo-chain
( .. )(
)
;
as:"xdo-minus-chain";
forthword synonym xdo-chain
is doing the same as do-chain
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.
EXTENSIONS
new-sys-chain
( .. )( | ) ; |
; |
forthword synonym new-sys-chain
is doing the same as new-chain
this word is provided only for compatibility with common forth usage in programs. Thegiven synonym should be preferred however.