From 5cf1b36e5f6bb93e5faec49bd37d2aa6cb1b7d91 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 14 May 2017 01:23:14 -0400 Subject: - WIP: Function analysis. --- new-luxc/source/luxc/base.lux | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'new-luxc/source/luxc/base.lux') 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)))) -- cgit v1.2.3