about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-23 00:45:35 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-23 00:45:35 -0800
commiteacb2ce45868c952346ae2efea64dc759e50488f (patch)
tree07b8e0baab1722f888d365e3cba6f16eb1f4cf29
parent7cd72da17c979d3b5f8662f5e5d7e10796f1c8e4 (diff)
downloadmu-eacb2ce45868c952346ae2efea64dc759e50488f.tar.gz
828 - interactive repl
Still klunky since mu has no notion of a return value. I find myself
using $print all the time.
-rwxr-xr-xmu24
-rw-r--r--mu.arc28
2 files changed, 36 insertions, 16 deletions
diff --git a/mu b/mu
index e2731406..858438b8 100755
--- a/mu
+++ b/mu
@@ -1,19 +1,27 @@
 #!/bin/bash
-# Run this from the mu directory.
 #
-# Wrapper to allow selectively running parts of the mu codebase/tests.
+# To run a program:
+#   $ mu [mu files]
+# To run a file of tests (in arc):
+#   $ mu test [arc files]
+# To start an interactive session:
+#   $ mu repl
 #
-# Usage:
-#  mu [mu files]
-#  mu test [arc files]
-#
-# To actually mess with load levels, skip this script and call load.arc
-# directly.
+# To mess with load levels and selectively run parts of the codebase, skip
+# this script and call load.arc directly.
 
 if [[ $1 == "test" ]]
 then
   shift
   ./anarki/arc load.arc "$@"  # test currently assumed to be arc files rather than mu files
+elif [[ $1 == "repl" ]]
+then
+  if [ "$(type rlwrap)" ]
+  then
+    rlwrap -C mu ./anarki/arc mu.arc
+  else
+    ./anarki/arc mu.arc
+  fi
 else
   ./anarki/arc load.arc mu.arc -- "$@"  # mu files from args
 fi
diff --git a/mu.arc b/mu.arc
index d5b15de3..1dbcb4ae 100644
--- a/mu.arc
+++ b/mu.arc
@@ -509,6 +509,7 @@
       (trace "run" label.routine* " " pc.routine* ": " (body.routine* pc.routine*))
 ;?       (trace "run" routine*)
       (when (atom (body.routine* pc.routine*))  ; label
+;?         (tr "label") ;? 1
         (when (aand scheduler-switch-table*
                     (alref it (body.routine* pc.routine*)))
           (++ pc.routine*)
@@ -517,6 +518,7 @@
         (++ pc.routine*)
         (continue))
       (let (oarg op arg)  (parse-instr (body.routine* pc.routine*))
+;?         (tr op) ;? 1
         (let results
               (case op
                 ; arithmetic
@@ -1714,6 +1716,15 @@
      (freeze-another ',name)
      (run-more ',name)))
 
+; repl
+(def run-interactive (stmt)
+  ; careful to avoid re-processing functions and adding noise to traces
+  (= function*!interactive (convert-labels:convert-braces:tokenize-args (list stmt)))
+  (add-next-space-generator function*!interactive 'interactive)
+  (= location*!interactive (assign-names-to-location function*!interactive 'interactive location*!interactive))
+  (replace-names-with-location function*!interactive 'interactive)
+  (run-more 'interactive))
+
 (def routine-that-ran (f)
   (find [some [is f _!fn-name] stack._]
         completed-routines*))
@@ -3037,17 +3048,13 @@
 (freeze system-function*)
 )  ; section 100 for system software
 
-;; load all provided files and start at 'main'
+;; initialization
+
 (reset)
 (awhen (pos "--" argv)
+  ; batch mode: load all provided files and start at 'main'
   (map add-code:readfile (cut argv (+ it 1)))
-;?   (= dump-trace* (obj whitelist '("run"))) ;? 1
-;?   (= dump-trace* (obj whitelist '("schedule")))
-;?   (= dump-trace* (obj whitelist '("run" "continuation"))) ;? 1
-;?   (= dump-trace* (obj whitelist '("cn0" "cn1")))
-;?   (set dump-trace*) ;? 7
-;?   (freeze function*)
-;?   (prn function*!factorial)
+;?   (set dump-trace*)
   (run 'main)
   (if ($.current-charterm) ($.close-charterm))
   (when ($.graphics-open?) ($.close-viewport Viewport) ($.close-graphics))
@@ -3060,5 +3067,10 @@
 ;?       (prn routine)
       ))
 )
+(when (no cdr.argv)
+  ; interactive mode
+  (whilet expr (do (pr "mu> ") (read))
+    (run-interactive expr)))
+
 (reset)
 ;? (print-times)