diff options
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/analyser.clj | 10 | ||||
-rw-r--r-- | luxc/src/lux/analyser/lux.clj | 34 | ||||
-rw-r--r-- | luxc/src/lux/analyser/meta.clj | 1 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/lux.clj | 37 |
4 files changed, 46 insertions, 36 deletions
diff --git a/luxc/src/lux/analyser.clj b/luxc/src/lux/analyser.clj index 4d4a2c1a0..de5ff8725 100644 --- a/luxc/src/lux/analyser.clj +++ b/luxc/src/lux/analyser.clj @@ -144,6 +144,16 @@ (&/with-cursor cursor (&&lux/analyse-def-alias ?alias ?original))) + "lux def type tagged" + (|let [(&/$Cons [_ (&/$Identifier "" ?name)] + (&/$Cons ?value + (&/$Cons ?meta + (&/$Cons [_ (&/$Tuple ?tags)] + (&/$Nil))) + )) parameters] + (&/with-cursor cursor + (&&lux/analyse-def-type-tagged analyse optimize eval! compile-def ?name ?value ?meta ?tags))) + "lux def program" (|let [(&/$Cons ?program (&/$Nil)) parameters] (&/with-cursor cursor diff --git a/luxc/src/lux/analyser/lux.clj b/luxc/src/lux/analyser/lux.clj index 149bd4a99..8b2428ef0 100644 --- a/luxc/src/lux/analyser/lux.clj +++ b/luxc/src/lux/analyser/lux.clj @@ -542,7 +542,7 @@ (|do [output (analyse-function** analyse exo-type ?self ?arg ?body)] (return (&/|list output)))) -(defn analyse-def [analyse optimize eval! compile-def ?name ?value ?meta] +(defn analyse-def* [analyse optimize eval! compile-def ?name ?value ?meta & [?expected-type]] (|do [_ &/ensure-statement module-name &/get-module-name ? (&&module/defined? module-name ?name) @@ -550,11 +550,39 @@ (str "[Analyser Error] Cannot re-define " (str module-name &/+name-separator+ ?name))) =value (&/without-repl-closure (&/with-scope ?name - (&&/analyse-1+ analyse ?value))) + (if ?expected-type + (&/with-expected-type ?expected-type + (&&/analyse-1 analyse ?expected-type ?value)) + (&&/analyse-1+ analyse ?value)))) =meta (&&/analyse-1 analyse &type/Code ?meta) ==meta (eval! (optimize =meta)) - _ (compile-def ?name (optimize =value) ==meta) + def-value (compile-def ?name (optimize =value) ==meta) _ &type/reset-mappings] + (return (&/T [module-name (&&/expr-type* =value) def-value ==meta])))) + +(defn analyse-def [analyse optimize eval! compile-def ?name ?value ?meta] + (|do [_ (analyse-def* analyse optimize eval! compile-def ?name ?value ?meta)] + (return &/$Nil))) + +(defn analyse-def-type-tagged [analyse optimize eval! compile-def ?name ?value ?meta tags*] + (|do [[module-name def-type def-value ==meta] (analyse-def* analyse optimize eval! compile-def ?name ?value ?meta &type/Type) + _ (&/assert! (&type/type= &type/Type def-type) + "[Analyser Error] Cannot define tags for non-type.") + :let [was-exported? (|case (&&meta/meta-get &&meta/export?-tag ==meta) + (&/$Some _) + true + + _ + false)] + tags (&/map% (fn [tag*] + (|case tag* + [_ (&/$Text tag)] + (return tag) + + _ + (&/fail-with-loc "[Analyser Error] Incorrect format for tags."))) + tags*) + _ (&&module/declare-tags module-name tags was-exported? def-value)] (return &/$Nil))) (def ^:private dummy-cursor diff --git a/luxc/src/lux/analyser/meta.clj b/luxc/src/lux/analyser/meta.clj index 07ec470f3..fde261b0b 100644 --- a/luxc/src/lux/analyser/meta.clj +++ b/luxc/src/lux/analyser/meta.clj @@ -42,5 +42,4 @@ alias-tag "alias" export?-tag "export?" - tags-tag "tags" ) diff --git a/luxc/src/lux/compiler/jvm/lux.clj b/luxc/src/lux/compiler/jvm/lux.clj index 0fec62e8e..4af29d2f6 100644 --- a/luxc/src/lux/compiler/jvm/lux.clj +++ b/luxc/src/lux/compiler/jvm/lux.clj @@ -261,34 +261,7 @@ (throwable->text t))))) _ (&/without-repl-closure (&a-module/define module-name ?name def-type ?meta def-value))] - (|case (&/T [(&type/type= &type/Type def-type) - (&a-meta/meta-get &a-meta/tags-tag ?meta)]) - [true (&/$Some [_ (&/$Tuple tags*)])] - (|do [:let [was-exported? (|case (&a-meta/meta-get &a-meta/export?-tag ?meta) - (&/$Some _) - true - - _ - false)] - tags (&/map% (fn [tag*] - (|case tag* - [_ (&/$Text tag)] - (return tag) - - _ - (&/fail-with-loc "[Compiler Error] Incorrect format for tags."))) - tags*) - _ (&a-module/declare-tags module-name tags was-exported? def-value)] - (return nil)) - - [false (&/$Some _)] - (&/fail-with-loc "[Compiler Error] Cannot define tags for non-type.") - - [true (&/$Some _)] - (&/fail-with-loc "[Compiler Error] Incorrect format for tags.") - - [_ (&/$None)] - (return nil)))) + (return def-value))) (let [class-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) field-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC)] @@ -341,9 +314,9 @@ (return nil))) :let [_ (.visitEnd =class)] _ (&&/save-class! def-name (.toByteArray =class)) - _ (install-def! class-loader current-class module-name ?name ?body ?meta) + def-value (install-def! class-loader current-class module-name ?name ?body ?meta) :let [_ (println 'DEF (str module-name &/+name-separator+ ?name))]] - (return nil))) + (return def-value))) _ (|do [[file-name _ _] &/cursor @@ -368,9 +341,9 @@ (return nil))) :let [_ (.visitEnd =class)] _ (&&/save-class! def-name (.toByteArray =class)) - _ (install-def! class-loader current-class module-name ?name ?body ?meta) + def-value (install-def! class-loader current-class module-name ?name ?body ?meta) :let [_ (println 'DEF (str module-name &/+name-separator+ ?name))]] - (return nil))) + (return def-value))) )))) (defn compile-program [compile ?program] |