pcat: implement (br) and (br?)

This commit is contained in:
Virgil Dupras 2020-06-16 22:10:32 -04:00
parent 49979404a5
commit bc8144b4be
9 changed files with 70 additions and 62 deletions

View File

@ -1,7 +1,7 @@
CODE (?br) ( 0x67 ) CODE (?br) ( 0x67 )
HL POPqq, HL POPqq,
HLZ, HLZ,
JRZ, L2 BWR ( BR + 2. False, branch ) JRZ, L2 BWR ( br + 1. False, branch )
L1 BSET ( loop will jump here ) L1 BSET ( loop will jump here )
( True, skip next 2 bytes and don't branch ) ( True, skip next 2 bytes and don't branch )
IY INCss, IY INCss, IY INCss, IY INCss,

View File

@ -2,4 +2,5 @@
0x31 OPrr XORxx, 0x30 OPrr XORrr, 0x31 OPrr XORxx, 0x30 OPrr XORrr,
0x88 OPrr MOVrr, 0x89 OPrr MOVxx, 0x28 OPrr SUBrr, 0x88 OPrr MOVrr, 0x89 OPrr MOVxx, 0x28 OPrr SUBrr,
0x29 OPrr SUBxx, 0x08 OPrr ORrr, 0x09 OPrr ORxx, 0x29 OPrr SUBxx, 0x08 OPrr ORrr, 0x09 OPrr ORxx,
0x3a OPrr CMPrr, 0x3b OPrr CMPxx, 0x3a OPrr CMPrr, 0x3b OPrr CMPxx, 0x00 OPrr ADDrr,
0x01 OPrr ADDxx,

18
blk/813
View File

