diff --git a/projects/software/asma.tal b/projects/software/asma.tal index 51739e2..abf2250 100644 --- a/projects/software/asma.tal +++ b/projects/software/asma.tal @@ -250,10 +250,8 @@ ;asma-output/offset STA2 ;asma/addr STA2 ;asma/state STA - #01 ( 0001 ) - SWPk ( 0001 0100 ) ;asma/written-addr STA2 + #01 SWP ( 0100 ) ;asma/written-addr STA2 ;&preamble-end ;&preamble SUB2k ,asma-assemble-chunk JSR POP2 POP2 - ;asma/line STA2 JMP2r &preamble @@ -265,32 +263,22 @@ ) @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 - 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 + asma-IF-ERROR ,&error JCN ( flush output buffer ) ;asma-output/ptr LDA2 ;asma-write-buffer SUB2 ;asma/flush-fn LDA2 JSR2 - POP2 &error - POP2 POP2 POP2 + POP2 POP2 POP2 POP2 POP2 JMP2r +include projects/library/file-read-chunks.tal + ( 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 @@ -300,28 +288,34 @@ of the last token in the chunk. ) -@asma-assemble-chunk ( ptr* len* -- assembled-up-to-ptr* ) - OVR2 ADD2 #0001 SUB2 SWP2 STH2k +@asma-assemble-chunk ( line^ ptr* len^ -- assembled-up-to-ptr* ) + 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 - &next-char-pop + &next-char-pop ( line^ last-ptr* ptr* char / start-of-token* ) POP - &next-char INC2 - &loop ( last-ptr* ptr* / start-of-token* ) - OVR2 OVR2 LTH2 ,&end JCN - LDAk ( last-ptr* ptr* char / start-of-token* ) + &loop ( line^ last-ptr* ptr* / start-of-token* ) + LTH2k ,&end JCN + LDAk ( line^ last-ptr* ptr* char / start-of-token* ) DUP #20 GTH ,&next-char-pop JCN - #00 OVR2 ( last-ptr* ptr* char 00 ptr* / start-of-token* ) - STA - STH2r ,asma-assemble-token JSR asma-IF-ERROR ,&error JCN + #00 OVR2 ( line^ last-ptr* ptr* char 00 ptr* / start-of-token* ) + STA STH2r ( line^ last-ptr* ptr* char start-of-token* ) + ,asma-assemble-token JSR ( line^ last-ptr* ptr* char ) + asma-IF-ERROR ,&error JCN - #0a NEQ ,¬-newline JCN - ;asma/line LDA2 INC2 ;asma/line STA2 + #0a NEQ ,¬-newline JCN ( line^ last-ptr* ptr* ) + ROT2 INC2 ( last-ptr* ptr* line+1^ ) + DUP2 ;asma/line STA2 + ROT2 ROT2 ( line^ last-ptr* ptr* ) ¬-newline - DUP2 INC2 STH2 ,&next-char JMP + INC2 DUP2 STH2 ( line^ last-ptr* ptr* / start-of-token* ) + ,&loop JMP &end POP2 POP2 STH2r