aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm.lux2
-rw-r--r--new-luxc/source/program.lux122
-rw-r--r--stdlib/source/lux/tool/compiler/program.lux94
3 files changed, 133 insertions, 85 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/new-luxc/source/luxc/lang/translation/jvm.lux
index 5ffb60482..01bc2b36f 100644
--- a/new-luxc/source/luxc/lang/translation/jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm.lux
@@ -120,7 +120,7 @@
[value (evaluate! library loader class-name valueI)]
(wrap [class-name value]))))
-(def: #export init
+(def: #export host
(IO Host)
(io (let [library (loader.new-library [])
loader (loader.memory library)]
diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux
index 0f761d70d..c4fe26e0b 100644
--- a/new-luxc/source/program.lux
+++ b/new-luxc/source/program.lux
@@ -3,104 +3,58 @@
[cli (#+ program:)]
[control
[monad (#+ do)]]
- [data
- ["." error (#+ Error)]
- ["." text
- format]]
- ["." io (#+ IO io)]
- [time
- ["." instant (#+ Instant)]]
+ ["." io (#+ IO)]
[world
- ["." file (#+ File)]
- ["." console]]
+ ["." file]]
+ [host
+ ["." js]]
[tool
- ["." compiler
- ["." cli (#+ Configuration)]
- [meta
- ["." archive]
- [io
- ["." context]]]
- ["." phase
- ["." translation]
+ [compiler
+ ["." cli]
+ ["/" program]
+ [phase
+ [analysis
+ [".A" macro]]
+ ["." translation
+ [".T" js
+ [".JS" runtime]
+ [".JS" expression]
+ [".JS" extension]]]
["." statement]]
[default
- ["." platform (#+ Platform)]
- ["." init]
- ["." syntax]]]
- ## ["." interpreter]
- ]]
+ ["." platform (#+ Platform)]]]]]
[luxc
[lang
- ["." host/jvm]
+ [host
+ ["." jvm]]
[translation
- ["." jvm
- ["." runtime]
- ["." expression]
+ [".T" jvm
+ [".JVM" runtime]
+ [".JVM" expression]
[procedure
- ["." common]]]]]])
+ [".JVM" common]]]]]]
+ )
-(def: (or-crash! failure-description action)
- (All [a]
- (-> Text (IO (Error a)) (IO a)))
+(def: jvm
+ (IO (Platform IO jvm.Anchor jvm.Inst jvm.Definition))
(do io.monad
- [?output action]
- (case ?output
- (#error.Failure error)
- (exec (log! (format text.new-line
- failure-description text.new-line
- error text.new-line))
- (io.exit +1))
-
- (#error.Success output)
- (wrap output))))
-
-(def: (timed action)
- (All [a]
- (-> (-> Any (IO (Error a))) (IO (Error a))))
- (do (error.with io.monad)
- [start (: (IO (Error Instant))
- (error.lift io.monad instant.now))
- result (action [])
- finish (: (IO (Error Instant))
- (error.lift io.monad instant.now))
- #let [elapsed-time (instant.span start finish)
- _ (log! (format text.new-line
- "Elapsed time: " (%duration elapsed-time)))]]
- (wrap result)))
+ [host jvmT.host]
+ (wrap {#platform.&monad io.monad
+ #platform.&file-system file.system
+ #platform.host host
+ #platform.phase expressionJVM.translate
+ #platform.runtime runtimeJVM.translate})))
-(def: jvm-platform
- (IO (Platform IO host/jvm.Anchor host/jvm.Inst host/jvm.Definition))
+(def: js
+ (IO (Platform IO js.Var js.Expression js.Statement))
(do io.monad
- [host jvm.init]
+ [host jsT.host]
(wrap {#platform.&monad io.monad
#platform.&file-system file.system
#platform.host host
- #platform.phase expression.translate
- #platform.runtime runtime.translate})))
+ #platform.phase expressionJS.translate
+ #platform.runtime runtimeJS.translate})))
(program: [{service cli.service}]
- (do io.monad
- [platform (: (IO (Platform IO host/jvm.Anchor host/jvm.Inst host/jvm.Definition))
- ..jvm-platform)
- console (:: @ map error.assume console.system)]
- (case service
- (#cli.Compilation configuration)
- (<| (or-crash! "Compilation failed:")
- ..timed
- (function (_ _)
- (do (error.with io.monad)
- [state (: (IO (Error (statement.State+ host/jvm.Anchor host/jvm.Inst host/jvm.Definition)))
- (platform.initialize platform common.bundle))
- ## _ (platform.compile platform (set@ #cli.module syntax.prelude configuration) state)
- _ (: (IO (Error Any))
- (platform.compile platform configuration state))
- ## _ (cache/io.clean target ...)
- ]
- (wrap (log! "Compilation complete!")))))
-
- (#cli.Interpretation configuration)
- ## TODO: Fix the interpreter...
- (undefined)
- ## (<| (or-crash! "Interpretation failed:")
- ## (interpreter.run (error.with io.monad) console platform configuration common.bundle))
- )))
+ ## (/.compiler ..js commonJVM.bundle service)
+ (/.compiler macroA.jvm ..js extensionJS.bundle service))
diff --git a/stdlib/source/lux/tool/compiler/program.lux b/stdlib/source/lux/tool/compiler/program.lux
new file mode 100644
index 000000000..4194e0e8d
--- /dev/null
+++ b/stdlib/source/lux/tool/compiler/program.lux
@@ -0,0 +1,94 @@
+(.module:
+ [lux #*
+ [type (#+ :share)]
+ [cli (#+ program:)]
+ ["." io (#+ IO io)]
+ [control
+ [monad (#+ do)]]
+ [data
+ ["." error (#+ Error)]
+ ["." text
+ format]]
+ [time
+ ["." instant (#+ Instant)]]
+ [world
+ ["." console]]
+ [tool
+ [compiler
+ [phase
+ [analysis
+ [macro (#+ Expander)]]
+ ["." translation]
+ ["." statement]]
+ [default
+ ["." platform (#+ Platform)]
+ ["." syntax]]]
+ ## ["." interpreter]
+ ]]
+ [//
+ ["." cli (#+ Service)]])
+
+(def: (or-crash! failure-description action)
+ (All [a]
+ (-> Text (IO (Error a)) (IO a)))
+ (do io.monad
+ [?output action]
+ (case ?output
+ (#error.Failure error)
+ (exec (log! (format text.new-line
+ failure-description text.new-line
+ error text.new-line))
+ (io.exit +1))
+
+ (#error.Success output)
+ (wrap output))))
+
+(def: (timed action)
+ (All [a]
+ (-> (-> Any (IO (Error a))) (IO (Error a))))
+ (do (error.with io.monad)
+ [start (: (IO (Error Instant))
+ (error.lift io.monad instant.now))
+ result (action [])
+ finish (: (IO (Error Instant))
+ (error.lift io.monad instant.now))
+ #let [elapsed-time (instant.span start finish)
+ _ (log! (format text.new-line
+ "Elapsed time: " (%duration elapsed-time)))]]
+ (wrap result)))
+
+(def: #export (compiler expander platform bundle service)
+ (All [anchor expression statement]
+ (-> Expander
+ (IO (Platform IO anchor expression statement))
+ (translation.Bundle anchor expression statement)
+ Service
+ (IO Any)))
+ (do io.monad
+ [platform platform
+ console (:: @ map error.assume console.system)]
+ (case service
+ (#cli.Compilation configuration)
+ (<| (or-crash! "Compilation failed:")
+ ..timed
+ (function (_ _)
+ (do (error.with io.monad)
+ [state (:share [anchor expression statement]
+ {(Platform IO anchor expression statement)
+ platform}
+ {(IO (Error (statement.State+ anchor expression statement)))
+ (platform.initialize expander platform bundle)})
+ _ (: (IO (Error Any))
+ (platform.compile expander platform (set@ #cli.module syntax.prelude configuration) state))
+ ## _ (: (IO (Error Any))
+ ## (platform.compile expander platform configuration state))
+ ## _ (cache/io.clean target ...)
+ ]
+ (wrap (log! "Compilation complete!")))))
+
+ (#cli.Interpretation configuration)
+ ## TODO: Fix the interpreter...
+ (undefined)
+ ## (<| (or-crash! "Interpretation failed:")
+ ## (interpreter.run (error.with io.monad) console platform configuration bundle))
+ )))