Added keep mode optimizations to asma

This commit is contained in:
Andrew Alderwick 2021-05-13 22:51:36 +01:00
parent 8845a326d8
commit 696958a413
1 changed files with 24 additions and 24 deletions

View File

@ -42,8 +42,8 @@
OVR2 .File/name DEO2 OVR2 .File/name DEO2
DUP2 .File/offset DEO2 DUP2 .File/offset DEO2
#0100 .File/length DEO2 #0100 .File/length DEO2
#fe00 DUP2 DUP2 .File/load DEO2 #fe00 DUP2k .File/load DEO2
.File/success DEI2 DUP2 ORA ,&not-end JCN .File/success DEI2 ORAk ,&not-end JCN
POP2 POP2 POP2 POP2
&error &error
POP2 POP2 POP2 POP2 POP2 POP2
@ -71,7 +71,7 @@
JMP2r JMP2r
@asma-assemble-chunk ( ptr* len* -- assembled-up-to-ptr* ) @asma-assemble-chunk ( ptr* len* -- assembled-up-to-ptr* )
OVR2 ADD2 #0001 SUB2 SWP2 DUP2 STH2 OVR2 ADD2 #0001 SUB2 SWP2 STH2k
,&loop JMP ,&loop JMP
&next-char-pop &next-char-pop
@ -80,7 +80,7 @@
#0001 ADD2 #0001 ADD2
&loop ( last-ptr* ptr* / start-of-token* ) &loop ( last-ptr* ptr* / start-of-token* )
OVR2 OVR2 LTH2 ,&end JCN OVR2 OVR2 LTH2 ,&end JCN
DUP2 LDA ( last-ptr* ptr* char / start-of-token* ) LDAk ( last-ptr* ptr* char / start-of-token* )
DUP #20 GTH ,&next-char-pop JCN DUP #20 GTH ,&next-char-pop JCN
#00 OVR2 ( last-ptr* ptr* char 00 ptr* / start-of-token* ) #00 OVR2 ( last-ptr* ptr* char 00 ptr* / start-of-token* )
@ -108,21 +108,21 @@
DUP2 .Console/string DEO2 #0a .Console/char DEO DUP2 .Console/string DEO2 #0a .Console/char DEO
DUP2 ;asma/token STA2 DUP2 ;asma/token STA2
DUP2 ;asma/orig-token STA2 DUP2 ;asma/orig-token STA2
DUP2 LDA ,&not-empty JCN LDAk ,&not-empty JCN
POP2 POP2
JMP2r JMP2r
&not-empty ( token* / ) &not-empty ( token* / )
( truncate to one char long ) ( truncate to one char long )
#0001 ADD2 ( end* / ) #0001 ADD2 ( end* / )
DUP2 STH2 DUP2r LDAr ( end* / end* char ) STH2k LDAkr ( end* / end* char )
DUP2 STH2 ( end* / end* char end* ) STH2k ( end* / end* char end* )
LITr 00 STH2 ( / end* char end* 00 end* ) LITr 00 STH2 ( / end* char end* 00 end* )
STAr ( / end* char end* ) STAr ( / end* char end* )
( find lowest set bit of assembler/state ( find lowest set bit of assembler/state
in C, this would be i & -i ) in C, this would be i & -i )
#00 ;asma/state LDA DUP2 SUB AND ( tree-offset* / end* ) #00 ;asma/state LDA SUBk AND ( tree-offset* / end* )
DUP2 ;&first-char-trees ADD2 ( tree-offset* incoming-ptr* / end* ) DUP2 ;&first-char-trees ADD2 ( tree-offset* incoming-ptr* / end* )
;asma-traverse-tree JSR2 ;asma-traverse-tree JSR2
@ -172,7 +172,7 @@
LIT2r 0000 LIT2r 0000
&loop &loop
DUP2 LDA LDAk
DUP ,&not-end JCN DUP ,&not-end JCN
POP POP2 POP POP2
STH2r ROT #01 ADD #03 MUL STH2r ROT #01 ADD #03 MUL
@ -195,7 +195,7 @@
LITr 00 LITr 00
&loop &loop
DUP2 LDA LDAk
,&not-end JCN ,&not-end JCN
POP2 STHr POP2 STHr
JMP2r JMP2r
@ -216,8 +216,8 @@
( truncate to three chars long ) ( truncate to three chars long )
#0003 ADD2 ( end* / ) #0003 ADD2 ( end* / )
DUP2 STH2 DUP2r LDAr ( end* / end* char ) STH2k LDAkr ( end* / end* char )
DUP2 STH2 ( end* / end* char end* ) STH2k ( end* / end* char end* )
LITr 00 STH2 ( / end* char end* 00 end* ) LITr 00 STH2 ( / end* char end* 00 end* )
STAr ( / end* char end* ) STAr ( / end* char end* )
@ -227,7 +227,7 @@
;asma-opcodes/_disasm SUB2 #0003 SFT2 ( 00 byte / end* ) ;asma-opcodes/_disasm SUB2 #0003 SFT2 ( 00 byte / end* )
&loop &loop
DUP2r LDAr STHr LIT2r 0001 ADD2r ( 00 byte char / end* ) LDAkr STHr LIT2r 0001 ADD2r ( 00 byte char / end* )
DUP ,&not-end JCN DUP ,&not-end JCN
POP POP2r POP POP2r
SWP SWP
@ -278,7 +278,7 @@
,asma-append-heap-byte JMP ( tail call ) ,asma-append-heap-byte JMP ( tail call )
@asma-append-heap-string ( string* -- ) @asma-append-heap-string ( string* -- )
DUP2 LDA LDAk
DUP ,asma-append-heap-byte JSR DUP ,asma-append-heap-byte JSR
,&keep-going JCN ,&keep-going JCN
POP2 JMP2r POP2 JMP2r
@ -298,11 +298,11 @@
#0a .Console/char DEO ) #0a .Console/char DEO )
&loop ( incoming-ptr* ) &loop ( incoming-ptr* )
DUP2 LDA2 ORA ,&valid-node JCN LDA2k ORA ,&valid-node JCN
#01 JMP2r #01 JMP2r
&valid-node &valid-node
LDA2 DUP2 STH2 LDA2 STH2k
#0004 ADD2 ,asma-strcmp-tree JSR #0004 ADD2 ,asma-strcmp-tree JSR
DUP ,&nomatch JCN DUP ,&nomatch JCN
POP2r JMP2r POP2r JMP2r
@ -319,8 +319,8 @@
;asma/token LDA2 STH2 ;asma/token LDA2 STH2
&loop ( node-key* / token* ) &loop ( node-key* / token* )
DUP2 #0001 ADD2 SWP2 LDA DUP2r LDAr STHr DUP2 #0001 ADD2 SWP2 LDA LDAkr STHr
DUP2 ORA ,&not-end JCN ORAk ,&not-end JCN
( end of C strings, match found ) ( end of C strings, match found )
POP2r POP POP2r POP
@ -447,7 +447,7 @@
;asma/token LDA2 ;asma/token LDA2
&loop &loop
DUP2 LDA LDAk
DUP ,&not-end JCN DUP ,&not-end JCN
POP POP2 POP POP2
@ -495,13 +495,13 @@
JMP2r JMP2r
@asma-addr-helper ( -- addr* ) @asma-addr-helper ( -- addr* )
;asma/token LDA2 DUP2 LDA #26 NEQ ,&not-local JCN ;asma/token LDA2 LDAk #26 NEQ ,&not-local JCN
#0001 ADD2 ;asma/token STA2 #0001 ADD2 ;asma/token STA2
;asma/scope-addr LDA2 ;asma-trees/scope LDA2 ;asma/scope-addr LDA2 ;asma-trees/scope LDA2
,&final-lookup JMP ,&final-lookup JMP
&not-local ( token* ) &not-local ( token* )
DUP2 LDA LDAk
DUP ,&not-end JCN DUP ,&not-end JCN
POP POP2 POP POP2
#0000 ;asma-trees/labels #0000 ;asma-trees/labels
@ -519,7 +519,7 @@
STHr ,&not-found JCN STHr ,&not-found JCN
( token* binary-ptr* ) ( token* binary-ptr* )
#0001 ADD2 ;asma/token STA2 #0001 ADD2 ;asma/token STA2
DUP2 LDA2 SWP2 #0002 ADD2 LDA2k SWP2 #0002 ADD2
&final-lookup ( addr-offset* incoming-ptr* ) &final-lookup ( addr-offset* incoming-ptr* )
;asma-traverse-tree JSR2 ,&not-found JCN ;asma-traverse-tree JSR2 ,&not-found JCN
@ -574,13 +574,13 @@
;asma-trees/macros ;asma-traverse-tree JSR2 ,&not-macro JCN ;asma-trees/macros ;asma-traverse-tree JSR2 ,&not-macro JCN
&macro-loop &macro-loop
DUP2 LDA ,&keep-going JCN LDAk ,&keep-going JCN
&error &error
POP2 POP2
JMP2r JMP2r
&keep-going &keep-going
DUP2 DUP2 ;asma-strlen JSR2 #00 SWP #0001 ADD2 ADD2 DUP2k ;asma-strlen JSR2 #00 SWP #0001 ADD2 ADD2
SWP2 ;asma-assemble-token JSR2 asma-IF-ERROR ,&error JCN SWP2 ;asma-assemble-token JSR2 asma-IF-ERROR ,&error JCN
,&macro-loop JMP ,&macro-loop JMP