about summary refs log tree commit diff stats
path: root/lambda-to-mu.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-07-22 14:00:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-07-22 14:00:48 -0700
commitbe6e752626711047064fe176843972be5eaa2add (patch)
tree81048e7ccad554ece3d69806366e6c9ea0d9d28b /lambda-to-mu.mu
parent0c1ae52feb9ee7cc1858237d0c17da1cf863c2cc (diff)
downloadmu-be6e752626711047064fe176843972be5eaa2add.tar.gz
3124
Reorganize data structure for lambda cells. Create our first real unit
test for the compiler in the process.
Diffstat (limited to 'lambda-to-mu.mu')
-rw-r--r--lambda-to-mu.mu49
1 files changed, 28 insertions, 21 deletions
diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu
index 0ad61e51..4feb5ac9 100644
--- a/lambda-to-mu.mu
+++ b/lambda-to-mu.mu
@@ -10,51 +10,58 @@ result <- add a t1]
   ]
 ]
 
-container cell [
-  first:address:cell-value
-  rest:address:cell
+def lambda-to-mu in:address:array:character -> out:address:array:character [
+  local-scope
+  load-ingredients
+  out <- copy 0
+  tmp:address:cell <- parse in
+  out <- to-mu tmp
 ]
 
-exclusive-container cell-value [
+exclusive-container cell [
   atom:address:array:character
-  cell:address:cell
+  pair:pair
+]
+
+container pair [
+  first:address:cell
+  rest:address:cell
 ]
 
 def new-atom name:address:array:character -> result:address:cell [
   local-scope
   load-ingredients
-  cv:address:cell-value <- new cell-value:type
-  *cv <- merge 0/tag:atom, name
   result <- new cell:type
-  *result <- merge cv, 0/rest
+  *result <- merge 0/tag:atom, name
 ]
 
 def new-cell a:address:cell, b:address:cell -> result:address:cell [
   local-scope
   load-ingredients
-  cv:address:cell-value <- new cell-value:type
-  *cv <- merge 1/tag:cell, a
   result <- new cell:type
-  *result <- merge cv/first, b/rest
+  *result <- merge 1/tag:pair, a/first, b/rest
 ]
 
 def is-atom? x:address:cell -> result:boolean [
+  local-scope
+  load-ingredients
   reply-unless x, 0/false
-  cv:address:cell-value <- get *x, first:offset
-  reply-unless cv, 0/false
-  _, result <- maybe-convert *cv, atom:variant
+  _, result <- maybe-convert *x, atom:variant
 ]
 
 def is-cell? x:address:cell -> result:boolean [
+  local-scope
+  load-ingredients
   reply-unless x, 0/false
-  cv:address:cell-value <- get *x, first:offset
-  reply-unless cv, 0/false
-  _, result <- maybe-convert *cv, atom:variant
+  _, result <- maybe-convert *x, pair:variant
 ]
 
-def lambda-to-mu in:address:array:character -> out:address:array:character [
+scenario atom-operations [
   local-scope
-  load-ingredients
-  tmp <- parse in
-  out <- to-mu tmp
+  s:address:array:character <- new [a]
+  x:address:cell <- new-atom s
+  10:boolean/raw <- is-atom? x
+  memory-should-contain [
+    10 <- 1
+  ]
 ]