FAST Forth Native-Language Embedded Computers
FAST Forth Native-Language Embedded Computers
FAST Forth Native-Language Embedded Computers
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
I<br />
Listing One. Parallel <strong>Forth</strong> extension. 1<br />
\ Dr. Michael B. Montvelishsky, Saransk Russia 1993<br />
\ PARALLELISM WORDSET by Michael Montvelishsky, 25-Sep-93<br />
ANEW PARALLEL<br />
CR .FREE<br />
\ ............................................................ \<br />
\ It is just a simple troock :-) "TROOCK" is the Russian<br />
\ To replace the pause hook :-) pronounce of the "TRICK"<br />
\ PAUSE is CODE-word now.<br />
' PAUSE \ OLD<br />
DEFER PAUSE ' NOOP IS PAUSE<br />
' PAUSE \ OLD NEW<br />
PDUP SWAP - \ OLD NEW SHIFT<br />
OVER 1 + + ! \ OLD NEW ( ADJUSTED ! )<br />
TUCK \ NEW OLD NEW<br />
HERE SWAP - \ NEW OLD SIZE<br />
CMOVE FORGET PAUSE<br />
\ PAUSE is DEFERed NOW!<br />
USER<br />
VARIABLE (NEST)<br />
VARIABLE (PARENT)<br />
VARIABLE (NEXT)<br />
VARIABLE RP<br />
VARIABLE SP<br />
VARIABLE RETURN-STACK-SIZE<br />
VARIABLE DATA-STACK-SIZE<br />
VARIABLE USER-AREA-SIZE<br />
\ GLOBAL memory allocation tool:<br />
DP CONSTANT (HEAP)<br />
: MALLOC (HEAP) +! ;<br />
: HEAP (HEAP) @ ;<br />
\ Initiate variables:<br />
UP @ (PARENT) !<br />
UP @ (NEXT) !<br />
0 (NEST) !<br />
64 USER-AREA-SIZE !<br />
128 RETURN-STACK-SIZE !<br />
64 DATA-STACK-SIZE !<br />
\ Point to the last mounted proc<br />
\ Point to the parent proc<br />
\ Point to the next proc in ring<br />
\ To save<br />
\ stacks' value FORTH<br />
\ To change return stack size<br />
\ - \ data stack size<br />
\ - \ user area size<br />
: PROC-SIZE ( -- current-proc-size )<br />
USER-AREA-SIZE @ RETURN-STACK-SIZE @ + DATA-STACK-SIZE @ +<br />
: GO-NEST SP@ RP@ RP ! SP ! (NEST) @ UP ! RP @ RP! SP @ SP! ;<br />
: (PAUSE) SP@ RP@ RP ! SP ! (NEXT) @ UP ! RP @ RP! SP @ SP! ;<br />
\ Stop all current processes and go to parent process<br />
: STOP-ALL (PARENT) @ (NEXT) ! (PAUSE) ;<br />
\ Parallelism enable/disable<br />
: MULTI [' ] (PAUSE) IS PAUSE ;<br />
: SINGLE [ ' ] NOOP IS PAUSE ;<br />
\ Stop itself<br />
: STOP ( --- : Excludes proc from procs' ring )<br />
UP @ DUP (NEXT) @ - IF \ Last in the ring?<br />
UP @ BEGIN (NEXT) 2DUP @ - WHILE @ UP ! REPEAT<br />
SWAP UP ! (NEXT) @ SWAP ! (PAUSE)<br />
ELSE<br />
STOP-ALL<br />
THEN<br />
\ Create NEW process with specified PFA PARRENT -process and<br />
\ process to be PREVlous in processes' ring<br />
(Ltsfrng One conl:nues on next page)<br />
<strong>Forth</strong> Dimensions 17<br />
(Line Editor, continued frompage 14.)<br />
INSERTKEY is activated by<br />
the Insert key.<br />
The last screen is 507, and it<br />
is wholly given over to the mon-<br />
ster word LNED. Line two con-<br />
tains the necessary initialization.<br />
The main loop, starting on line<br />
three, concludes at the end of<br />
line 13. This is followed by the<br />
close-out code on lines 14 and<br />
15.<br />
Most of the interior of the<br />
loop is a case statement using<br />
the Eaker case statement. Lines<br />
ten, 11 and 12 deal with the<br />
delete and backspace keys in a<br />
series of nested if ... else ...<br />
then statements. Line 13 deals<br />
.with the end-loop condition,<br />
which is either a carriage return<br />
(control-M) or an overflow of<br />
the line buffer.<br />
Screen 508 contains a num-<br />
ber of test words which were<br />
found useful during the coding<br />
phase. They are not part of the<br />
final application, and are not<br />
compiled except for testing.<br />
Completion of compilation<br />
returns control to screen 501.<br />
Line 11 installs the line editor<br />
into the system by ticking the<br />
line editor and placing its code<br />
field address into the user vari-<br />
able ' EXPECT.<br />
Because forgetting this code<br />
would have disastrous results,<br />
we inhibit forgetting below LNED<br />
by moving FENCE to above it.<br />
User Controls<br />
Because the code is self-installing<br />
at compile time, the user<br />
does not even need to know it is<br />
there in order to use it. However,<br />
he will get the most out of<br />
it by adding a few keystrokes to<br />
his repertoire.<br />
The left- and right-arrows<br />
operate to move the cursor left<br />
and right within the line.<br />
The up- and down-arrows<br />
operate to move the user within<br />
the string buffer. The up-arrow<br />
will retrieve the most recent line<br />
from the string buffer into the<br />
editor buffer. The user may scroll<br />
through the string buffer by repeatedly<br />
striking the up-arrow.<br />
March 1994 April