aboutsummaryrefslogtreecommitdiff
path: root/lux-r/source/luxc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lux-r/source/luxc/lang/host/r.lux (renamed from new-luxc/source/luxc/lang/host/r.lux)0
-rw-r--r--lux-r/source/luxc/lang/synthesis/variable.lux98
-rw-r--r--lux-r/source/luxc/lang/translation/r.lux (renamed from new-luxc/source/luxc/lang/translation/r.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/case.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/case.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/expression.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/expression.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/function.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/function.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/loop.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/loop.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/primitive.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/primitive.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/procedure/common.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/procedure/host.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/procedure/host.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/reference.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/reference.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/runtime.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/statement.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/statement.jvm.lux)0
-rw-r--r--lux-r/source/luxc/lang/translation/r/structure.jvm.lux (renamed from new-luxc/source/luxc/lang/translation/r/structure.jvm.lux)0
14 files changed, 98 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/host/r.lux b/lux-r/source/luxc/lang/host/r.lux
index 6e4c7fb5b..6e4c7fb5b 100644
--- a/new-luxc/source/luxc/lang/host/r.lux
+++ b/lux-r/source/luxc/lang/host/r.lux
diff --git a/lux-r/source/luxc/lang/synthesis/variable.lux b/lux-r/source/luxc/lang/synthesis/variable.lux
new file mode 100644
index 000000000..f6a45b02e
--- /dev/null
+++ b/lux-r/source/luxc/lang/synthesis/variable.lux
@@ -0,0 +1,98 @@
+(.module:
+ lux
+ (lux (data [number]
+ (coll [list "list/" Fold<List> Monoid<List>]
+ ["s" set])))
+ (luxc (lang ["la" analysis]
+ ["ls" synthesis]
+ [".L" variable #+ Variable])))
+
+(def: (bound-vars path)
+ (-> ls.Path (List Variable))
+ (case path
+ (#ls.BindP register)
+ (list (.int register))
+
+ (^or (#ls.SeqP pre post) (#ls.AltP pre post))
+ (list/compose (bound-vars pre) (bound-vars post))
+
+ _
+ (list)))
+
+(def: (path-bodies path)
+ (-> ls.Path (List ls.Synthesis))
+ (case path
+ (#ls.ExecP body)
+ (list body)
+
+ (#ls.SeqP pre post)
+ (path-bodies post)
+
+ (#ls.AltP pre post)
+ (list/compose (path-bodies pre) (path-bodies post))
+
+ _
+ (list)))
+
+(def: (non-arg? arity var)
+ (-> ls.Arity Variable Bit)
+ (and (variableL.local? var)
+ (n/> arity (.nat var))))
+
+(type: Tracker (s.Set Variable))
+
+(def: init-tracker Tracker (s.new number.Hash<Int>))
+
+(def: (unused-vars current-arity bound exprS)
+ (-> ls.Arity (List Variable) ls.Synthesis (List Variable))
+ (let [tracker (loop [exprS exprS
+ tracker (list/fold s.add init-tracker bound)]
+ (case exprS
+ (#ls.Variable var)
+ (if (non-arg? current-arity var)
+ (s.remove var tracker)
+ tracker)
+
+ (#ls.Variant tag last? memberS)
+ (recur memberS tracker)
+
+ (#ls.Tuple membersS)
+ (list/fold recur tracker membersS)
+
+ (#ls.Call funcS argsS)
+ (list/fold recur (recur funcS tracker) argsS)
+
+ (^or (#ls.Recur argsS)
+ (#ls.Procedure name argsS))
+ (list/fold recur tracker argsS)
+
+ (#ls.Let offset inputS outputS)
+ (|> tracker (recur inputS) (recur outputS))
+
+ (#ls.If testS thenS elseS)
+ (|> tracker (recur testS) (recur thenS) (recur elseS))
+
+ (#ls.Loop offset initsS bodyS)
+ (recur bodyS (list/fold recur tracker initsS))
+
+ (#ls.Case inputS outputPS)
+ (let [tracker' (list/fold s.add
+ (recur inputS tracker)
+ (bound-vars outputPS))]
+ (list/fold recur tracker' (path-bodies outputPS)))
+
+ (#ls.Function arity env bodyS)
+ (list/fold s.remove tracker env)
+
+ _
+ tracker
+ ))]
+ (s.to-list tracker)))
+
+## (def: (optimize-register-use current-arity [pathS bodyS])
+## (-> ls.Arity [ls.Path ls.Synthesis] [ls.Path ls.Synthesis])
+## (let [bound (bound-vars pathS)
+## unused (unused-vars current-arity bound bodyS)
+## adjusted (adjust-vars unused bound)]
+## [(|> pathS (clean-pattern adjusted) simplify-pattern)
+## (clean-expression adjusted bodyS)]))
diff --git a/new-luxc/source/luxc/lang/translation/r.lux b/lux-r/source/luxc/lang/translation/r.lux
index a4a3db1f5..a4a3db1f5 100644
--- a/new-luxc/source/luxc/lang/translation/r.lux
+++ b/lux-r/source/luxc/lang/translation/r.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/case.jvm.lux b/lux-r/source/luxc/lang/translation/r/case.jvm.lux
index 42460b620..42460b620 100644
--- a/new-luxc/source/luxc/lang/translation/r/case.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/case.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/expression.jvm.lux b/lux-r/source/luxc/lang/translation/r/expression.jvm.lux
index 3c41fbe63..3c41fbe63 100644
--- a/new-luxc/source/luxc/lang/translation/r/expression.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/expression.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/function.jvm.lux b/lux-r/source/luxc/lang/translation/r/function.jvm.lux
index f39a5e1a2..f39a5e1a2 100644
--- a/new-luxc/source/luxc/lang/translation/r/function.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/function.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/loop.jvm.lux b/lux-r/source/luxc/lang/translation/r/loop.jvm.lux
index f1197e5ce..f1197e5ce 100644
--- a/new-luxc/source/luxc/lang/translation/r/loop.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/loop.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/primitive.jvm.lux b/lux-r/source/luxc/lang/translation/r/primitive.jvm.lux
index 8bc7da848..8bc7da848 100644
--- a/new-luxc/source/luxc/lang/translation/r/primitive.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/primitive.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux b/lux-r/source/luxc/lang/translation/r/procedure/common.jvm.lux
index 85ccd90dc..85ccd90dc 100644
--- a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/procedure/common.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/procedure/host.jvm.lux b/lux-r/source/luxc/lang/translation/r/procedure/host.jvm.lux
index 3bd33955f..3bd33955f 100644
--- a/new-luxc/source/luxc/lang/translation/r/procedure/host.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/procedure/host.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/reference.jvm.lux b/lux-r/source/luxc/lang/translation/r/reference.jvm.lux
index 7de1c74ee..7de1c74ee 100644
--- a/new-luxc/source/luxc/lang/translation/r/reference.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/reference.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux b/lux-r/source/luxc/lang/translation/r/runtime.jvm.lux
index d641041d2..d641041d2 100644
--- a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/runtime.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/statement.jvm.lux b/lux-r/source/luxc/lang/translation/r/statement.jvm.lux
index 1798cb56d..1798cb56d 100644
--- a/new-luxc/source/luxc/lang/translation/r/statement.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/statement.jvm.lux
diff --git a/new-luxc/source/luxc/lang/translation/r/structure.jvm.lux b/lux-r/source/luxc/lang/translation/r/structure.jvm.lux
index cea8fcd59..cea8fcd59 100644
--- a/new-luxc/source/luxc/lang/translation/r/structure.jvm.lux
+++ b/lux-r/source/luxc/lang/translation/r/structure.jvm.lux