summaryrefslogtreecommitdiff
path: root/sanctuary.fs
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-04-12 09:56:56 +1000
committerkitty <nepeta@canaglie.net>2026-04-12 09:56:56 +1000
commit8a0a5595ab3e8ab8cdcd36c24c6d22f85cdee00e (patch)
tree3c588c73e3239f218aa4f880cd631e327d7b15cd /sanctuary.fs
parent62adb1da98c0a2186367e2ffb4eb8791153e7267 (diff)
console input: it Works, ok
Diffstat (limited to 'sanctuary.fs')
-rw-r--r--sanctuary.fs118
1 files changed, 25 insertions, 93 deletions
diff --git a/sanctuary.fs b/sanctuary.fs
index 72dd439..6342227 100644
--- a/sanctuary.fs
+++ b/sanctuary.fs
@@ -10,6 +10,11 @@
: tuck swap over ;
: not 0= ;
+\ todo doc
+: / /mod nip ;
+: mod /mod drop ;
+: */ */mod nip ;
+: negate 0 swap - ;
: <mark here ;
: <resolve here 4 + - d, ;
@@ -28,6 +33,9 @@
: ?dup dup 0<> if dup then ;
: exit [ hex ] c3 c, [ decimal ] ; immediate compile-only
+\ todo doc
+: abs dup 0< if negate then ;
+
: allot dp +! ;
: ?find ?dup if find 0= if 2drop abort then else abort then ;
@@ -219,6 +227,21 @@ init-source value source-id
:noname sp-reset e." stack underflow" ecr abort ; is ?underflow?
\ }}}
+32 constant bl
+: space bl emit ;
+: spaces begin dup 0> while space 1- repeat drop ;
+
+\ NUMERIC OUTPUT {{{
+\ todo doc
+: (u.) <# #s #> ;
+: u. (u.) type space ;
+: u.r >r (u.) r> over - spaces type ;
+
+: (.) dup abs <# #s swap sign #> ;
+: . (.) type space ;
+: .r >r (.) r> over - spaces type ;
+\ }}}
+
\ if you need more than 16 layers of included files: go away™
\ todo doc
16 constant #buffers
@@ -291,98 +314,7 @@ privatise
0<> if true else false then ;
: quit 0 to source-id postpone [
- begin refill while interpret ( ." ok" cr ) repeat ;
-quit
-
-\ 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 ;
-\ }}}
+ begin refill while interpret ." ok" cr repeat ;
\ }}}
\ \ VOCABULARY {{{
@@ -398,4 +330,4 @@ quit
\ gonna need to be rewritten when/if i add vocabulary/wordlist support
\ : words ;
\ }}}
-bye
+quit bye