aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/synthesizer
diff options
context:
space:
mode:
authorEduardo Julian2017-06-06 20:23:15 -0400
committerEduardo Julian2017-06-06 20:23:15 -0400
commit4480e41e949ba3ba0c9bceeed43e3f144f82103b (patch)
treee31476d83b24a55746738c0b0b5100931ce289c3 /new-luxc/source/luxc/synthesizer
parentaa3dcb411db1bfbf41ca59c334c6c792b9e40d0c (diff)
- Now optimizing functions.
Diffstat (limited to 'new-luxc/source/luxc/synthesizer')
-rw-r--r--new-luxc/source/luxc/synthesizer/function.lux55
-rw-r--r--new-luxc/source/luxc/synthesizer/structure.lux28
2 files changed, 83 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/synthesizer/function.lux b/new-luxc/source/luxc/synthesizer/function.lux
new file mode 100644
index 000000000..be6a74da0
--- /dev/null
+++ b/new-luxc/source/luxc/synthesizer/function.lux
@@ -0,0 +1,55 @@
+(;module:
+ lux
+ (lux (data (coll [list "L/" Functor<List> Fold<List>])))
+ (luxc (lang ["la" analysis]
+ ["ls" synthesis])))
+
+(def: #export (environment scope)
+ (-> Scope (List ls;Variable))
+ (|> scope
+ (get@ [#;captured #;mappings])
+ (L/map (function [[_ _ ref]]
+ (case ref
+ (#;Local idx)
+ (nat-to-int idx)
+
+ (#;Captured idx)
+ (|> idx n.inc nat-to-int (i.* -1))
+ )))))
+
+(do-template [<name> <comp>]
+ [(def: #export (<name> var)
+ (-> ls;Variable Bool)
+ (<comp> 0 var))]
+
+ [function-var? i.=]
+ [local-var? i.>]
+ [captured-var? i.<]
+ )
+
+(def: #export (nested-function? scope-args)
+ (-> Nat Bool)
+ (n.> +1 scope-args))
+
+(def: #export (adjust-var scope-args var)
+ (-> Nat ls;Variable ls;Variable)
+ (|> scope-args n.dec nat-to-int (i.+ var)))
+
+(def: #export (to-captured idx)
+ (-> Nat Int)
+ (|> idx n.inc nat-to-int (i.* -1)))
+
+(def: #export (to-local idx)
+ (-> Nat Int)
+ (nat-to-int idx))
+
+(def: #export (unfold-apply apply)
+ (-> la;Analysis [la;Analysis (List la;Analysis)])
+ (loop [apply apply
+ args (list)]
+ (case apply
+ (#la;Apply arg func)
+ (recur func (#;Cons arg args))
+
+ _
+ [apply args])))
diff --git a/new-luxc/source/luxc/synthesizer/structure.lux b/new-luxc/source/luxc/synthesizer/structure.lux
new file mode 100644
index 000000000..403817c53
--- /dev/null
+++ b/new-luxc/source/luxc/synthesizer/structure.lux
@@ -0,0 +1,28 @@
+(;module:
+ lux
+ (luxc (lang ["la" analysis])))
+
+(def: #export (unfold-tuple tuple)
+ (-> la;Analysis (List la;Analysis))
+ (case tuple
+ (#la;Product left right)
+ (#;Cons left (unfold-tuple right))
+
+ _
+ (list tuple)))
+
+(def: #export (unfold-variant variant)
+ (-> (Either la;Analysis la;Analysis) [Nat Bool la;Analysis])
+ (loop [so-far +0
+ variantA variant]
+ (case variantA
+ (#;Left valueA)
+ (case valueA
+ (#la;Sum choice)
+ (recur (n.inc so-far) choice)
+
+ _
+ [so-far false valueA])
+
+ (#;Right valueA)
+ [(n.inc so-far) true valueA])))