(asma) Remove tail call optimisation.

This commit is contained in:
Andrew Alderwick 2022-10-19 12:07:52 +01:00
parent 55f5f7a800
commit ca6d755bd6
1 changed files with 11 additions and 37 deletions

View File

@ -225,7 +225,7 @@
;asma-read-buffer DUP2 ;asma-read-buffer/end ROT2 SUB2 ( func* line^ filename* buf* size^ ) ;asma-read-buffer DUP2 ;asma-read-buffer/end ROT2 SUB2 ( func* line^ filename* buf* size^ )
ROT2 ( func* line^ buf* size^ filename* ) ROT2 ( func* line^ buf* size^ filename* )
,file-read-chunks JSR ,file-read-chunks JSR
;asma-flush-held JSR2 ;asma-flush-lit JSR2
asma-IF-ERROR ,&error JCN asma-IF-ERROR ,&error JCN
@ -351,7 +351,7 @@
@asma [ @asma [
&pass $1 &state $1 &line $2 &lines $2 &break $1 &eof $1 &pass $1 &state $1 &line $2 &lines $2 &break $1 &eof $1
&comment-level $1 &comment-level $1
&token $2 &orig-token $2 &lit $1 &lit-present $1 &jsr $1 &token $2 &orig-token $2 &lit $1 &lit-present $1
&addr $2 &written-addr $2 &flush-fn $2 &addr $2 &written-addr $2 &flush-fn $2
&src-filename $2 &dest-filename $2 &src-filename $2 &dest-filename $2
&error $2 &log-level $1 &error $2 &log-level $1
@ -516,7 +516,6 @@
@asma-write-lit ( byte -- ) @asma-write-lit ( byte -- )
;asma/lit LDA2 ,&present JCN ;asma/lit LDA2 ,&present JCN
,asma-flush-held JSR
POP #01 ;asma/lit STA2 POP #01 ;asma/lit STA2
#0002 ,asma-advance-addr JMP ( tail call ) #0002 ,asma-advance-addr JMP ( tail call )
&present &present
@ -533,22 +532,14 @@
SWP2 STA2 SWP2 STA2
JMP2r JMP2r
@asma-flush-held ( -- ) @asma-flush-lit ( -- )
;asma/lit LDA2 ,&lit-present JCN ;asma/lit LDA2 ,&present JCN
POP ,&part2 JMP POP JMP2r
&lit-present &present
#fffe ,asma-advance-addr JSR #fffe ,asma-advance-addr JSR
LIT LIT ,asma-write-byte/raw JSR LIT LIT ,asma-write-byte/raw JSR
,asma-write-byte/raw JSR ,asma-write-byte/raw JSR
#0000 ;asma/lit STA2 #0000 ;asma/lit STA2
&part2
;asma/jsr LDA DUP ,&jsr-present JCN
POP JMP2r
&jsr-present
#ffff ,asma-advance-addr JSR
,asma-write-byte/raw JSR
#00 ;asma/jsr STA
JMP2r JMP2r
@asma-write-short ( short -- ) @asma-write-short ( short -- )
@ -557,7 +548,7 @@
( fall through ) ( fall through )
@asma-write-byte ( byte -- ) @asma-write-byte ( byte -- )
,asma-flush-held JSR ,asma-flush-lit JSR
&raw &raw
;asma/addr LDA2 ;asma/written-addr LDA2 ;asma/addr LDA2 ;asma/written-addr LDA2
LTH2k ,&rewound JCN LTH2k ,&rewound JCN
@ -676,7 +667,7 @@
JMP2r JMP2r
@asma-label-define @asma-label-define
;asma-flush-held JSR2 ;asma-flush-lit JSR2
;asma-trees/labels ,asma-label-helper JSR ;asma-trees/labels ,asma-label-helper JSR
,&already-existed JCN ,&already-existed JCN
@ -687,7 +678,7 @@
JMP2r JMP2r
@asma-sublabel-define @asma-sublabel-define
;asma-flush-held JSR2 ;asma-flush-lit JSR2
;asma-trees/scope LDA2 ,asma-label-helper JSR ;asma-trees/scope LDA2 ,asma-label-helper JSR
POP POP2 POP POP2
JMP2r JMP2r
@ -717,12 +708,12 @@
#00 JMP2r #00 JMP2r
@asma-pad-absolute @asma-pad-absolute
;asma-flush-held JSR2 ;asma-flush-lit JSR2
#0000 ;asma/addr STA2 #0000 ;asma/addr STA2
,asma-pad-helper JMP ,asma-pad-helper JMP
@asma-pad-relative @asma-pad-relative
;asma-flush-held JSR2 ;asma-flush-lit JSR2
( fall through ) ( fall through )
@asma-pad-helper ( -- ) @asma-pad-helper ( -- )
@ -861,25 +852,8 @@
@asma-normal-body @asma-normal-body
;asma-parse-opcode JSR2 ,&not-opcode JCN ;asma-parse-opcode JSR2 ,&not-opcode JCN
DUP [ LIT JSR ] EQU ,&hold-jsr JCN
DUP [ LIT JSR2 ] EQU ,&hold-jsr JCN
DUP [ LIT JMP2r ] NEQ ,&write-opcode JCN
;asma/jsr LDA ,&optimise-jsr-jmp2r JCN
&write-opcode
;asma-write-byte JMP2 ( tail call ) ;asma-write-byte JMP2 ( tail call )
&hold-jsr
;asma-flush-held JSR2
;asma/jsr STA
#0001 ;asma-advance-addr JMP2 ( tail call )
&optimise-jsr-jmp2r
POP
;asma/jsr LDAk #00 SWP2 STA
#e0 AND [ LIT JMP ] ORA
#ffff ;asma-advance-addr JSR2
,&write-opcode JMP
&not-opcode &not-opcode
#01 ;asma-parse-hex-string JSR2 JMP #01 ;asma-parse-hex-string JSR2 JMP
( hex invalid ) ,&not-hex JMP ( hex invalid ) ,&not-hex JMP