aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/base.lux
diff options
context:
space:
mode:
authorEduardo Julian2017-05-14 01:23:14 -0400
committerEduardo Julian2017-05-14 01:23:14 -0400
commit5cf1b36e5f6bb93e5faec49bd37d2aa6cb1b7d91 (patch)
tree33b4058b0c2ed4590bebf361142848cee5de7802 /new-luxc/source/luxc/base.lux
parent5690e2329296f63d55ba39d1d07218528d1cb984 (diff)
- WIP: Function analysis.
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/base.lux38
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))))