about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-01 16:34:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-11-01 16:34:33 -0700
commit002cbf13f181626ff5bc71f4d7269637ea0fdfea (patch)
treea1e99a25a2597894873b8e209e2101c7d7b0438a
parent2c9aa92f56c6f4051216774e9d10f795dd12bf0d (diff)
downloadmu-002cbf13f181626ff5bc71f4d7269637ea0fdfea.tar.gz
213 - bring back the fork example
-rw-r--r--Readme8
-rw-r--r--fork.mu18
-rw-r--r--mu.arc6
-rw-r--r--mu.arc.t12
4 files changed, 42 insertions, 2 deletions
diff --git a/Readme b/Readme
index 609cb911..167a0cb3 100644
--- a/Readme
+++ b/Readme
@@ -20,11 +20,19 @@ Now try a test program.
 Location z contains the sum of locations x and y.
 (You have to imagine that location 3 maps to 'z' for now, sorry..)
 
+Another example, this time with concurrency.
+
+  $ ./anarki/arc mu.arc fork.mu
+
+Notice that it repeatedly prints either '34' or '35' at random. Hit ctrl-c to
+stop.
+
 == Now dive in
 
 Try running the tests:
 
   $ ./anark/arc mu.arc.t
+  #t  # all tests passed!
 
 Now start reading mu.arc.t. The html rendering mu.arc.t.html might be easier
 to read in your browser.
diff --git a/fork.mu b/fork.mu
new file mode 100644
index 00000000..316aa98a
--- /dev/null
+++ b/fork.mu
@@ -0,0 +1,18 @@
+(main
+  (fork (thread2 fn))
+  ((default-scope scope-address) <- new (scope literal) (2 literal))
+  ((x integer) <- copy (34 literal))
+  { begin
+    (print-primitive (x integer))
+    (continue)
+  }
+)
+
+(thread2
+  ((default-scope scope-address) <- new (scope literal) (2 literal))
+  ((y integer) <- copy (35 literal))
+  { begin
+    (print-primitive (y integer))
+    (continue)
+  }
+)
diff --git a/mu.arc b/mu.arc
index 9005c9f9..8774b6bc 100644
--- a/mu.arc
+++ b/mu.arc
@@ -669,7 +669,7 @@
     instrs))
 
 (def maybe-add (arg offset idx)
-  (unless (or (in ty.arg 'literal 'offset)
+  (unless (or (in ty.arg 'literal 'offset 'fn)
               (offset v.arg)
               (~isa v.arg 'sym)
               (in v.arg 'nil 'default-scope)
@@ -767,4 +767,6 @@
   (map add-fns:readfile it)
   (run 'main)
   (if ($.current-charterm) ($.close-charterm))
-  (prn memory*))
+  (prn memory*)
+;?   (prn completed-routines*)
+)
diff --git a/mu.arc.t b/mu.arc.t
index 4fdabb56..002ecbcf 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1286,6 +1286,18 @@
             ((nil integer) <- add (1 integer) (2 integer))))
   (prn "F - convert-names never renames nil"))
 
+; kludgy support for 'fork'
+(reset)
+(new-trace "convert-names-functions")
+(if (~iso (convert-names
+            '(((x integer) <- copy (4 literal))
+              ((y integer) <- copy (2 literal))
+              ((z fn) <- add (x integer) (y integer))))
+          '(((1 integer) <- copy (4 literal))
+            ((2 integer) <- copy (2 literal))
+            ((z fn) <- add (1 integer) (2 integer))))
+  (prn "F - convert-names never renames nil"))
+
 ; A rudimentary memory allocator. Eventually we want to write this in mu.
 ;
 ; No deallocation yet; let's see how much code we can build in mu before we