diff options
| author | kitty <nepeta@canaglie.net> | 2026-04-08 15:50:10 +1000 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-04-08 15:50:10 +1000 |
| commit | c883fe4b1c57be9025bdde00b61663ec10d3d593 (patch) | |
| tree | e1b510a2d74030d61fe7088adb0603924f1fd867 | |
| parent | 9f7f9d1e12db5c6299dd3db297dde1d36c6a5d06 (diff) | |
yeah i'm simplifying this shit
| -rw-r--r-- | sanctuary.fs | 179 |
1 files changed, 91 insertions, 88 deletions
diff --git a/sanctuary.fs b/sanctuary.fs index 80faf6b..e161e6e 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -205,94 +205,97 @@ false value nonaming -1 constant string-source init-source value source-id -8192 constant /buffer -5 constant /buffer-header -/buffer /buffer-header - constant /buffer-buffer -create base-buffer /buffer allot \ stdin input buffer -variable latest-buffer - -\ format: LINK LINEBUF-PTR >IN USED FD [BUFFER (8152B)] -: buf>line cell+ ; -: buf>in 2 cells + ; -: buf>used 3 cells + ; -: buf>fd 4 cells + ; -: buf>buf 5 cells + ; - -4096 constant /linebuf -2 constant /linebuf-header -/linebuf /linebuf-header - constant /linebuf-buffer -create base-linebuffer /linebuf allot -\ format >IN USED -: linebuf>used cell+ ; -: linebuf>buf 2 cells + ; - -base-linebuffer base-buffer buf>line ! -base-buffer latest-buffer ! - -\ todo doc -: create-linebuffer ( buf-a -- ) dup /linebuf ?allocate swap buf>line ! ; - -\ SEGFAULT HERE -: refill-buffer ( a -- u | 0 ) dup >r dup buf>fd @ swap ( fd a ) - dup buf>in 0 swap ! dup buf>used 0 swap ! - buf>buf swap >r /buffer-buffer r> read-file ( u e ) drop - r> ( u a ) buf>used ! ; -: create-buffer ( fd -- something? ) /buffer ?allocate ( fd a ) - dup latest-buffer @ swap ! dup buf>fd rot swap ! - dup refill-buffer 0= if abort then - dup create-linebuffer - latest-buffer ! ; -: free-buffer ( a -- ) dup @ >r - dup buf>line @ free free - r> latest-buffer ! ; - -: cbuffer->in latest-buffer @ buf>in ; -: cbuffer-used latest-buffer @ buf>used ; -: cbuffer-fd latest-buffer @ buf>fd ; -: cbuffer-line latest-buffer @ buf>line ; -: cbuffer-linebuf latest-buffer @ buf>line @ linebuf>buf ; - -: cbuffer-empty? cbuffer->in @ cbuffer-used @ >= ; - -: bufkey ( -- c | -1 ) - cbuffer-empty? if - latest-buffer @ refill-buffer 0= if -1 exit then - then - latest-buffer @ cbuffer->in @ + c@ - cbuffer->in @ 1+ cbuffer->in ! ; - -private{ -0 value #read -0 value #read-limit -0 value destination-base -: finish-accept ( -- u ) #read ; -}private -\ uses memory for readability, maybe too slow? -\ need to test to see. -: accept ( a u -- u ) 0 to #read to #read-limit to destination-base - begin - #read #read-limit < - while - bufkey dup 0>= over 10 <> or if - destination-base #read + c! - 1 +to #read - else - drop finish-accept exit - then - repeat - finish-accept ( only reached when buffer limit reached ) ; -privatise - -\ : _ s" stack underflow" type abort ; ' _ is !underflow -\ : _ s" stack overflow" type abort ; ' _ is !overflow -\ : _ s" word not found" type abort ; ' _ is !notfound - -: refill source-id 0< if false exit then - 0 >in ! cbuffer-linebuf tib ! cbuffer-linebuf /linebuf-buffer accept - dup #tib ! dup 0= if true else false then ; - -: quit 0 to source-id [compile] [ begin refill while interpret repeat ; -quit +: ." ; \ todo doc + +\ OLD VERSION I GAVE UP ON BECAUSE IT'S TOO COMPLICATED AND SUCKS SHIT {{{ +\ 8192 constant /buffer +\ 5 constant /buffer-header +\ /buffer /buffer-header - constant /buffer-buffer +\ create base-buffer /buffer allot \ stdin input buffer +\ variable latest-buffer +\ +\ \ format: LINK LINEBUF-PTR >IN USED FD [BUFFER (8152B)] +\ : buf>line cell+ ; +\ : buf>in 2 cells + ; +\ : buf>used 3 cells + ; +\ : buf>fd 4 cells + ; +\ : buf>buf 5 cells + ; +\ +\ 4096 constant /linebuf +\ 2 constant /linebuf-header +\ /linebuf /linebuf-header - constant /linebuf-buffer +\ create base-linebuffer /linebuf allot +\ \ format >IN USED +\ : linebuf>used cell+ ; +\ : linebuf>buf 2 cells + ; +\ +\ base-linebuffer base-buffer buf>line ! +\ base-buffer latest-buffer ! +\ +\ \ todo doc +\ : create-linebuffer ( buf-a -- ) dup /linebuf ?allocate swap buf>line ! ; +\ +\ \ SEGFAULT HERE +\ : refill-buffer ( a -- u | 0 ) dup >r dup buf>fd @ swap ( fd a ) +\ dup buf>in 0 swap ! dup buf>used 0 swap ! +\ buf>buf swap >r /buffer-buffer r> read-file ( u e ) drop +\ r> ( u a ) buf>used ! ; +\ : create-buffer ( fd -- something? ) /buffer ?allocate ( fd a ) +\ dup latest-buffer @ swap ! dup buf>fd rot swap ! +\ dup refill-buffer 0= if abort then +\ dup create-linebuffer +\ latest-buffer ! ; +\ : free-buffer ( a -- ) dup @ >r +\ dup buf>line @ free free +\ r> latest-buffer ! ; +\ +\ : cbuffer->in latest-buffer @ buf>in ; +\ : cbuffer-used latest-buffer @ buf>used ; +\ : cbuffer-fd latest-buffer @ buf>fd ; +\ : cbuffer-line latest-buffer @ buf>line ; +\ : cbuffer-linebuf latest-buffer @ buf>line @ linebuf>buf ; +\ +\ : cbuffer-empty? cbuffer->in @ cbuffer-used @ >= ; +\ +\ : bufkey ( -- c | -1 ) +\ cbuffer-empty? if +\ latest-buffer @ refill-buffer 0= if -1 exit then +\ then +\ latest-buffer @ cbuffer->in @ + c@ +\ cbuffer->in @ 1+ cbuffer->in ! ; +\ +\ private{ +\ 0 value #read +\ 0 value #read-limit +\ 0 value destination-base +\ : finish-accept ( -- u ) #read ; +\ }private +\ \ uses memory for readability, maybe too slow? +\ \ need to test to see. +\ : accept ( a u -- u ) 0 to #read to #read-limit to destination-base +\ begin +\ #read #read-limit < +\ while +\ bufkey dup 0>= over 10 <> or if +\ destination-base #read + c! +\ 1 +to #read +\ else +\ drop finish-accept exit +\ then +\ repeat +\ finish-accept ( only reached when buffer limit reached ) ; +\ privatise +\ +\ \ : _ s" stack underflow" type abort ; ' _ is !underflow +\ \ : _ s" stack overflow" type abort ; ' _ is !overflow +\ \ : _ s" word not found" type abort ; ' _ is !notfound +\ +\ : refill source-id 0< if false exit then +\ 0 >in ! cbuffer-linebuf tib ! cbuffer-linebuf /linebuf-buffer accept +\ dup #tib ! dup 0= if true else false then ; +\ +\ : quit 0 to source-id [compile] [ begin refill while interpret repeat ; +\ }}} \ }}} \ \ VOCABULARY {{{ |