@ -1,14 +1,16 @@
( BOOT DICT: There are only 3 words in the boot dict, but ( BOOT DICT: There are only 3 words in the boot dict, but
these words' offset need to be stable, so they're part of these words' offset need to be stable, so they're part of
the "stable ABI" ) the "stable ABI" )
'E' A, 'X' A, 'I' A, 'T' A, 'E' A, 'X' A, 'I' A, 'T' A, 0 A,, ( prev ) 4 A, ( len )
0 A,, ( prev ) 4 A, ( len ) H@ XCURRENT ! ( set current tip of dict, 0x42 )
H@ XCURRENT ! ( set current tip of dict, 0x42 ) 0x17 A, ( nativeWord )
0x17 A, ( nativeWord )
DX [BP] 0 MOVx[]+, BP DECx, BP DECx, ( popRS ) DX [BP] 0 MOVx[]+, BP DECx, BP DECx, ( popRS )
;CODE ;CODE NOP,
PC ORG @ 0x20 + ! ( numberWord ) CODE (br) ( 0x53 ) L2 BSET ( used in br? )
PC ORG @ 0x24 + ! ( addrWord ) ( see B287 for comments ) DI DX MOVxx, DI [DI] MOVx[], DX DI ADDxx,
DI DX MOVxx, DI [DI] MOVx[], DI PUSHx, ;CODE NOP, NOP,
CODE (br?) ( 0x67 )
AX POPx, AX AX ORxx, JZ, L2 @ RPCs, ( False, branch )
( True, skip next 2 bytes and don't branch )
DX INCx, DX INCx, DX INCx, DX INCx,
;CODE ;CODE

19
blk/814
View File

@ -1,14 +1,5 @@
PC 0x1d - ORG @ 0x1b + ! ( next ) PC ORG @ 0x20 + ! ( numberWord )
DI DX MOVxx, ( <-- IP ) DX INCx, DX INCx, PC ORG @ 0x24 + ! ( addrWord ) ( see B287 for comments )
DI [DI] MOVx[], ( wordref ) DI DX MOVxx, DI [DI] MOVx[], DI PUSHx,
( continue to execute ) DX INCx, DX INCx,
L1 BSET PC 0x36 - ORG @ 0x34 + ! ( execute -- DI -> wordref ) ;CODE
AH AH XORrr, AL [DI] MOVr[],
DI INCx, ( PFA )
AX JMPr,
PC 0x11 - ORG @ 0x0f + ! ( compiledWord -- DI -> PFA )
BP INCx, BP INCx, [BP] 0 DX MOV[]+x, ( pushRS )
DX DI MOVxx, DX INCx, DX INCx, ( --> IP )
DI [DI] MOVx[],
JMPs, L1 @ RPCs,

30
blk/815
View File

@ -1,16 +1,14 @@
L4 BSET PC 3 - ORG @ 4 + ! ( find ) PC 0x1d - ORG @ 0x1b + ! ( next )
( find word the same name as str in SI starting from tip in DI DX MOVxx, ( <-- IP ) DX INCx, DX INCx,
DI. Returns wordref in DI. Z if found, NZ if not. ) DI [DI] MOVx[], ( wordref )
CH CH XORrr, CL [SI] MOVr[], ( CX -> strlen ) ( continue to execute )
SI INCx, ( first char ) AX AX XORxx, ( initial prev ) L1 BSET PC 0x36 - ORG @ 0x34 + ! ( execute -- DI -> wordref )
BEGIN, ( loop ) AH AH XORrr, AL [DI] MOVr[],
DI AX SUBxx, ( jump to prev wordref ) DI INCx, ( PFA )
AL [DI] -1 MOVr[]+, ( strlen ) AX JMPr,
CL AL CMPrr, IFZ, ( same len )
SI PUSHx, DI PUSHx, CX PUSHx, ( --> lvl 3 ) PC 0x11 - ORG @ 0x0f + ! ( compiledWord -- DI -> PFA )
3 ADDALi, ( header ) AH AH XORrr, DI AX SUBxx, BP INCx, BP INCx, [BP] 0 DX MOV[]+x, ( pushRS )
REPZ, CMPSB, DX DI MOVxx, DX INCx, DX INCx, ( --> IP )
CX POPx, DI POPx, SI POPx, ( <-- lvl 3 ) DI [DI] MOVx[],
IFZ, AL AL XORrr, ( Z ) RETn, THEN, JMPs, L1 @ RPCs,
THEN,
( cont. )

22
blk/816
View File

@ -1,6 +1,16 @@
( find cont. ) L4 BSET PC 3 - ORG @ 4 + ! ( find )
DI 3 SUBxi, AX [DI] MOVx[], ( prev ) ( find word the same name as str in SI starting from tip in
AX AX ORxx, DI. Returns wordref in DI. Z if found, NZ if not. )
JNZ, AGAIN, ( loop ) CH CH XORrr, CL [SI] MOVr[], ( CX -> strlen )
AX INCx, ( NZ ) RETn, SI INCx, ( first char ) AX AX XORxx, ( initial prev )
BEGIN, ( loop )
DI AX SUBxx, ( jump to prev wordref )
AL [DI] -1 MOVr[]+, ( strlen )
CL AL CMPrr, IFZ, ( same len )
SI PUSHx, DI PUSHx, CX PUSHx, ( --> lvl 3 )
3 ADDALi, ( header ) AH AH XORrr, DI AX SUBxx,
REPZ, CMPSB,
CX POPx, DI POPx, SI POPx, ( <-- lvl 3 )
IFZ, AL AL XORrr, ( Z ) RETn, THEN,
THEN,
( cont. )

21
blk/817
View File

@ -1,15 +1,6 @@
CODE BYE BEGIN, JMPs, AGAIN, ;CODE ( find cont. )
CODE EMIT DI 3 SUBxi, AX [DI] MOVx[], ( prev )
AX POPx, AH 0x0e MOVri, ( print char ) 0x10 INT, AX AX ORxx,
;CODE JNZ, AGAIN, ( loop )
: FOO 'X' EMIT ; : BAR FOO FOO BYE ; AX INCx, ( NZ ) RETn,
L3 BSET 3 A, 'B' A, 'A' A, 'R' A,
PC 3 - ORG @ 1+ ! ( main )
SP PS_ADDR MOVxI,
BP RS_ADDR MOVxI,
DI 0x08 MOVxm, ( LATEST )
SI L3 @ MOVxI,
CALLn, L4 @ RPCn, ( find )
IFZ, JMPn, L1 @ RPCn, ( execute ) THEN,
AH 0x0e MOVri, ( print char ) AL '!' MOVri, 0x10 INT,
BEGIN, JMPs, AGAIN,

15
blk/818 Normal file
View File

@ -0,0 +1,15 @@
CODE BYE BEGIN, JMPs, AGAIN, ;CODE
CODE EMIT
AX POPx, AH 0x0e MOVri, ( print char ) 0x10 INT,
;CODE CODE 0 AX AX XORxx, AX PUSHx, ;CODE
: FOO 'X' EMIT ; : BAR 0 IF FOO THEN FOO BYE ;
L3 BSET 3 A, 'B' A, 'A' A, 'R' A,
PC 3 - ORG @ 1+ ! ( main )
SP PS_ADDR MOVxI,
BP RS_ADDR MOVxI,
DI 0x08 MOVxm, ( LATEST )
SI L3 @ MOVxI,
CALLn, L4 @ RPCn, ( find )
IFZ, JMPn, L1 @ RPCn, ( execute ) THEN,
AH 0x0e MOVri, ( print char ) AL '!' MOVri, 0x10 INT,
BEGIN, JMPs, AGAIN,

View File

@ -3,7 +3,7 @@
750 LOAD ( 8086 asm ) 750 LOAD ( 8086 asm )
262 LOAD ( xcomp ) 262 LOAD ( xcomp )
270 LOAD ( xcomp overrides ) 270 LOAD ( xcomp overrides )
812 817 LOADR 812 818 LOADR
(entry) _ (entry) _
( Update LATEST ) ( Update LATEST )
PC ORG @ 8 + ! PC ORG @ 8 + !