Browse code

Use file-read-chunks library in asma.

Andrew Alderwick authored on 04/10/2021 21:28:13
Showing 1 changed files
... ...
@@ -250,10 +250,8 @@
250 250
 		;asma-output/offset STA2
251 251
 		;asma/addr STA2
252 252
 		;asma/state STA
253
-	#01 ( 0001 )
254
-	SWPk ( 0001 0100 ) ;asma/written-addr STA2
253
+	#01 SWP ( 0100 ) ;asma/written-addr STA2
255 254
 	;&preamble-end ;&preamble SUB2k ,asma-assemble-chunk JSR POP2 POP2
256
-	;asma/line STA2
257 255
 	JMP2r
258 256
 
259 257
 	&preamble
... ...
@@ -265,32 +263,22 @@
265 263
 )
266 264
 
267 265
 @asma-assemble-file-pass ( filename-ptr* -- )
268
-	#0000
266
+	;asma-assemble-chunk #0001 ROT2 ( func* line^ filename* )
267
+	;asma-read-buffer DUP2 ;asma-read-buffer/end ROT2 SUB2 ( func* line^ filename* buf* size^ )
268
+	ROT2 ( func* line^ buf* size^ filename* )
269
+	,file-read-chunks JSR
269 270
 
270
-	&loop
271
-	OVR2 .File/name DEO2
272
-	DUP2 .File/offset-ls DEO2
273
-	;asma-read-buffer/end ;asma-read-buffer SUB2 STH2k .File/length DEO2
274
-	;asma-read-buffer DUP2k .File/load DEO2
275
-	.File/success DEI2
276
-	DUP2 STH2r SUB2 ORA ,&last-one JCN
277
-	,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
278
-	SUB2 SUB2
279
-	,&loop JMP
280
-
281
-	&last-one
282
-	ADD2k #00 ROT ROT STA
283
-	INC2
284
-	,asma-assemble-chunk JSR asma-IF-ERROR ,&error JCN
271
+	asma-IF-ERROR ,&error JCN
285 272
 
286 273
 	( flush output buffer )
287 274
 	;asma-output/ptr LDA2 ;asma-write-buffer SUB2 ;asma/flush-fn LDA2 JSR2
288 275
 
289
-	POP2
290 276
 	&error
291
-	POP2 POP2 POP2
277
+	POP2 POP2 POP2 POP2 POP2
292 278
 	JMP2r
293 279
 
280
+include projects/library/file-read-chunks.tal
281
+
294 282
 (
295 283
 	Assemble a chunk of source code, which begins with whitespace or the start
296 284
 	of a token and is divided up into tokens separated by whitespace. If the
... ...
@@ -300,28 +288,34 @@
300 288
 	of the last token in the chunk.
301 289
 )
302 290
 
303
-@asma-assemble-chunk ( ptr* len* -- assembled-up-to-ptr* )
304
-	OVR2 ADD2 #0001 SUB2 SWP2 STH2k
291
+@asma-assemble-chunk ( line^ ptr* len^ -- assembled-up-to-ptr* )
292
+	ROT2k ( line^ ptr* len^ ptr* len^ line^ )
293
+	;asma/line STA2 ( line^ ptr* len^ ptr* len^ )
294
+	ADD2 #0001 SUB2 NIP2 ( line^ ptr* last-ptr* )
295
+	SWP2 STH2k ( line^ last-ptr* ptr* / ptr* )
305 296
 	,&loop JMP
306 297
 
307
-	&next-char-pop
298
+	&next-char-pop ( line^ last-ptr* ptr* char / start-of-token* )
308 299
 	POP
309
-	&next-char
310 300
 	INC2
311
-	&loop ( last-ptr* ptr* / start-of-token* )
312
-	OVR2 OVR2 LTH2 ,&end JCN
313
-	LDAk ( last-ptr* ptr* char / start-of-token* )
301
+	&loop ( line^ last-ptr* ptr* / start-of-token* )
302
+	LTH2k ,&end JCN
303
+	LDAk ( line^ last-ptr* ptr* char / start-of-token* )
314 304
 	DUP #20 GTH ,&next-char-pop JCN
315 305
 
316
-	#00 OVR2 ( last-ptr* ptr* char 00 ptr* / start-of-token* )
317
-	STA
318
-	STH2r ,asma-assemble-token JSR asma-IF-ERROR ,&error JCN
306
+	#00 OVR2 ( line^ last-ptr* ptr* char 00 ptr* / start-of-token* )
307
+	STA STH2r ( line^ last-ptr* ptr* char start-of-token* )
308
+	,asma-assemble-token JSR ( line^ last-ptr* ptr* char )
309
+	asma-IF-ERROR ,&error JCN
319 310
 
320
-	#0a NEQ ,&not-newline JCN
321
-	;asma/line LDA2 INC2 ;asma/line STA2
311
+	#0a NEQ ,&not-newline JCN ( line^ last-ptr* ptr* )
312
+	ROT2 INC2 ( last-ptr* ptr* line+1^ )
313
+	DUP2 ;asma/line STA2
314
+	ROT2 ROT2 ( line^ last-ptr* ptr* )
322 315
 	&not-newline
323 316
 
324
-	DUP2 INC2 STH2 ,&next-char JMP
317
+	INC2 DUP2 STH2 ( line^ last-ptr* ptr* / start-of-token* )
318
+	,&loop JMP
325 319
 
326 320
 	&end
327 321
 	POP2 POP2 STH2r