1c9a7fc45258 — Leonard Ritter 28 days ago
* improved interpreter docs
3 files changed, 55 insertions(+), 20 deletions(-)

M lib/tukan/uvm.sc
M testing/test_echo.tuk
M testing/tuk_interpreter.sc
M lib/tukan/uvm.sc +26 -8
@@ 1301,7 1301,7 @@ sugar uquote (expr...)
 let builtins global-env =
     fold (scope env = (Scope) (Cell)) for name in
         sugar-quote + - * / let fn quote set get nextindex _ == != not all
-            \ any dump totext .. cond
+            \ any dump totext .. cond setmeta getmeta
         sym := (Atom (name as Symbol))
         code := ('hashbits sym)
         _

          
@@ 1516,14 1516,9 @@ fn... ueval (env : Atom, expr : Atom)
                 if (all-kinds? Atom.Kind.Cell source)
                     source as:= Cell
                     let key = ('get-index args 1)
-                    let value = ('get-index args 2)
                     if (any-kinds? Atom.Kind.None key) (Atom)
                     else
-                        let result = ('get source key)
-                        if ('none? result)
-                            value
-                        else
-                            result
+                        'get source key
                 else
                     if (not (any-none? source))
                         errormsg "cell expected, got " (kindstrs source)

          
@@ 1576,8 1571,31 @@ fn... ueval (env : Atom, expr : Atom)
             case builtins.not (eval-not)
             # (set table key value)
             case builtins.set (eval-set)
-            # (get table key default)
+            # (get table key)
             case builtins.get (eval-get)
+            case builtins.setmeta
+                let source = ('get-index args 0)
+                let meta = ('get-index args 1)
+                if (all-kinds? Atom.Kind.Cell source meta)
+                    let _source = source
+                    source as:= Cell
+                    Atom ('set-meta source meta)
+                else
+                    if (not (any-none? source))
+                        errormsg "cell expected, got " (kindstrs source)
+                    elseif (not (any-none? meta))
+                        errormsg "meta cell expected, got " (kindstrs source)
+                    (Atom)
+            case builtins.getmeta
+                let source = ('get-index args 0)
+                if (all-kinds? Atom.Kind.Cell source)
+                    let _source = source
+                    source as:= Cell
+                    copy ('get-meta source)
+                else
+                    if (not (any-none? source))
+                        errormsg "cell expected, got " (kindstrs source)
+                    (Atom)
             # (countof table)
             case builtins.nextindex (eval-countof)
             case builtins._

          
M testing/test_echo.tuk +8 -1
@@ 1,6 1,13 @@ 
 : exit?
     == "\n" (get io 'readline)
-: state (get io 'state (_ (: index 0)))
+: state
+    any
+        get io 'state
+        setmeta
+            _
+                : index 0
+            _
+                : class "state"
 cond (any exit? false)
     _
         : exit 0

          
M testing/tuk_interpreter.sc +21 -11
@@ 20,15 20,12 @@ struct Options
 
 fn run (argc argv program opts)
     #
+        BASIC
+        =====
+
         inputs:
             setup : ?
                 sent for the first frame of the application.
-            readline : text
-                sent after a `prompt` request.
-            break : ?
-                sent when the user presses Ctrl+D on the prompt. if the program
-                doesn't subsequently set `block-break`, it is aborted with
-                error code 255.
             state : ?
                 as set by `state`. When previously saved to disk, it will be
                 provided along with `setup`.

          
@@ 36,6 33,24 @@ fn run (argc argv program opts)
         outputs:
             exit : number
                 when set, exits the program with the provided errorcode.
+            state : ?
+                when set, is feedback as `state`. the application can maintain
+                stateful variables this way and simulate mutation. if provided
+                after receiving a `break` or when sending an `exit`, its contents
+                 will be serialized to disk.
+
+        Console
+        =======
+
+        inputs:
+            readline : text
+                sent after a `prompt` request.
+            break : ?
+                sent when the user presses Ctrl+D on the prompt. if the program
+                doesn't subsequently set `block-break`, it is aborted with
+                error code 255.
+
+        outputs:
             prompt : text
                 when set, sends a prompt to the user and sends the users input
                 via `readline` back into the program. if the user presses

          
@@ 43,11 58,6 @@ fn run (argc argv program opts)
             block-break : ?
                 if set in a frame where `break` is set, prevents the break from
                 prompt to be executed.
-            state : ?
-                when set, is feedback as `state`. the application can maintain
-                stateful variables this way and simulate mutation. if provided
-                after receiving a `break` or when sending an `exit`, its contents
-                 will be serialized to disk.
             stdout : text
                 when set, prints text to stdout.