mirror of
https://github.com/hsoft/collapseos.git
synced 2025-04-02 04:38:40 +11:00
Add words 1+ 2+ 1- 2- and consts 0 1 -1
Saves quite a few bytes in the final binary.
This commit is contained in:
parent
e1e634c815
commit
5d4155aa32
2
blk/054
2
blk/054
@ -10,3 +10,5 @@ MOD a b -- c a % b -> c
|
|||||||
AND a b -- c a & b -> c
|
AND a b -- c a & b -> c
|
||||||
OR a b -- c a | b -> c
|
OR a b -- c a | b -> c
|
||||||
XOR a b -- c a ^ b -> c
|
XOR a b -- c a ^ b -> c
|
||||||
|
|
||||||
|
Shortcuts: 1+ 2+ 1- 2-
|
||||||
|
Binary file not shown.
@ -29,7 +29,7 @@
|
|||||||
: LIST
|
: LIST
|
||||||
BLK@
|
BLK@
|
||||||
16 0 DO
|
16 0 DO
|
||||||
I 1 + .2 SPC
|
I 1+ .2 SPC
|
||||||
64 I * BLK( + (print)
|
64 I * BLK( + (print)
|
||||||
CRLF
|
CRLF
|
||||||
LOOP
|
LOOP
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
: H@ HERE @ ;
|
: H@ HERE @ ;
|
||||||
: IMMEDIATE
|
: IMMEDIATE
|
||||||
CURRENT @ 1 -
|
CURRENT @ 1-
|
||||||
DUP C@ 128 OR SWAP C!
|
DUP C@ 128 OR SWAP C!
|
||||||
;
|
;
|
||||||
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
|
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
|
||||||
@ -52,7 +52,7 @@
|
|||||||
2 ALLOT
|
2 ALLOT
|
||||||
DUP H@ -^ SWAP ( a-H a )
|
DUP H@ -^ SWAP ( a-H a )
|
||||||
!
|
!
|
||||||
H@ 2 - ( push a. -2 for allot offset )
|
H@ 2- ( push a. -2 for allot offset )
|
||||||
; IMMEDIATE
|
; IMMEDIATE
|
||||||
|
|
||||||
: CREATE
|
: CREATE
|
||||||
@ -97,7 +97,7 @@
|
|||||||
( Increase loop counter and returns whether we should loop. )
|
( Increase loop counter and returns whether we should loop. )
|
||||||
: _
|
: _
|
||||||
R> ( IP, keep for later )
|
R> ( IP, keep for later )
|
||||||
R> 1 + ( ip i+1 )
|
R> 1+ ( ip i+1 )
|
||||||
DUP >R ( ip i )
|
DUP >R ( ip i )
|
||||||
I' = ( ip f )
|
I' = ( ip f )
|
||||||
SWAP >R ( f )
|
SWAP >R ( f )
|
||||||
@ -123,7 +123,7 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
: DELW
|
: DELW
|
||||||
1 - 0 SWAP C!
|
1- 0 SWAP C!
|
||||||
;
|
;
|
||||||
|
|
||||||
: PREV
|
: PREV
|
||||||
@ -132,7 +132,7 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
: WHLEN
|
: WHLEN
|
||||||
1 - C@ ( name len field )
|
1- C@ ( name len field )
|
||||||
127 AND ( 0x7f. remove IMMEDIATE flag )
|
127 AND ( 0x7f. remove IMMEDIATE flag )
|
||||||
3 + ( fixed header len )
|
3 + ( fixed header len )
|
||||||
;
|
;
|
||||||
@ -155,6 +155,6 @@
|
|||||||
['] INTERPRET ( I )
|
['] INTERPRET ( I )
|
||||||
BEGIN ( I )
|
BEGIN ( I )
|
||||||
DUP ( I I )
|
DUP ( I I )
|
||||||
R> DROP I 2 - @ ( I I a )
|
R> DROP I 2- @ ( I I a )
|
||||||
= UNTIL
|
= UNTIL
|
||||||
;
|
;
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
256 /MOD SWAP
|
256 /MOD SWAP
|
||||||
.x .x
|
.x .x
|
||||||
SPC
|
SPC
|
||||||
2 +
|
2+
|
||||||
LOOP
|
LOOP
|
||||||
DROP
|
DROP
|
||||||
8 0 DO
|
8 0 DO
|
||||||
@ -58,7 +58,7 @@
|
|||||||
DUP <>{ 0x20 &< 0x7e |> <>}
|
DUP <>{ 0x20 &< 0x7e |> <>}
|
||||||
IF DROP '.' THEN
|
IF DROP '.' THEN
|
||||||
EMIT
|
EMIT
|
||||||
1 +
|
1+
|
||||||
LOOP
|
LOOP
|
||||||
CRLF
|
CRLF
|
||||||
;
|
;
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
( special case: do we have a negative? )
|
( special case: do we have a negative? )
|
||||||
DUP '-' = IF
|
DUP '-' = IF
|
||||||
( Oh, a negative, let's recurse and reverse )
|
( Oh, a negative, let's recurse and reverse )
|
||||||
DROP 1 + ( a+1 )
|
DROP 1+ ( a+1 )
|
||||||
(parsed) ( n f )
|
(parsed) ( n f )
|
||||||
0 ROT ( f 0 n )
|
0 ROT ( f 0 n )
|
||||||
- SWAP EXIT ( 0-n f )
|
- SWAP EXIT ( 0-n f )
|
||||||
@ -88,7 +88,7 @@
|
|||||||
2DROP 0 EXIT ( a 0 )
|
2DROP 0 EXIT ( a 0 )
|
||||||
THEN
|
THEN
|
||||||
BEGIN ( a r 0 )
|
BEGIN ( a r 0 )
|
||||||
DROP SWAP 1 + ( r a+1 )
|
DROP SWAP 1+ ( r a+1 )
|
||||||
DUP C@ ( r a c )
|
DUP C@ ( r a c )
|
||||||
ROT SWAP ( a r c )
|
ROT SWAP ( a r c )
|
||||||
_pdacc ( a r f )
|
_pdacc ( a r f )
|
||||||
@ -113,18 +113,18 @@
|
|||||||
|
|
||||||
: ,
|
: ,
|
||||||
HERE @ !
|
HERE @ !
|
||||||
HERE @ 2 + HERE !
|
HERE @ 2+ HERE !
|
||||||
;
|
;
|
||||||
|
|
||||||
: C,
|
: C,
|
||||||
HERE @ C!
|
HERE @ C!
|
||||||
HERE @ 1 + HERE !
|
HERE @ 1+ HERE !
|
||||||
;
|
;
|
||||||
|
|
||||||
( The NOT is to normalize the negative/positive numbers to 1
|
( The NOT is to normalize the negative/positive numbers to 1
|
||||||
or 0. Hadn't we wanted to normalize, we'd have written:
|
or 0. Hadn't we wanted to normalize, we'd have written:
|
||||||
32 CMP 1 - )
|
32 CMP 1 - )
|
||||||
: WS? 33 CMP 1 + NOT ;
|
: WS? 33 CMP 1+ NOT ;
|
||||||
|
|
||||||
: TOWORD
|
: TOWORD
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -142,7 +142,7 @@
|
|||||||
( We take advantage of the fact that char MSB is
|
( We take advantage of the fact that char MSB is
|
||||||
always zero to pre-write our null-termination )
|
always zero to pre-write our null-termination )
|
||||||
OVER ! ( a )
|
OVER ! ( a )
|
||||||
1 + ( a+1 )
|
1+ ( a+1 )
|
||||||
C< ( a c )
|
C< ( a c )
|
||||||
DUP WS?
|
DUP WS?
|
||||||
UNTIL
|
UNTIL
|
||||||
@ -157,7 +157,7 @@
|
|||||||
DUP C@ ( a c )
|
DUP C@ ( a c )
|
||||||
DUP C, ( a c )
|
DUP C, ( a c )
|
||||||
NOT IF DROP EXIT THEN
|
NOT IF DROP EXIT THEN
|
||||||
1 + ( a+1 )
|
1+ ( a+1 )
|
||||||
AGAIN
|
AGAIN
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -165,7 +165,7 @@
|
|||||||
HERE @ ( w h )
|
HERE @ ( w h )
|
||||||
SWAP SCPY ( h )
|
SWAP SCPY ( h )
|
||||||
( Adjust HERE -1 because SCPY copies the null )
|
( Adjust HERE -1 because SCPY copies the null )
|
||||||
HERE @ 1 - ( h h' )
|
HERE @ 1- ( h h' )
|
||||||
DUP HERE ! ( h h' )
|
DUP HERE ! ( h h' )
|
||||||
SWAP - ( sz )
|
SWAP - ( sz )
|
||||||
( write prev value )
|
( write prev value )
|
||||||
@ -220,7 +220,7 @@
|
|||||||
32 , ,
|
32 , ,
|
||||||
;
|
;
|
||||||
|
|
||||||
: IMMED? 1 - C@ 0x80 AND ;
|
: IMMED? 1- C@ 0x80 AND ;
|
||||||
|
|
||||||
( ';' can't have its name right away because, when created, it
|
( ';' can't have its name right away because, when created, it
|
||||||
is not an IMMEDIATE yet and will not be treated properly by
|
is not an IMMEDIATE yet and will not be treated properly by
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
DUP <>{ 0x70 &= 0x58 |= 0x20 |= 0x24 |= <>}
|
DUP <>{ 0x70 &= 0x58 |= 0x20 |= 0x24 |= <>}
|
||||||
IF DROP 4 + EXIT THEN
|
IF DROP 4 + EXIT THEN
|
||||||
( regular word )
|
( regular word )
|
||||||
0x22 = NOT IF 2 + EXIT THEN
|
0x22 = NOT IF 2+ EXIT THEN
|
||||||
( it's a lit, skip to null char )
|
( it's a lit, skip to null char )
|
||||||
( a )
|
( a )
|
||||||
1 + ( we skip by 2, but the loop below is pre-inc... )
|
1+ ( we skip by 2, but the loop below is pre-inc... )
|
||||||
BEGIN 1 + DUP C@ NOT UNTIL
|
BEGIN 1+ DUP C@ NOT UNTIL
|
||||||
( skip null char )
|
( skip null char )
|
||||||
1 +
|
1+
|
||||||
;
|
;
|
||||||
|
|
||||||
( Get word addr, starting at name's address )
|
( Get word addr, starting at name's address )
|
||||||
@ -57,7 +57,7 @@
|
|||||||
our number will be treated like a regular wordref.
|
our number will be treated like a regular wordref.
|
||||||
)
|
)
|
||||||
DROP
|
DROP
|
||||||
2 + ( o ol a+2 )
|
2+ ( o ol a+2 )
|
||||||
ROT ROT 2DROP ( a )
|
ROT ROT 2DROP ( a )
|
||||||
EXIT
|
EXIT
|
||||||
THEN
|
THEN
|
||||||
@ -93,9 +93,9 @@
|
|||||||
( doesWord is processed exactly like a compiledWord, but
|
( doesWord is processed exactly like a compiledWord, but
|
||||||
starts 2 bytes further. )
|
starts 2 bytes further. )
|
||||||
( ol o a2 a1 n )
|
( ol o a2 a1 n )
|
||||||
0x2b = IF 2 + THEN
|
0x2b = IF 2+ THEN
|
||||||
( ol o a2 a1 )
|
( ol o a2 a1 )
|
||||||
1 + ( ol o a2 a1+1 )
|
1+ ( ol o a2 a1+1 )
|
||||||
BEGIN ( ol o a2 a1 )
|
BEGIN ( ol o a2 a1 )
|
||||||
2OVER ( ol o a2 a1 ol o )
|
2OVER ( ol o a2 a1 ol o )
|
||||||
SWAP ( ol o a2 a1 o ol )
|
SWAP ( ol o a2 a1 o ol )
|
||||||
@ -136,11 +136,11 @@
|
|||||||
prev word is a "hook word", that is, an empty word. )
|
prev word is a "hook word", that is, an empty word. )
|
||||||
( H@ == target )
|
( H@ == target )
|
||||||
DUP H@ !
|
DUP H@ !
|
||||||
DUP 1 - C@ 0x7f AND ( t namelen )
|
DUP 1- C@ 0x7f AND ( t namelen )
|
||||||
SWAP 3 - @ ( namelen po )
|
SWAP 3 - @ ( namelen po )
|
||||||
-^ ( o )
|
-^ ( o )
|
||||||
( H@+2 == offset )
|
( H@+2 == offset )
|
||||||
H@ 2 + ! ( )
|
H@ 2+ ! ( )
|
||||||
( We have our offset, now let's copy our memory chunk )
|
( We have our offset, now let's copy our memory chunk )
|
||||||
H@ @ DUP WHLEN - ( src )
|
H@ @ DUP WHLEN - ( src )
|
||||||
DUP H@ -^ ( src u )
|
DUP H@ -^ ( src u )
|
||||||
@ -162,7 +162,7 @@
|
|||||||
DUP ROT ( wr wr we )
|
DUP ROT ( wr wr we )
|
||||||
( call RLWORD. we need a sig: ol o wr we )
|
( call RLWORD. we need a sig: ol o wr we )
|
||||||
H@ @ ( wr wr we ol )
|
H@ @ ( wr wr we ol )
|
||||||
H@ 2 + @ ( wr wr we ol o )
|
H@ 2+ @ ( wr wr we ol o )
|
||||||
2SWAP ( wr ol o wr we )
|
2SWAP ( wr ol o wr we )
|
||||||
RLWORD ( wr )
|
RLWORD ( wr )
|
||||||
( wr becomes wr's prev and we is wr-header )
|
( wr becomes wr's prev and we is wr-header )
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
: (parsec) ( a -- n f )
|
: (parsec) ( a -- n f )
|
||||||
( apostrophe is ASCII 39 )
|
( apostrophe is ASCII 39 )
|
||||||
DUP C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
|
DUP C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
|
||||||
DUP 2 + C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
|
DUP 2+ C@ 39 = NOT IF 0 EXIT THEN ( a 0 )
|
||||||
( surrounded by apos, good, return )
|
( surrounded by apos, good, return )
|
||||||
1 + C@ 1 ( n 1 )
|
1+ C@ 1 ( n 1 )
|
||||||
;
|
;
|
||||||
|
|
||||||
( returns negative value on error )
|
( returns negative value on error )
|
||||||
@ -28,7 +28,7 @@
|
|||||||
( '0': ASCII 0x30 'x': 0x78 0x7830: 30768 )
|
( '0': ASCII 0x30 'x': 0x78 0x7830: 30768 )
|
||||||
DUP @ 30768 = NOT IF 0 EXIT THEN ( a 0 )
|
DUP @ 30768 = NOT IF 0 EXIT THEN ( a 0 )
|
||||||
( We have "0x" prefix )
|
( We have "0x" prefix )
|
||||||
2 +
|
2+
|
||||||
( validate slen )
|
( validate slen )
|
||||||
DUP SLEN ( a l )
|
DUP SLEN ( a l )
|
||||||
DUP 0 = IF DROP 0 EXIT THEN ( a 0 )
|
DUP 0 = IF DROP 0 EXIT THEN ( a 0 )
|
||||||
@ -40,7 +40,7 @@
|
|||||||
hexdig ( a r n )
|
hexdig ( a r n )
|
||||||
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
||||||
SWAP 16 * + ( a r*16+n )
|
SWAP 16 * + ( a r*16+n )
|
||||||
SWAP 1 + SWAP ( a+1 r )
|
SWAP 1+ SWAP ( a+1 r )
|
||||||
AGAIN
|
AGAIN
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@
|
|||||||
( '0': ASCII 0x30 'b': 0x62 0x6230: 25136 )
|
( '0': ASCII 0x30 'b': 0x62 0x6230: 25136 )
|
||||||
DUP @ 25136 = NOT IF 0 EXIT THEN ( a 0 )
|
DUP @ 25136 = NOT IF 0 EXIT THEN ( a 0 )
|
||||||
( We have "0b" prefix )
|
( We have "0b" prefix )
|
||||||
2 +
|
2+
|
||||||
( validate slen )
|
( validate slen )
|
||||||
DUP SLEN ( a l )
|
DUP SLEN ( a l )
|
||||||
DUP 0 = IF DROP 0 EXIT THEN ( a 0 )
|
DUP 0 = IF DROP 0 EXIT THEN ( a 0 )
|
||||||
@ -70,7 +70,7 @@
|
|||||||
bindig ( a r n )
|
bindig ( a r n )
|
||||||
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
||||||
SWAP 2 * + ( a r*2+n )
|
SWAP 2 * + ( a r*2+n )
|
||||||
SWAP 1 + SWAP ( a+1 r )
|
SWAP 1+ SWAP ( a+1 r )
|
||||||
AGAIN
|
AGAIN
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
( points to INBUF )
|
( points to INBUF )
|
||||||
: IN( 2 RDLNMEM+ ;
|
: IN( 2 RDLNMEM+ ;
|
||||||
( points to INBUF's end )
|
( points to INBUF's end )
|
||||||
: IN) INBUFSZ 2 + RDLNMEM+ ;
|
: IN) INBUFSZ 2+ RDLNMEM+ ;
|
||||||
|
|
||||||
( flush input buffer )
|
( flush input buffer )
|
||||||
( set IN> to IN( and set IN> @ to null )
|
( set IN> to IN( and set IN> @ to null )
|
||||||
@ -25,7 +25,7 @@
|
|||||||
: (inbs)
|
: (inbs)
|
||||||
( already at IN( ? )
|
( already at IN( ? )
|
||||||
IN> @ IN( = IF EXIT THEN
|
IN> @ IN( = IF EXIT THEN
|
||||||
IN> @ 1 - IN> !
|
IN> @ 1- IN> !
|
||||||
SPC BS
|
SPC BS
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
DUP ( astart aend )
|
DUP ( astart aend )
|
||||||
BEGIN
|
BEGIN
|
||||||
DUP C@ 0 = IF -^ EXIT THEN
|
DUP C@ 0 = IF -^ EXIT THEN
|
||||||
1 +
|
1+
|
||||||
AGAIN
|
AGAIN
|
||||||
;
|
;
|
||||||
|
@ -371,7 +371,7 @@
|
|||||||
( Place BEGIN, where you want to jump back and AGAIN after
|
( Place BEGIN, where you want to jump back and AGAIN after
|
||||||
a relative jump operator. Just like BSET and BWR. )
|
a relative jump operator. Just like BSET and BWR. )
|
||||||
: BEGIN, PC ;
|
: BEGIN, PC ;
|
||||||
: AGAIN, PC - 1 - A, ;
|
: AGAIN, PC - 1- A, ;
|
||||||
|
|
||||||
: BSET PC SWAP ! ;
|
: BSET PC SWAP ! ;
|
||||||
: BWR @ AGAIN, ;
|
: BWR @ AGAIN, ;
|
||||||
@ -383,11 +383,10 @@
|
|||||||
: IFNC, JRC, FJR, ;
|
: IFNC, JRC, FJR, ;
|
||||||
: THEN,
|
: THEN,
|
||||||
DUP PC ( l l pc )
|
DUP PC ( l l pc )
|
||||||
-^ 1 - ( l off )
|
-^ 1- ( l off )
|
||||||
( warning: l is a PC offset, not a mem addr! )
|
( warning: l is a PC offset, not a mem addr! )
|
||||||
SWAP ORG @ + ( off addr )
|
SWAP ORG @ + ( off addr )
|
||||||
C!
|
C!
|
||||||
;
|
;
|
||||||
: FWR BSET 0 A, ;
|
: FWR BSET 0 A, ;
|
||||||
: FSET @ THEN, ;
|
: FSET @ THEN, ;
|
||||||
|
|
||||||
|
@ -381,3 +381,48 @@ CODE (im1)
|
|||||||
IM1,
|
IM1,
|
||||||
EI,
|
EI,
|
||||||
;CODE
|
;CODE
|
||||||
|
|
||||||
|
CODE 0
|
||||||
|
HL 0 LDddnn,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE 1
|
||||||
|
HL 1 LDddnn,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE -1
|
||||||
|
HL -1 LDddnn,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE 1+
|
||||||
|
HL POPqq,
|
||||||
|
chkPS,
|
||||||
|
HL INCss,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE 1-
|
||||||
|
HL POPqq,
|
||||||
|
chkPS,
|
||||||
|
HL DECss,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE 2+
|
||||||
|
HL POPqq,
|
||||||
|
chkPS,
|
||||||
|
HL INCss,
|
||||||
|
HL INCss,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
|
||||||
|
CODE 2-
|
||||||
|
HL POPqq,
|
||||||
|
chkPS,
|
||||||
|
HL DECss,
|
||||||
|
HL DECss,
|
||||||
|
HL PUSHqq,
|
||||||
|
;CODE
|
||||||
|
Loading…
Reference in New Issue
Block a user