aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/compiler/default.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/compiler/default.lux')
-rw-r--r--stdlib/source/lux/compiler/default.lux58
1 files changed, 35 insertions, 23 deletions
diff --git a/stdlib/source/lux/compiler/default.lux b/stdlib/source/lux/compiler/default.lux
index 16c1a2b0e..73b018c95 100644
--- a/stdlib/source/lux/compiler/default.lux
+++ b/stdlib/source/lux/compiler/default.lux
@@ -5,7 +5,7 @@
["ex" exception (#+ exception:)]]
[data
["." product]
- ["." error]
+ ["." error (#+ Error)]
[text ("text/." Hash<Text>)
format
["." encoding]]
@@ -36,12 +36,20 @@
## [cache/io])
)
-(def: #export prelude Text "lux")
+(type: Reader
+ (-> .Source (Error [.Source Code])))
-(def: (read current-module aliases)
- (-> Text Aliases (analysis.Operation Code))
+(def: (reader current-module aliases)
+ (-> Text Aliases (analysis.Operation Reader))
+ (function (_ [bundle state])
+ (let [[cursor offset source-code] (get@ #.source state)]
+ (#error.Success [[bundle state]
+ (syntax.parse current-module aliases ("lux text size" source-code))]))))
+
+(def: (read reader)
+ (-> Reader (analysis.Operation Code))
(function (_ [bundle compiler])
- (case (syntax.read current-module aliases (get@ #.source compiler))
+ (case (reader (get@ #.source compiler))
(#error.Error error)
(#error.Error error)
@@ -88,26 +96,30 @@
(|>> module.set-compiled
statement.lift-analysis))
- (def: (loop-module-compilation module-name)
+ (def: (module-compilation-iteration reader)
+ (-> Reader (All [anchor expression statement] <Operation>))
+ (<| (phase.timed (name-of ..module-compilation-iteration) "ITERATION")
+ (do phase.Monad<Operation>
+ [code (statement.lift-analysis
+ (do @
+ [code (<| (phase.timed (name-of ..module-compilation-iteration) "syntax")
+ (..read reader))
+ #let [[cursor _] code]
+ _ (analysis.set-cursor cursor)]
+ (wrap code)))
+ _ (<| (phase.timed (name-of ..module-compilation-iteration) "PHASE")
+ (totalS.phase code))]
+ init.refresh)))
+
+ (def: (module-compilation-loop module-name)
(All [anchor expression statement]
(-> Text <Operation>))
- (let [iteration (: (All [anchor expression statement]
- <Operation>)
- (<| (phase.timed (name-of ..loop-module-compilation) "ITERATION")
- (do phase.Monad<Operation>
- [code (statement.lift-analysis
- (do @
- [code (<| (phase.timed (name-of ..loop-module-compilation) "syntax")
- (..read module-name syntax.no-aliases))
- #let [[cursor _] code]
- _ (analysis.set-cursor cursor)]
- (wrap code)))
- _ (<| (phase.timed (name-of ..loop-module-compilation) "PHASE")
- (totalS.phase code))]
- init.refresh)))]
+ (do phase.Monad<Operation>
+ [reader (statement.lift-analysis
+ (..reader module-name syntax.no-aliases))]
(function (_ state)
(loop [state state]
- (case (iteration state)
+ (case (module-compilation-iteration reader state)
(#error.Success [state' output])
(recur state')
@@ -121,7 +133,7 @@
(-> Text Source <Operation>))
(do phase.Monad<Operation>
[_ (begin-module-compilation module-name source)
- _ (loop-module-compilation module-name)]
+ _ (module-compilation-loop module-name)]
(end-module-compilation module-name)))
(def: #export (compile-module platform configuration compiler)
@@ -186,7 +198,7 @@
(-> <Platform> Configuration <Bundle> (! Any)))
(do (:: (get@ #file-system platform) &monad)
[compiler (initialize platform configuration translation-bundle)
- _ (compile-module platform (set@ #cli.module ..prelude configuration) compiler)
+ _ (compile-module platform (set@ #cli.module syntax.prelude configuration) compiler)
_ (compile-module platform configuration compiler)
## _ (cache/io.clean target ...)
]