aboutsummaryrefslogtreecommitdiff
path: root/lux-bootstrapper
diff options
context:
space:
mode:
authorEduardo Julian2022-07-09 14:35:38 -0400
committerEduardo Julian2022-07-09 14:35:38 -0400
commit7db42ab1b9d3c764772ca63c74bf44bb2b8b8325 (patch)
treebd1c865dea0902790f3e462cec4f9bc8d8ae428f /lux-bootstrapper
parentfc2737b5226eda69c12bc593e83e22ed54e4d3af (diff)
First-class programs instead of having a "lux program" extension.
Diffstat (limited to 'lux-bootstrapper')
-rw-r--r--lux-bootstrapper/src/lux.clj6
-rw-r--r--lux-bootstrapper/src/lux/analyser.clj8
-rw-r--r--lux-bootstrapper/src/lux/analyser/lux.clj8
-rw-r--r--lux-bootstrapper/src/lux/analyser/proc/jvm.clj2
-rw-r--r--lux-bootstrapper/src/lux/compiler.clj4
-rw-r--r--lux-bootstrapper/src/lux/compiler/jvm.clj36
6 files changed, 32 insertions, 32 deletions
diff --git a/lux-bootstrapper/src/lux.clj b/lux-bootstrapper/src/lux.clj
index 783a25a64..1d337df04 100644
--- a/lux-bootstrapper/src/lux.clj
+++ b/lux-bootstrapper/src/lux.clj
@@ -21,8 +21,10 @@
(defn -main [& args]
(|case (&/->list args)
- (&/$Item "release" (&/$Item program-module (&/$Item dependencies (&/$Item source-dirs (&/$Item target-dir (&/$End))))))
- (&compiler/compile-program &/$Build program-module
+ (&/$Item "release" (&/$Item program-module (&/$Item program-definition (&/$Item dependencies (&/$Item source-dirs (&/$Item target-dir (&/$End)))))))
+ (&compiler/compile-program &/$Build
+ program-module
+ program-definition
(separate-paths dependencies)
(separate-paths source-dirs)
target-dir)
diff --git a/lux-bootstrapper/src/lux/analyser.clj b/lux-bootstrapper/src/lux/analyser.clj
index 7b6e009dd..286205e44 100644
--- a/lux-bootstrapper/src/lux/analyser.clj
+++ b/lux-bootstrapper/src/lux/analyser.clj
@@ -36,8 +36,7 @@
(|let [analyse (partial analyse-ast optimize eval! compile-module compilers)
[location token] ?token
compile-def (aget compilers 0)
- compile-program (aget compilers 1)
- macro-caller (aget compilers 2)]
+ macro-caller (aget compilers 1)]
(|case token
;; Standard special forms
(&/$Bit ?value)
@@ -141,11 +140,6 @@
[_ (&/$Tuple ?slots)]
(&&lux/analyse-def-type-tagged analyse optimize eval! compile-def ?name ?value true ?slots exported?))))
- "lux def program"
- (|let [(&/$Item ?program (&/$End)) parameters]
- (&/with-location location
- (&&lux/analyse-program analyse optimize compile-program ?program)))
-
"lux def module"
(|let [(&/$Item ?imports (&/$End)) parameters]
(&/with-location location
diff --git a/lux-bootstrapper/src/lux/analyser/lux.clj b/lux-bootstrapper/src/lux/analyser/lux.clj
index 23f6cf4fa..07ef7e07f 100644
--- a/lux-bootstrapper/src/lux/analyser/lux.clj
+++ b/lux-bootstrapper/src/lux/analyser/lux.clj
@@ -737,11 +737,3 @@
_ (&type/check exo-type ==type)
=value (&&/analyse-1+ analyse ?value)]
(return (&/|list (coerce ==type =value)))))
-
-(let [program-type (&/$Function (&/$Apply &type/Text &type/List)
- (&/$Apply &type/Any &type/IO))]
- (defn analyse-program [analyse optimize compile-program ?program]
- (|do [_ &/ensure-declaration
- =program (&&/analyse-1 analyse program-type ?program)
- _ (compile-program (optimize =program))]
- (return &/$End))))
diff --git a/lux-bootstrapper/src/lux/analyser/proc/jvm.clj b/lux-bootstrapper/src/lux/analyser/proc/jvm.clj
index 0cfa8c873..9dba428d5 100644
--- a/lux-bootstrapper/src/lux/analyser/proc/jvm.clj
+++ b/lux-bootstrapper/src/lux/analyser/proc/jvm.clj
@@ -932,7 +932,7 @@
))))
(defn analyse-host [analyse exo-type compilers proc ?values]
- (|let [[_ _ _ compile-class compile-interface] compilers]
+ (|let [[_ _ compile-class compile-interface] compilers]
(try (case proc
"jvm object synchronized" (analyse-jvm-object-synchronized analyse exo-type ?values)
"jvm object class" (analyse-jvm-object-class analyse exo-type ?values)
diff --git a/lux-bootstrapper/src/lux/compiler.clj b/lux-bootstrapper/src/lux/compiler.clj
index a3e60e463..671f7e82b 100644
--- a/lux-bootstrapper/src/lux/compiler.clj
+++ b/lux-bootstrapper/src/lux/compiler.clj
@@ -24,6 +24,6 @@
(defn compile-module [source-dirs name]
(&&jvm/compile-module source-dirs name))
-(defn compile-program [mode program-module dependencies source-dirs target-dir]
+(defn compile-program [mode program-module program-definition dependencies source-dirs target-dir]
(init! dependencies target-dir)
- (&&jvm/compile-program mode program-module source-dirs))
+ (&&jvm/compile-program mode program-module program-definition source-dirs))
diff --git a/lux-bootstrapper/src/lux/compiler/jvm.clj b/lux-bootstrapper/src/lux/compiler/jvm.clj
index ebef7c418..1baec30e1 100644
--- a/lux-bootstrapper/src/lux/compiler/jvm.clj
+++ b/lux-bootstrapper/src/lux/compiler/jvm.clj
@@ -154,12 +154,10 @@
return))))
(def all-compilers
- (let [compile-expression* (partial compile-expression nil)]
- (&/T [(partial &&lux/compile-def compile-expression)
- (partial &&lux/compile-program compile-expression*)
- (fn [macro args state] (.apply macro args state))
- (partial &&proc-host/compile-jvm-class compile-expression*)
- &&proc-host/compile-jvm-interface])))
+ (&/T [(partial &&lux/compile-def compile-expression)
+ (fn [macro args state] (.apply macro args state))
+ (partial &&proc-host/compile-jvm-class (partial compile-expression nil))
+ &&proc-host/compile-jvm-interface]))
(defn ^:private activate-module! [name file-hash]
(|do [_ (&&cache/delete name)
@@ -174,10 +172,10 @@
(let [+field-flags+ (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC)
+datum-sig+ "Ljava/lang/Object;"]
- (defn compile-module [source-dirs name]
+ (defn compile-module [source-dirs name next]
(|do [[file-name file-content] (&&io/read-file source-dirs name)
:let [file-hash (hash file-content)
- compile-module!! (&&parallel/parallel-compilation (partial compile-module source-dirs))]]
+ compile-module!! (&&parallel/parallel-compilation (fn [sub_module] (compile-module source-dirs sub_module nil)))]]
(&/|eitherL (&&cache/load name)
(|do [module-exists? (&a-module/exists? name)]
(if module-exists?
@@ -199,7 +197,11 @@
(&/exhaust% compiler-step))
(&/set$ &/$source (&reader/from name file-content) state))
(&/$Right ?state _)
- (&/run-state (|do [:let [_ (.visitEnd =class)]
+ (&/run-state (|do [_ (if next
+ (&/with-writer =class
+ next)
+ (return nil))
+ :let [_ (.visitEnd =class)]
_ (save-module! name file-hash (.toByteArray =class))
:let [_ (println 'MODULE name)]]
(return file-hash))
@@ -237,14 +239,24 @@
(&/|table)
]))))
+(def program-type
+ (&/$Function (&/$Apply &type/Text &type/List)
+ (&/$Apply &type/Any &type/IO)))
+
(let [!err! *err*]
- (defn compile-program [mode program-module source-dirs]
+ (defn compile-program [mode program-module program-definition source-dirs]
(let [m-action (|do [_ (&&cache/pre-load-cache! source-dirs
&&jvm-cache/load-def-value
&&jvm-cache/install-all-defs-in-module
&&jvm-cache/uninstall-all-defs-in-module)
- _ (compile-module source-dirs &/prelude)]
- (compile-module source-dirs program-module))]
+ _ (compile-module source-dirs &/prelude nil)]
+ (compile-module source-dirs program-module
+ (|do [[de_aliased_symbol [exported? actual-type ?value]] (&a-module/find-def program-module program-definition)
+ _ (&type/check program-type actual-type)
+ here &/location]
+ (&&lux/compile-program (partial compile-expression nil)
+ (&a/|meta program-type here
+ (&o/$def de_aliased_symbol))))))]
(|case (m-action (&/init-state "{old}" mode (jvm-host)))
(&/$Right ?state _)
(do (println "Compilation complete!")