ref: 3559ce237b055bff14861549b29ca4cdf8707221
parent: 84b7df170ff07aa5b082570c996e37caedb5caa9
author: 9ferno <gophone2015@gmail.com>
date: Tue Feb 15 23:12:17 EST 2022
working ns from forth
--- /dev/null
+++ b/forth/helpers.f
@@ -1,0 +1,32 @@
+
+\ from http://www.forth.org/forth_coding.html
+\ ignore until ) from the input stream during compilation (R -- )
+\ : (R [char] ) parse drop ; immediate
+: (R closeparen drop ; immediate
+
+\ Glossary Text: All words shall be accompanied by clear, concise explanatory text in the form of
+\ a glossary text entry, which may be extracted later by automated tools that aid in the
+\ generation of user documentation. Glossary text shall refer to the declared stack effects
+\ of a word, if any, and declare any exceptions that might be generated by the function for
+\ non-valid parameters.
+\ ignore until ) from the input stream during compilation (G is the glossary text entry comment. )
+: (G closeparen drop ; immediate
+
+hex
+003 constant MORDER \ #define MORDER 0x0003 /* mask for bits defining order of mounting */
+000 constant MREPL \ #define MREPL 0x0000 /* mount replaces object */
+001 constant MBEFORE \ #define MBEFORE 0x0001 /* mount goes before others in union directory */
+002 constant MAFTER \ #define MAFTER 0x0002 /* mount goes after others in union directory */
+004 constant MCREATE \ #define MCREATE 0x0004 /* permit creation in mounted directory */
+010 constant MCACHE \ #define MCACHE 0x0010 /* cache some data */
+017 constant MMASK \ #define MMASK 0x0017 /* all bits on */
+decimal
+
+: bind ( 'cs_new 'cs_old flags -- ) \ cs = counted string
+ >r count cstring1 >r count cstring0 r> r> sysbind ;
+
+: sbind ( 'new nnew 'old nold flags -- )
+ >r >r >r \ ( 'new nnew ) (R flags nold 'old )
+ cstring0 \ ( 'padtext-new ) (R flags nold 'old )
+ r> r> cstring1 \ ( 'padtext_new 'padtext_old ) (R flags )
+ r> sysbind ;
--- /dev/null
+++ b/forth/ns.f
@@ -1,0 +1,17 @@
+: ioerror ( n -- ) ." ioerror: " . cr ;
+
+: show ( read_count -- )
+ dup 0 < if ioerror then
+ pad swap ( 'pad read_count ) type ;
+
+: untileof ( fd -- fd )
+ begin
+ dup pad 1024 sysread ( fd read_count )
+ ?dup while show ( fd )
+ repeat ;
+
+: ns s" #p/1/ns" cstring0 r/o sysopen ( fd )
+ dup -1 > ( fd fd>=0? )
+ if ( fd ) untileof sysclose drop
+ else ." open error: " .
+ then ;
--- /dev/null
+++ b/init.f
@@ -1,0 +1,19 @@
+include /forth/helpers.f
+
+1 2 + 3 + 4 + 5 + .
+: first 1 2 + 3 + . ;
+
+first
+
+include /forth/ns.f
+" ns before" type cr
+ns
+
+" #l0" " /net" MAFTER sbind
+" #I0" " /net" MAFTER sbind
+
+" ns after" type cr
+ns
+
+
+" end of init.f" type cr