home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
ddjmag
/
ddj8710.arc
/
TRCY2EXP.LST
< prev
Wrap
File List
|
1987-09-14
|
5KB
|
198 lines
: I> COMPILE R> ; IMMEDIATE ( no offset)
: >I COMPILE >R ; IMMEDIATE ( no offset)
: I> R> R> 1+ SWAP >R ; IMMEDIATE ( one-byte offset)
: >I R> SWAP 1- >R >R ; IMMEDIATE ( one-byte offset)
: I> R> R> 2+ SWAP >R ; IMMEDIATE ( two-byte offset)
: >I R> SWAP 2- >R >R ; IMMEDIATE ( two-byte offset)
: lit ( - n) I> DUP @ SWAP 2+ >I ;
: LITERAL COMPILE lit , ; IMMEDIATE
Example 1: A way to hide the adjustment of >
: ALIGN ; IMMEDIATE ( no alignment)
: REALIGN ; ( no alignment)
: ALIGN HERE 1 AND ALLOT ; IMMEDIATE ( cell-alignment)
: REALIGN ( a - a') DUP 1 AND + ; ( cell-alignment)
: (") ( - addr n) I> @ COUNT 2DUP + REALIGN >I ;
: " COMPILE (") 34 WORD DUP C@ ( n ) 1+ >R
COUNT HERE SWAP CMOVE R> ALLOT ALIGN ; IMMEDIATE
Example 2: A definition of "when the dictionary is aligned
2 CONSTANT CELL ( byte-addressed 16-bit cells)
: CELLS 2* ; ( size of cell area in bytes)
: CELL+ 2+ ; ( skip to the next cell address)
4 CONSTANT CELL ( byte-addressed 32-bit cells)
: CELLS 4 * ; ( size of cell area in bytes)
: CELL+ 4 + ; ( skip to the next cell address)
1 CONSTANT CELL ( cell-addressed one-byte-per-cell)
: CELLS ; ( size of cell area in bytes)
: CELL+ 1+ ; ( skip to the next cell address)
CELL ALLOT ( allocate a cell)
10 CELLS ALLOT ( allocate 10 cells)
( addr ) DO ... CELL+ ( skip to next cell) LOOP
Example 3: A way to hide the number of bytes per cell
Listing 1
SCR# 0
( A Forth Standard Prelude )
This file defines additional functions and extensions which
cannot be provided in the Forth-83 Standard.
Select the appropriate prelude for the particular Forth you are
using and load it before loading a Standard program using these
functions.
Copyright 1986 1987 by Martin J. Tracy.
SCR# 1
( Select a FORTH-83 implementation)
FORTH DECIMAL
( 2 LOAD ( *** model ****)
( 3 4 THRU ( Lab Microsystems, Inc. PC/FORTH Ver. 3.0)
( 5 LOAD ( Laxen-Perry F83 Ver. 2.1)
( 6 LOAD ( MicroMotion MasterForth Ver. 1.2)
( 7 LOAD ( ZEN Ver. 0.0)
( 8 LOAD ( FORTH, Inc. PolyFORTH II ISD-4 MS-DOS)
SCR# 2
( FORTH-83 functions-- typical definitions)
( Note: functions already provided need not be redefined.)
: RECURSE [COMPILE] RECURSE ; IMMEDIATE
: INTERPRET INTERPRET ;
: I> ( - 'data ) COMPILE R> ; IMMEDIATE
: >I ( - 'data ) COMPILE >R ; IMMEDIATE
( Used for alignment: )
: ALIGN HERE 1 AND ALLOT ;
: REALIGN ( a - a' ) DUP 1 AND + ;
( Note: defined here for a dumb terminal.)
: TAB ( x y ) CR 2DROP ;
: PAGE 25 0 DO CR LOOP 0 0 TAB ;
: MARK ( a n) TYPE ;
SCR# 3
( Lab Microsystems, Inc. PC/FORTH Ver. 3.0)
( RECURSE and INTERPRET are provided.)
( Used by hi-level run-time words to find in-line data: )
: I> ( - 'data ) COMPILE R> ; IMMEDIATE
: >I ( - 'data ) COMPILE >R ; IMMEDIATE
( PC/FORTH already has a word ALIGN which works differently.)
( The following two definitions must be in the order shown: )
: REALIGN ( addr --- addr' ) ALIGN ;
( 8086/80286 run-time I realignment.)
: ALIGN ( --) EVEN ;
( 8086/80286 compilation address alignment.)
SCR# 4
( Lab Microsystems, Inc. PC/FORTH Ver. 3.0)
( x y --- )
: TAB GOTOXY ;
( --- ; clear screen and home cursor )
: PAGE CLS ;
( a n --- ; display string in inverse video )
: MARK REVERSE TYPE REVERSE ;
SCR# 5
( Laxen-Perry No Visible Support F83 Ver. 2.1)
( RECURSE and INTERPRET are provided.)
( Used by hi-level run-time words to find in-line data: )
: I> ( - 'data ) COMPILE R> ; IMMEDIATE
: >I ( - 'data ) COMPILE >R ; IMMEDIATE
( Used for alignment: )
: ALIGN ; : REALIGN ;
: PAGE ( -- ) DARK ;
\ clear screen and home cursor.
: TAB ( x y -- ) AT ;
\ move cursor to given coordinate.
: MARK ( a n -- ) TYPE ;
\ the MARK function is not provided in F83.
SCR# 6
( MicroMotion MasterForth Ver. 1.2.4)
( RECURSE is provided.)
: INTERPRET TIB #TIB @ EVAL ;
: >I COMPILE >R ; IMMEDIATE
: I> COMPILE R> ; IMMEDIATE
NEED ALIGN \IF : ALIGN ;
NEED REALIGN \IF : REALIGN ;
( PAGE is provided.)
: TAB ( x y) AT ;
: MARK ( a n) +INVERSE TYPE -INVERSE ;
SCR# 7
( ZEN 0.0)
( RECURSE and INTERPRET are provided.)
( >I and I> are provided.)
NEED ALIGN \IF : ALIGN ;
NEED REALIGN \IF : REALIGN ;
( PAGE TAB and MARK are provided.)
SCR# 8
( FORTH, Inc. polyFORTH MS-DOS ISD) HEX 1F1F WIDTH !
( Forth-83 Compatibility layer must be loaded first.)
: RECURSE LAST @ @ 2+ COUNT + , ; IMMEDIATE
( INTERPRET is provided.)
( Used by hi-level run-time words to find in-line data: )
: I> ( - 'data ) COMPILE R> ; IMMEDIATE
: >I ( - 'data ) COMPILE >R ; IMMEDIATE
( Used for alignment: )
: ALIGN ; : REALIGN ;
( PAGE and MARK are provided.)
: TAB ( x y ) SWAP TAB ;
( move cursor to given coordinate.)