From a059eda0ecd73cbb6277da3bf64a550097bc346d Mon Sep 17 00:00:00 2001 From: kitty Date: Sun, 29 Mar 2026 20:23:28 +1100 Subject: DEFER-ed words in core, file open/read/write/close --- sanctuary.fs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sanctuary.fs') diff --git a/sanctuary.fs b/sanctuary.fs index 1aab4e2..e198710 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -74,6 +74,7 @@ decimal r> dup >resolve 4 + ( u a ) postpone literal ( a ) drop ; immediate compile-only : zstrlen dup begin dup c@ 0<> while 1+ repeat swap - ; +\ 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, ; \ PRIVATISATION AND HIDING {{{ @@ -126,6 +127,12 @@ 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 @@ -142,6 +149,11 @@ variable hld 0 constant r/o 1 constant w/o 2 constant r/w + +: open-file swap >r 0 r> sys-open >errno ; +: close-file sys-close ; +: read-file >r swap r> sys-read >errno ; +: write-file >r swap r> sys-write >errno ; \ }}} bye -- cgit v1.2.3