diff options
Diffstat (limited to 'stdlib/source/lux/language/compiler/translation.lux')
-rw-r--r-- | stdlib/source/lux/language/compiler/translation.lux | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/stdlib/source/lux/language/compiler/translation.lux b/stdlib/source/lux/language/compiler/translation.lux index 01dc584e6..077076d2f 100644 --- a/stdlib/source/lux/language/compiler/translation.lux +++ b/stdlib/source/lux/language/compiler/translation.lux @@ -11,8 +11,10 @@ [collection [row (#+ Row)] ["dict" dictionary (#+ Dictionary)]]] + [function] [world [file (#+ File)]]] - [// (#+ Operation Compiler)] + ["." // + [extension]] [//synthesis (#+ Synthesis)]) (do-template [<name>] @@ -47,8 +49,11 @@ #buffer (Maybe (Buffer code)) #artifacts (Artifacts code)}) -(type: #export (Translator anchor code) - (Compiler (State anchor code) Synthesis code)) +(type: #export (Operation anchor code) + (extension.Operation (State anchor code) Synthesis code)) + +(type: #export (Compiler anchor code) + (extension.Compiler (State anchor code) Synthesis code)) (def: #export (init host) (All [anchor code] (-> (Host code) (..State anchor code))) @@ -61,26 +66,23 @@ (def: #export (with-context expr) (All [anchor code output] - (-> (Operation (..State anchor code) output) - (Operation (..State anchor code) [Text output]))) - (function (_ state) + (-> (Operation anchor code output) + (Operation anchor code [Text output]))) + (function (_ [bundle state]) (let [[old-scope old-inner] (get@ #context state) new-scope (format old-scope "c___" (%i (.int old-inner)))] - (case (expr (set@ #context [new-scope +0] state)) - (#error.Success [state' output]) - (#error.Success [(set@ #context [old-scope (inc old-inner)] state') + (case (expr [bundle (set@ #context [new-scope +0] state)]) + (#error.Success [[bundle' state'] output]) + (#error.Success [[bundle' (set@ #context [old-scope (inc old-inner)] state')] [new-scope output]]) (#error.Error error) (#error.Error error))))) (def: #export context - (All [anchor code] (Operation (..State anchor code) Text)) - (function (_ state) - (#error.Success [state - (|> state - (get@ #context) - (get@ #scope-name))]))) + (All [anchor code] (Operation anchor code Text)) + (extension.read (|>> (get@ #context) + (get@ #scope-name)))) (do-template [<tag> <with-declaration> <with-type> <with-value> @@ -88,57 +90,56 @@ [(def: #export <with-declaration> (All [anchor code output] <with-type>) (function (_ body) - (function (_ state) - (case (body (set@ <tag> (#.Some <with-value>) state)) - (#error.Success [state' output]) - (#error.Success [(set@ <tag> (get@ <tag> state) state') + (function (_ [bundle state]) + (case (body [bundle (set@ <tag> (#.Some <with-value>) state)]) + (#error.Success [[bundle' state'] output]) + (#error.Success [[bundle' (set@ <tag> (get@ <tag> state) state')] output]) (#error.Error error) (#error.Error error))))) (def: #export <get> - (All [anchor code] (Operation (..State anchor code) <get-type>)) - (function (_ state) + (All [anchor code] (Operation anchor code <get-type>)) + (function (_ (^@ stateE [bundle state])) (case (get@ <tag> state) (#.Some output) - (#error.Success [state output]) + (#error.Success [stateE output]) #.None (ex.throw <exception> []))))] [#anchor (with-anchor anchor) - (-> anchor (Operation (..State anchor code) output) - (Operation (..State anchor code) output)) + (-> anchor (Operation anchor code output) + (Operation anchor code output)) anchor anchor anchor no-anchor] [#buffer with-buffer - (-> (Operation (..State anchor code) output) - (Operation (..State anchor code) output)) + (-> (Operation anchor code output) + (Operation anchor code output)) row.empty buffer (Buffer code) no-active-buffer] ) (def: #export artifacts (All [anchor code] - (Operation (..State anchor code) (Artifacts code))) - (function (_ state) - (#error.Success [state (get@ #artifacts state)]))) + (Operation anchor code (Artifacts code))) + (extension.read (get@ #artifacts))) (do-template [<name>] [(def: #export (<name> code) (All [anchor code] - (-> code (Operation (..State anchor code) Any))) - (function (_ state) + (-> code (Operation anchor code Any))) + (function (_ (^@ stateE [bundle state])) (case (:: (get@ #host state) <name> code) (#error.Error error) (ex.throw cannot-interpret error) (#error.Success output) - (#error.Success [state output]))))] + (#error.Success [stateE output]))))] [execute!] [evaluate!] @@ -146,20 +147,14 @@ (def: #export (save! name code) (All [anchor code] - (-> Ident code (Operation (..State anchor code) Any))) + (-> Ident code (Operation anchor code Any))) (do //.Monad<Operation> [_ (execute! code)] - (function (_ state) - (#error.Success [(update@ #buffer - (maybe/map (row.add [name code])) - state) - []])))) + (extension.update (update@ #buffer (maybe/map (row.add [name code])))))) (def: #export (save-buffer! target) (All [anchor code] - (-> File (Operation (..State anchor code) Any))) + (-> File (Operation anchor code Any))) (do //.Monad<Operation> [buffer ..buffer] - (function (_ state) - (#error.Success [(update@ #artifacts (dict.put target buffer) state) - []])))) + (extension.update (update@ #artifacts (dict.put target buffer))))) |