summaryrefslogtreecommitdiff
path: root/sanctuary.fs
diff options
context:
space:
mode:
Diffstat (limited to 'sanctuary.fs')
-rw-r--r--sanctuary.fs40
1 files changed, 33 insertions, 7 deletions
diff --git a/sanctuary.fs b/sanctuary.fs
index e198710..0199296 100644
--- a/sanctuary.fs
+++ b/sanctuary.fs
@@ -77,6 +77,21 @@ decimal
\ todo s>z becomes s>z, s>z writes to pad (will then need to be moved below pno)
: s>z here -rot cmove, 0 c, ;
+\ DEFER {{{
+\ todo doc
+\ : defer create ['] abort , does> @ execute ;
+\ : create parse-name (header) latest ! ['] (create) compile, 0 , ;
+\ : does> latest @ >body 2 + ['] (does>) over ! \ replace call loc
+\ ( replace destination ) 11 + r> swap ! ;
+\ todo ['] abort → ['] ?defer or something (where ?defer yields an appropriate error)
+: defer parse-name (header) latest !
+ ['] (defer) compile, ['] abort , ( sic ) ;
+: >defer ( ht -- a ) 13 + ;
+: defer@ >defer @ ;
+: defer! >defer ! ;
+: is state @ if postpone ['] postpone defer! else ' defer! then ; immediate
+\ }}}
+
\ PRIVATISATION AND HIDING {{{
\ maybe i add locals later, implementation may be complex though. this isn't.
\ privatise just loops through words from the start of privatisation
@@ -97,7 +112,17 @@ variable private0 variable private$
0 private0 ! 0 private$ ! ;
\ }}}
-\ MMAP {{{
+\ ERRNO {{{
+\ CONSTANTS {{{
+-11 constant EAGAIN -12 constant ENOMEM -13 constant EACCES
+-22 constant EINVAL -25 constant ENOTTY
+\ }}}
+\ transform syscall result into [RESULT] IOR output,
+\ where IOR is zero on no error and negative on an error (RESULT then being 0)
+: >errno dup 0< if 0 swap else 0 then ;
+\ }}}
+
+\ DYNAMIC ALLOCATION (MMAP) {{{
\ MMAP CONSTANTS {{{
hex
\ prot
@@ -110,6 +135,13 @@ decimal
: mmap 9 syscall6 ;
: munmap 11 syscall2 ;
+
+: allocate ( u -- a e ) >r 0 -1 ( offset fd , unused here )
+ MAP_PRIVATE MAP_ANONYMOUS or ( flags )
+ PROT_READ PROT_WRITE or ( prot )
+ r> 0 ( length addr )
+ mmap >errno ;
+: free ( a u -- e ) swap munmap ;
\ }}}
\ NUMERIC OUTPUT {{{
@@ -127,12 +159,6 @@ variable hld
: #> drop hld @ pad$ over - ;
\ }}}
-\ ERRNO {{{
-\ transform syscall result into [RESULT] IOR output,
-\ where IOR is zero on no error and negative on an error (RESULT then being 0)
-: >errno dup 0< if 0 swap else 0 then ;
-\ }}}
-
\ I/O {{{
0 constant stdin
1 constant stdout