diff options
author | Eduardo Julian | 2017-06-06 20:23:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-06-06 20:23:15 -0400 |
commit | 4480e41e949ba3ba0c9bceeed43e3f144f82103b (patch) | |
tree | e31476d83b24a55746738c0b0b5100931ce289c3 /new-luxc/source/luxc/synthesizer/function.lux | |
parent | aa3dcb411db1bfbf41ca59c334c6c792b9e40d0c (diff) |
- Now optimizing functions.
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/synthesizer/function.lux | 55 |
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]))) |