The new metacompiler's first big test was metacompiling an existing version of Fleet Forth. Since I'm using VICE instead of a real Commodore 64, the disks are actually disk images and the disk image with the new kernel was identical to the one created with the original metacompiler. I also have SEEALL to test kernels I build. Successfully loading the system loader and the utilities is a test. SEEALL showing the expected disassembly/decompilation is another.
Code:
: (SEE) ( CFA -- )
DUP CR .NAME
SETWIDTH <SEE> ;
: SEE ( -- ) ' (SEE) ;
: SEEALL ( -- )
WITH-WORDS NAME> (SEE)
COLS ?CR ;
I've simplified some of the more obscure code for the metacompiler by adding two new words. These new words use the coroutine word CO
Code:
: >META ( -- )
ORDER@
META DEFINITIONS
CO ORDER! ;
: >SHADOW ( -- )
ORDER@
[SHADOW] SHADOW DEFINITIONS
CO ORDER! ;
The word >META saves the values of CONTEXT and CURRENT to the auxiliary stack then changes the search and compile vocabularies to META . CO causes the rest of >META to run after >META's caller exits. That last part of >META restores the CONTEXT and CURRENT vocabularies.
>SHADOW does the same thing for the SHADOW vocabulary.
This source
Code:
: DEFINE ( W -- )
ORDER@
[SHADOW] SHADOW DEFINITIONS
CONSTANT ORDER! ;
META DEFINITIONS
: MACRO ( ADR CNT -- )
ORDER@
[SHADOW] SHADOW DEFINITIONS
[HOST] MACRO ORDER! ;
HOST
: <MCONSTANT> ( N ADR -- )
>IN @ HEADER >IN !
CF, DUP V,
ORDER@
[SHADOW] SHADOW DEFINITIONS [HOST]
CONSTANT
ORDER! ;
: <M2CONSTANT> ( D ADR -- )
>IN @ HEADER >IN !
CF, 2DUP V, V,
ORDER@
[SHADOW] SHADOW [HOST]
DEFINITIONS 2CONSTANT
ORDER! ;
: <MCREATE> ( ADR -- )
>IN @ HEADER >IN ! CF,
ORDER@
[SHADOW] SHADOW DEFINITIONS
THERE CONSTANT
ORDER! ;
: <<MUSER>> ( C -- )
CREATE
C,
[ HERE 2+ >A ]
DOES>
C@ USER.AREA + ;
: <MUSER> ( C ADR -- )
>IN @ HEADER >IN ! CF,
DUP VC,
ORDER@
[SHADOW] SHADOW [HOST]
DEFINITIONS
<<MUSER>>
ORDER! ;
A> CONSTANT MUSER-CF
is simplified to this
Code:
: DEFINE ( W -- )
>SHADOW CONSTANT ;
META DEFINITIONS
: MACRO ( ADR CNT -- )
>SHADOW MACRO ;
HOST
: <MCONSTANT> ( N ADR -- )
>IN @ HEADER >IN !
CF, DUP V,
>SHADOW CONSTANT ;
: <M2CONSTANT> ( D ADR -- )
>IN @ HEADER >IN !
CF, 2DUP V, V,
>SHADOW 2CONSTANT ;
: <MCREATE> ( ADR -- )
>IN @ HEADER >IN ! CF,
>SHADOW THERE CONSTANT ;
0 VALUE MUSER-CF
: <MUSER> ( C ADR -- )
>IN @ HEADER >IN ! CF,
DUP VC,
>SHADOW
CREATE
C,
[ HERE 2+ TO MUSER-CF ]
DOES>
C@ USER.AREA + ;
Likewise, this source
Code:
: DEFINER ( CFA -- )
['] ORDER! >BODY >R
ORDER@ META DEFINITIONS
CREATE
, 0 , 0 , 0 ,
[ HERE 2+ >A ]
DOES>
DUP 2+ SWAP @ EXECUTE ;
A> CONSTANT DEFINER-WORD
: DEF-RESET ( -- )
['] ORDER! >BODY >R
ORDER@ META WITH-WORDS
NAME> DUP @ DEFINER-WORD <>
IF DROP EXIT THEN
>BODY 2+ 6 ERASE ;
: VERIFY ( -- )
['] ORDER! >BODY >R
ORDER@ META WITH-WORDS
DUP NAME> DUP @ DEFINER-WORD <>
IF 2DROP EXIT THEN
>BODY 2+ @
IF DROP EXIT THEN
CR RON ID.
." . NOT DEFINED IN TARGET" ;
is simplified to this
Code:
: DEFINER ( CFA -- )
>META
CREATE
, 0 , 0 , 0 ,
[ HERE 2+ >A ]
DOES>
DUP 2+ SWAP @ EXECUTE ;
A> CONSTANT DEFINER-WORD
: DEF-RESET ( -- )
>META WITH-WORDS
NAME> DUP @ DEFINER-WORD <>
IF DROP EXIT THEN
>BODY 2+ 6 ERASE ;
: VERIFY ( -- )
>META WITH-WORDS
DUP NAME> DUP @ DEFINER-WORD <>
IF 2DROP EXIT THEN
>BODY 2+ @
IF DROP EXIT THEN
CR RON ID.
." . NOT DEFINED IN TARGET" ;
The metacompiler built with these changes successfully metacompiled Fleet Forth's kernel.