aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/synthesizer/function.lux
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source/luxc/synthesizer/function.lux')
-rw-r--r--new-luxc/source/luxc/synthesizer/function.lux55
1 files changed, 55 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])))