about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-05 19:47:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-05 19:47:34 -0700
commit4caa718f6b28871acc858cb9e5de7e0c4a7cba0f (patch)
tree7c146b9d0288bd8deb076a393f750ef1cd845044 /cpp
parent9b7e00e79b0b68d704005ab1e149be53c4154b20 (diff)
downloadmu-4caa718f6b28871acc858cb9e5de7e0c4a7cba0f.tar.gz
1272
Diffstat (limited to 'cpp')
-rw-r--r--cpp/020run.cc2
-rw-r--r--cpp/counters.mu11
-rw-r--r--cpp/factorial.mu20
3 files changed, 19 insertions, 14 deletions
diff --git a/cpp/020run.cc b/cpp/020run.cc
index 10e463b6..ee0bbb61 100644
--- a/cpp/020run.cc
+++ b/cpp/020run.cc
@@ -109,7 +109,7 @@ if (!Run_tests) {
   recipe_number r = Recipe_number[string("main")];
 //?   Trace_stream->dump_layer = "all"; //? 1
   if (r) run(r);
-  dump_memory();
+//?   dump_memory(); //? 1
   teardown();
 }
 
diff --git a/cpp/counters.mu b/cpp/counters.mu
index 8cc9a437..4662b833 100644
--- a/cpp/counters.mu
+++ b/cpp/counters.mu
@@ -1,19 +1,22 @@
+# example program: maintain multiple counters with isolated lexical scopes
+# (spaces)
+
 recipe init-counter [
-  default-space:address:space <- new location:type, 30:literal
+  default-space:address:array:location <- new location:type, 30:literal
   n:integer <- next-ingredient
   reply default-space:address:space
 ]
 
 recipe increment-counter [
-  default-space:address:space <- new location:type, 30:literal
-  0:address:space/names:init-counter <- next-ingredient  # setup outer space; it *must* come from 'init-counter'
+  default-space:address:array:location <- new location:type, 30:literal
+  0:address:array:location/names:init-counter <- next-ingredient  # setup outer space; it *must* come from 'init-counter'
   x:integer <- next-ingredient
   n:integer/space:1 <- add n:integer/space:1, x:integer
   reply n:integer/space:1
 ]
 
 recipe main [
-  default-space:address:space <- new location:type, 30:literal
+  default-space:address:array:location <- new location:type, 30:literal
   # counter A
   a:address:space <- init-counter 34:literal
   # counter B
diff --git a/cpp/factorial.mu b/cpp/factorial.mu
index 08d8afee..0921a7e9 100644
--- a/cpp/factorial.mu
+++ b/cpp/factorial.mu
@@ -1,3 +1,13 @@
+# example program: compute the factorial of 7
+
+recipe main [
+  default-space:address:space <- new location:type, 30:literal
+  x:integer <- factorial 7:literal
+  $print x:integer
+  $print [
+]
+]
+
 recipe factorial [
   default-space:address:array:location <- new location:type, 30:literal
   n:integer <- next-ingredient
@@ -14,16 +24,8 @@ recipe factorial [
   reply result:integer
 ]
 
-recipe main [
-  default-space:address:space <- new location:type, 30:literal
-  x:integer <- factorial 7:literal
-  $print x:integer
-  $print [
-]
-]
-
+# unit test
 scenario factorial-test [
-#?   dump all #? 1
   run [
     1:integer <- factorial 5:literal
   ]