about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-07-22 11:04:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-07-22 11:04:42 -0700
commit57807016a794fd8e4195fba6a6a8115f56553ea2 (patch)
tree8a7c0605a395246407c3ae2951d7f8a488f8f784
parent8d72e5652147a0218f36757fd9171f3f2beda887 (diff)
downloadmu-57807016a794fd8e4195fba6a6a8115f56553ea2.tar.gz
3121 - very preliminary spike on a compiler
Nothing runs yet. Just spewing out code at this point, as a kind of
sketching.
-rw-r--r--lambda-to-mu.mu60
1 files changed, 60 insertions, 0 deletions
diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu
new file mode 100644
index 00000000..0ad61e51
--- /dev/null
+++ b/lambda-to-mu.mu
@@ -0,0 +1,60 @@
+scenario convert-dataflow [
+  run [
+    local-scope
+    1:address:array:character/raw <- lambda-to-mu [(add a (multiply b c))]
+    2:array:character/raw <- copy *1:address:array:character/raw
+  ]
+  memory-should-contain [
+    2:array:character <- [t1 <- multiply b c
+result <- add a t1]
+  ]
+]
+
+container cell [
+  first:address:cell-value
+  rest:address:cell
+]
+
+exclusive-container cell-value [
+  atom:address:array:character
+  cell: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
+]
+
+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
+]
+
+def is-atom? x:address:cell -> result:boolean [
+  reply-unless x, 0/false
+  cv:address:cell-value <- get *x, first:offset
+  reply-unless cv, 0/false
+  _, result <- maybe-convert *cv, atom:variant
+]
+
+def is-cell? x:address:cell -> result:boolean [
+  reply-unless x, 0/false
+  cv:address:cell-value <- get *x, first:offset
+  reply-unless cv, 0/false
+  _, result <- maybe-convert *cv, atom:variant
+]
+
+def lambda-to-mu in:address:array:character -> out:address:array:character [
+  local-scope
+  load-ingredients
+  tmp <- parse in
+  out <- to-mu tmp
+]