refactor the file a bit

This commit is contained in:
~d6 2022-04-10 02:05:09 -04:00
parent 88b3204c7e
commit e1a559d850
1 changed files with 80 additions and 69 deletions

149
femto.tal
View File

@ -7,7 +7,6 @@
( - dollar ($) and caret (^) regex bug ) ( - dollar ($) and caret (^) regex bug )
( - get long line truncation/scrolling working ) ( - get long line truncation/scrolling working )
( - allow line numbers to be toggled off ) ( - allow line numbers to be toggled off )
( - help text )
( - open file command? ) ( - open file command? )
( - close file command? ) ( - close file command? )
( - search&replace ) ( - search&replace )
@ -16,7 +15,7 @@
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
( MAX file size is currently #d000, i.e. 53248 bytes ) ( MAX file size is currently #ce80, i.e. 52864 bytes )
%dbg { #ff .System/debug DEO } %dbg { #ff .System/debug DEO }
%emit { .Console/write DEO } %emit { .Console/write DEO }
@ -167,11 +166,11 @@
( TODO: enable closing/opening files with editor already running ) ( TODO: enable closing/opening files with editor already running )
@open-file ( filename* -> ) @open-file ( filename* -> )
.File/name DEO2 .File/name DEO2
#d001 .File/length DEO2 #ce81 .File/length DEO2
;data .File/read DEO2 ;data .File/read DEO2
.File/success DEI2 #0000 EQU2 .state/modified STZ .File/success DEI2 #0000 EQU2 .state/modified STZ
.File/success DEI2 #d001 LTH2 ,&ok JCN .File/success DEI2 #ce81 LTH2 ,&ok JCN
;messages/input-error ;print JSR2 ;messages/input-error ;print JSR2
;filename ;print JSR2 nl quit! ;filename ;print JSR2 nl quit!
@ -655,6 +654,14 @@
@move-to-message-line ( -> ) @move-to-message-line ( -> )
#0000 .term/rows LDZ2 #0002 ADD2 ;term-move-cursor JMP2 #0000 .term/rows LDZ2 #0002 ADD2 ;term-move-cursor JMP2
( COMPLETION )
@is-space ( c^ -> bool^ )
DUP #21 LTH SWP #7e GTH ORA JMP2r
@non-space ( c^ -> bool^ )
,is-space JSR #00 EQU JMP2r
( start a prompt on the message line ) ( start a prompt on the message line )
( ) ( )
( the arguments are as follows: ) ( the arguments are as follows: )
@ -670,8 +677,7 @@
#01 .prompt/active STZ ( prompt/active <- 1 ) #01 .prompt/active STZ ( prompt/active <- 1 )
.prompt/vector STZ2 ( prompt/vector <- vector ) .prompt/vector STZ2 ( prompt/vector <- vector )
DUP2 ;tmp/data ;str-copy JSR2 ( tmp/data <- default ) DUP2 ;tmp/data ;str-copy JSR2 ( tmp/data <- default )
;str-len JSR2 ;tmp/data ADD2 ( len(default)+data ) ;tmp/data ADD2 .tmp/pos STZ2 ( tmp/pos <- len(default)+data )
.tmp/pos STZ2 ( tmp/pos <- len(default)+data )
.prompt/string STZ2 ( prompt/string <- prompt ) .prompt/string STZ2 ( prompt/string <- prompt )
JMP2r JMP2r
&is-active &is-active
@ -711,7 +717,7 @@
;messages/save-failed ,&finish JMP ;messages/save-failed ,&finish JMP
&ok &ok
#00 .state/modified STZ #00 .state/modified STZ
;tmp/data ;filename ;str-copy JSR2 ;tmp/data ;filename ;str-copy JSR2 POP2
;messages/save-ok ;messages/save-ok
&finish &finish
;tmp/data ;send-message JSR2 ;tmp/data ;send-message JSR2
@ -1092,43 +1098,6 @@
@min2 ( x* y* -> min* ) @min2 ( x* y* -> min* )
LTH2k JMP SWP2 POP2 JMP2r LTH2k JMP SWP2 POP2 JMP2r
( ANSI terminal notes )
( )
( attrs [0-7] )
( reset, bright, dim, underscore, )
( blink, ???, reverse, hidden )
( )
( fg [30-37], bg [40-47] )
( black, red, green, yellow, )
( blue, magenta, cyan, white )
( ANSI control sequence to move the cursor to the given coord )
( ESC [ $row ; $col H )
@term-move-cursor ( col* row* -> )
ansi INC2 ( row+1 ) ;emit-dec2 JSR2
emit-; INC2 ( col+1 ) ;emit-dec2 JSR2
emit-H JMP2r
( ANSI control sequence to move N positions right )
( ESC [ $n C )
@term-move-right ( n* -> )
ansi ;emit-dec2 JSR2 emit-C JMP2r
( ANSI control sequence to get the cursor position )
( ESC [ 6 n )
@term-get-cursor-position ( -> )
ansi emit-6 emit-n JMP2r
( ANSI control sequence to erase entire screen )
( ESC [ 2 J )
@term-erase-all ( -> )
ansi emit-2 emit-J JMP2r
( ANSI control sequence to erase the current line )
( ESC [ 2 K )
@term-erase-line ( -> )
ansi emit-2 emit-K JMP2r
( method to add bits to the redraw register ) ( method to add bits to the redraw register )
( ) ( )
( state/redraw uses 8 bits to represent which parts ) ( state/redraw uses 8 bits to represent which parts )
@ -1142,12 +1111,12 @@
( ) ( )
( these don't perform a redraw right away, but instead ) ( these don't perform a redraw right away, but instead )
( signal that the next drawing should include that part. ) ( signal that the next drawing should include that part. )
@redraw-cursor ( -> ) #01 ;redraw-add JMP2 @redraw-cursor ( -> ) #01 ,redraw-add JMP
@redraw-statusbar ( -> ) #02 ;redraw-add JMP2 @redraw-statusbar ( -> ) #02 ,redraw-add JMP
@redraw-statusbar-and-cursor ( -> ) #03 ;redraw-add JMP2 @redraw-statusbar-and-cursor ( -> ) #03 ,redraw-add JMP
@redraw-prompt-and-cursor ( -> ) #05 ;redraw-add JMP2 @redraw-prompt-and-cursor ( -> ) #05 ,redraw-add JMP
@redraw-matches ( -> ) #08 ;redraw-add JMP2 @redraw-matches ( -> ) #08 ,redraw-add JMP
@redraw-all ( -> ) #1f ;redraw-add JMP2 @redraw-all ( -> ) #1f ,redraw-add JMP
( draw the current cursor location ) ( draw the current cursor location )
@draw-cursor ( -> ) @draw-cursor ( -> )
@ -1218,9 +1187,9 @@
@draw-linenum ( n* -> ) @draw-linenum ( n* -> )
;emit-reset JSR2 ;emit-reset JSR2
ansi .config/color LDZ2 emit emit emit-m ;emit-color JSR2
;emit-dec2-pad JSR2 sp ;emit-dec2-pad JSR2 sp
ansi emit-0 emit-m JMP2r ;emit-reset JMP2
@matches-at ( s* -> limit* ) @matches-at ( s* -> limit* )
LIT2r :tmp/data LIT2r :tmp/data
@ -1317,27 +1286,74 @@
&loop ORAk ,&next JCN POP2 POP2r JMP2r &loop ORAk ,&next JCN POP2 POP2r JMP2r
&next DEOkr INC2 ,&loop JMP &next DEOkr INC2 ,&loop JMP
( ESC [ 1 m )
( ANSI terminal notes )
( )
( attrs [0-7] )
( reset, bright, dim, underscore, )
( blink, ???, reverse, hidden )
( )
( fg [30-37], bg [40-47] )
( black, red, green, yellow, )
( blue, magenta, cyan, white )
( ANSI control sequence to move the cursor to the given coord )
( ESC [ $row ; $col H )
@term-move-cursor ( col* row* -> )
ansi INC2 ( row+1 ) ;emit-dec2 JSR2
emit-; INC2 ( col+1 ) ;emit-dec2 JSR2
emit-H JMP2r
( ANSI control sequence to move N positions right )
( ESC [ $n C )
@term-move-right ( n* -> )
ansi ;emit-dec2 JSR2 emit-C JMP2r
( ANSI control sequence to get the cursor position )
( ESC [ 6 n )
@term-get-cursor-position ( -> )
LIT2 00 'n LIT '6 ,ansi-emit JMP
( ANSI control sequence to erase entire screen )
( ESC [ 2 J )
@term-erase-all ( -> )
LIT2 00 'J LIT '2 ,ansi-emit JMP
( ANSI control sequence to erase the current line )
( ESC [ 2 K )
@term-erase-line ( -> )
LIT2 00 'K LIT '2 ,ansi-emit JMP
@ansi-emit ( 00 cn ... c1 c0 -> )
LITr 18 ( Console/write )
#5b1b STHkr DEO STHkr DEO ( ESC [ )
&loop LDA DUP ,&next JCN POP POPr JMP2r
&next STHkr DEO ,&loop JMP
( ESC [ 3 1 m )
@emit-red ( -> ) @emit-red ( -> )
ansi emit-3 emit-1 emit-m JMP2r LIT2 00 'm LIT2 '1 '3 ,ansi-emit JMP
( ESC [ 0 m ) ( ESC [ 0 m )
@emit-reset ( -> ) @emit-reset ( -> )
ansi emit-0 emit-m JMP2r #00 LIT2 'm '0 ,ansi-emit JMP
( ESC [ 1 m $ ESC [ 0 m ) ( ESC [ 1 m $ ESC [ 0 m )
@emit-red-dollar ( -> ) @emit-red-dollar ( -> )
;emit-red JSR2 emit-$ ;emit-reset JMP2 ,emit-red JSR emit-$ ,emit-reset JMP2
( ESC [ 3 $x ; 7 m ) ( ESC [ 3 $x ; 7 m )
( $x is 0-7 ) ( $x is 0-7 )
@emit-color-reverse ( -> ) @emit-color-reverse ( -> )
ansi .config/color LDZ2 emit emit emit-; emit-7 emit-m JMP2r LIT2 00 'm LIT2 '7 '; .config/color LDZ2 ,ansi-emit JMP
@emit-color ( -> )
LIT2 00 'm .config/color LDZ2 ,ansi-emit JMP
( ESC [ 3 $x ; 1 m ) ( ESC [ 3 $x ; 1 m )
( $x is 0-7 ) ( $x is 0-7 )
@emit-color-bold ( -> ) @emit-color-bold ( -> )
ansi .config/color LDZ2 emit emit emit-; emit-1 emit-m JMP2r LIT2 00 'm LIT2 '1 '; .config/color LDZ2 ,ansi-emit JMP
@draw-all ( -> ) @draw-all ( -> )
;term-erase-all JSR2 ;term-erase-all JSR2
@ -1393,19 +1409,14 @@
&draw-all ;draw-all JSR2 &draw-all ;draw-all JSR2
&finish POP #00 .state/redraw STZ BRK &finish POP #00 .state/redraw STZ BRK
@str-copy ( src* dst* -> ) @str-copy ( src* dst* -> len* )
STH2 ( src [dst] ) STH2 DUP2 ( src src [dst] )
&loop LDAk #00 EQU ,&done JCN &loop LDAk #00 EQU ,&done JCN
LDAk STH2kr STA LDAk STH2kr STA
INC2 INC2r ,&loop JMP INC2 INC2r ,&loop JMP
&done POP2 #00 STH2r STA &done ( src src+n [dst+n] )
JMP2r SWP2 SUB2
#00 STH2r STA
@str-len ( s* -> n* )
LIT2r 0000
&loop LDAk #00 EQU ,&done JCN
INC2 INC2r ,&loop JMP
&done POP2 STH2r
JMP2r JMP2r
@print ( s* -> ) @print ( s* -> )
@ -1660,6 +1671,6 @@
] ]
( actual file data to be edited ) ( actual file data to be edited )
@data $d000 @data $ce80
( end of femto.tal ) ( end of femto.tal )