From ac50e330fbcc1f30c67a620da4a17d70752ebeef Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 17 Jul 2024 19:51:04 -0700 Subject: [PATCH] Made stdlib of some functions --- src/left.tal | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/left.tal b/src/left.tal index 7054388..28580ef 100644 --- a/src/left.tal +++ b/src/left.tal @@ -1040,7 +1040,7 @@ @file-reopen ( -- ) ;text - ;filepath DUP2 file-is-bin? ?file-open-binary + ;filepath DUP2 fbin? ?file-open-binary .File/name DEO2 #fff0 ;text SUB2 .File/length DEO2 ;text .File/read DEO2 @@ -1082,16 +1082,9 @@ #0a18 DEO JMP2r -@file-size ( path* -- size* ) - .File/name DEO2 - #0100 .File/length DEO2 - #ff00 .File/stat DEO2 - #00 #ff04 STA - #ff00 !shex - @file-inject ( name* -- ) - DUP2 file-is-bin? ?file-inject-binary - DUP2 file-size ORAk ?{ POP2 POP2 JMP2r } + DUP2 fbin? ?file-inject-binary + DUP2 flen ORAk ?{ POP2 POP2 JMP2r } STH2k .File/length DEO2 .File/name DEO2 ( | erase when selection length ) @@ -1102,7 +1095,7 @@ get-from STH2r ADD2 ! @file-inject-binary ( name* -- ) - get-from STH2k OVR2 file-size DUP2 ADD2 DUP2 #02 SFT2 ADD2 + get-from STH2k OVR2 flen DUP2 ADD2 DUP2 #02 SFT2 ADD2 .File/name DEO2 #0001 .File/length DEO2 STH2r inject-binary DUP2 get-from SUB2 ! @@ -1132,20 +1125,6 @@ &tal-ext ".tal $1 -@file-is-bin? ( path* -- bool ) - .File/name DEO2 - #0001 .File/length DEO2 - &s ( -- ) - ;&b feof? ?{ - [ LIT &b $1 ] ?&s - #01 JMP2r - !&s } - #00 JMP2r - -@feof? ( buf* -- eof ) - .File/read DEO2 - .File/success DEI2 #0000 EQU2 JMP2r - @inject-binary ( addr* -- addr* ) STH2 #0000 @@ -1596,6 +1575,27 @@ SUB [ LIT "a ] ADD JMP2r } POP [ LIT "0 ] ADD JMP2r +@flen ( path* -- size* ) + .File/name DEO2 + #0100 .File/length DEO2 + #ff00 .File/stat DEO2 + #00 #ff04 STA + #ff00 !shex + +@fbin? ( path* -- bool ) + .File/name DEO2 + #0001 .File/length DEO2 + &s ( -- ) + ;&b feof? ?{ + [ LIT &b $1 ] ?&s + #01 JMP2r + !&s } + #00 JMP2r + +@feof? ( buf* -- eof ) + .File/read DEO2 + .File/success DEI2 #0000 EQU2 JMP2r + @clab? ( c -- bool ) DUP LIT "0 SUB #0a LTH ?&ok DUP LIT "a SUB #1a LTH ?&ok