diff options
author | Eduardo Julian | 2017-05-14 01:23:14 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-05-14 01:23:14 -0400 |
commit | 5cf1b36e5f6bb93e5faec49bd37d2aa6cb1b7d91 (patch) | |
tree | 33b4058b0c2ed4590bebf361142848cee5de7802 /new-luxc/source/luxc/base.lux | |
parent | 5690e2329296f63d55ba39d1d07218528d1cb984 (diff) |
- WIP: Function analysis.
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/base.lux | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/base.lux b/new-luxc/source/luxc/base.lux index 3a085e07e..74e316b3c 100644 --- a/new-luxc/source/luxc/base.lux +++ b/new-luxc/source/luxc/base.lux @@ -99,3 +99,41 @@ (#E;Success [compiler' output]) (#E;Success [(set@ #;source old-source compiler') output]))))) + +(def: #export (with-try handler action) + (All [a] (-> (-> Text (Lux a)) (Lux a) (Lux a))) + (function [compiler] + (case (action compiler) + (#E;Success [compiler' output]) + (#E;Success [compiler' output]) + + (#E;Error error) + ((handler error) compiler)))) + +(def: fresh-bindings + (All [k v] (Bindings k v)) + {#;counter +0 + #;mappings (list)}) + +(def: fresh-scope + Scope + {#;name (list) + #;inner +0 + #;locals fresh-bindings + #;captured fresh-bindings}) + +(def: #export (with-scope action) + (All [a] (-> (Lux a) (Lux [Scope a]))) + (function [compiler] + (case (action (update@ #;scopes (|>. (#;Cons fresh-scope)) compiler)) + (#E;Success [compiler' output]) + (case (get@ #;scopes compiler') + #;Nil + (#E;Error "Impossible error: Drained scopes!") + + (#;Cons head tail) + (#E;Success [(set@ #;scopes tail compiler') + [head output]])) + + (#E;Error error) + (#E;Error error)))) |