Use file-read-chunks library in asma.

This commit is contained in:
Andrew Alderwick 2021-10-04 22:28:13 +01:00
parent 4525d47699
commit e8f58aa579
1 changed files with 28 additions and 34 deletions

View File

@ -250,10 +250,8 @@
;asma-output/offset STA2 ;asma-output/offset STA2
;asma/addr STA2 ;asma/addr STA2
;asma/state STA ;asma/state STA
#01 ( 0001 ) #01 SWP ( 0100 ) ;asma/written-addr STA2
SWPk ( 0001 0100 ) ;asma/written-addr STA2
;&preamble-end ;&preamble SUB2k ,asma-assemble-chunk JSR POP2 POP2 ;&preamble-end ;&preamble SUB2k ,asma-assemble-chunk JSR POP2 POP2
;asma/line STA2
JMP2r JMP2r
&preamble &preamble
@ -265,32 +263,22 @@
) )
@asma-assemble-file-pass ( filename-ptr* -- ) @asma-assemble-file-pass ( filename-ptr* -- )
#0000 ;asma-assemble-chunk #0001 ROT2 ( func* line^ filename* )
;asma-read-buffer DUP2 ;asma-read-buffer/end ROT2 SUB2 ( func* line^ filename* buf* size^ )
ROT2 ( func* line^ buf* size^ filename* )
,file-read-chunks JSR
&loop asma-IF-ERROR ,&error JCN
OVR2 .File/name DEO2
DUP2 .File/offset-ls DEO2
;asma-read-buffer/end ;asma-read-buffer SUB2 STH2k .File/length DEO2
;asma-read-buffer DUP2k .File/load DEO2
.File/success DEI2
DUP2 STH2r SUB2 ORA ,&last-one JCN
,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
SUB2 SUB2
,&loop JMP
&last-one
ADD2k #00 ROT ROT STA
INC2
,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
( flush output buffer ) ( flush output buffer )
;asma-output/ptr LDA2 ;asma-write-buffer SUB2 ;asma/flush-fn LDA2 JSR2 ;asma-output/ptr LDA2 ;asma-write-buffer SUB2 ;asma/flush-fn LDA2 JSR2
POP2
&error &error
POP2 POP2 POP2 POP2 POP2 POP2 POP2 POP2
JMP2r JMP2r
include projects/library/file-read-chunks.tal
( (
Assemble a chunk of source code, which begins with whitespace or the start Assemble a chunk of source code, which begins with whitespace or the start
of a token and is divided up into tokens separated by whitespace. If the of a token and is divided up into tokens separated by whitespace. If the
@ -300,28 +288,34 @@
of the last token in the chunk. of the last token in the chunk.
) )
@asma-assemble-chunk ( ptr* len* -- assembled-up-to-ptr* ) @asma-assemble-chunk ( line^ ptr* len^ -- assembled-up-to-ptr* )
OVR2 ADD2 #0001 SUB2 SWP2 STH2k ROT2k ( line^ ptr* len^ ptr* len^ line^ )
;asma/line STA2 ( line^ ptr* len^ ptr* len^ )
ADD2 #0001 SUB2 NIP2 ( line^ ptr* last-ptr* )
SWP2 STH2k ( line^ last-ptr* ptr* / ptr* )
,&loop JMP ,&loop JMP
&next-char-pop &next-char-pop ( line^ last-ptr* ptr* char / start-of-token* )
POP POP
&next-char
INC2 INC2
&loop ( last-ptr* ptr* / start-of-token* ) &loop ( line^ last-ptr* ptr* / start-of-token* )
OVR2 OVR2 LTH2 ,&end JCN LTH2k ,&end JCN
LDAk ( last-ptr* ptr* char / start-of-token* ) LDAk ( line^ 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 ( line^ last-ptr* ptr* char 00 ptr* / start-of-token* )
STA STA STH2r ( line^ last-ptr* ptr* char start-of-token* )
STH2r ,asma-assemble-token JSR asma-IF-ERROR ,&error JCN ,asma-assemble-token JSR ( line^ last-ptr* ptr* char )
asma-IF-ERROR ,&error JCN
#0a NEQ ,&not-newline JCN #0a NEQ ,&not-newline JCN ( line^ last-ptr* ptr* )
;asma/line LDA2 INC2 ;asma/line STA2 ROT2 INC2 ( last-ptr* ptr* line+1^ )
DUP2 ;asma/line STA2
ROT2 ROT2 ( line^ last-ptr* ptr* )
&not-newline &not-newline
DUP2 INC2 STH2 ,&next-char JMP INC2 DUP2 STH2 ( line^ last-ptr* ptr* / start-of-token* )
,&loop JMP
&end &end
POP2 POP2 STH2r POP2 POP2 STH2r