diff options
-rw-r--r-- | luxc/src/lux/analyser/module.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/compiler/cache.clj | 16 | ||||
-rw-r--r-- | luxc/src/lux/compiler/core.clj | 11 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/module.lux | 24 | ||||
-rw-r--r-- | stdlib/source/lux.lux | 4 |
5 files changed, 41 insertions, 18 deletions
diff --git a/luxc/src/lux/analyser/module.clj b/luxc/src/lux/analyser/module.clj index 090165af9..ef89777a4 100644 --- a/luxc/src/lux/analyser/module.clj +++ b/luxc/src/lux/analyser/module.clj @@ -42,7 +42,7 @@ ;; "lux;types" (&/|table) ;; module-annotations - (&/T [(&/T ["" 0 0]) (&/$Record (&/|list))]) + &/$None ;; "module-state" $Active] )) @@ -222,7 +222,7 @@ (&/update$ &/$modules (fn [ms] (&/|update module-name - #(&/set$ $module-annotations anns %) + #(&/set$ $module-annotations (&/$Some anns) %) ms)))) nil))) diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj index 678fda334..28cfe53ee 100644 --- a/luxc/src/lux/compiler/cache.clj +++ b/luxc/src/lux/compiler/cache.clj @@ -112,10 +112,15 @@ (|do [_ (delete module)] (return false))) -(defn ^:private install-module [load-def-value module module-hash imports tag-groups module-anns def-entries] +(defn ^:private install-module [load-def-value module module-hash imports tag-groups ?module-anns def-entries] (|do [_ (&a-module/create-module module module-hash) _ (&a-module/flag-cached-module module) - _ (&a-module/set-anns module-anns module) + _ (|case ?module-anns + (&/$Some module-anns) + (&a-module/set-anns module-anns module) + + (&/$None _) + (return nil)) _ (&a-module/set-imports imports) _ (&/map% (partial process-def-entry load-def-value module) def-entries) @@ -144,14 +149,17 @@ (contains? cache-table* _module))) imports) (let [tag-groups (parse-tag-groups _tags-section) - [module-anns _] (&&&ann/deserialize _module-anns-section) + [?module-anns _] (if (= "..." _module-anns-section) + [&/$None nil] + (let [[module-anns _] (&&&ann/deserialize _module-anns-section)] + [(&/$Some module-anns) _])) def-entries (let [def-entries (vec (.split ^String _defs-section &&core/entry-separator))] (if (= [""] def-entries) &/$Nil (&/->list def-entries)))] (|do [_ (install-all-defs-in-module module-name) _ (install-module load-def-value module-name module-hash - imports tag-groups module-anns def-entries) + imports tag-groups ?module-anns def-entries) =module (&/find-module module-name)] (return (&/T [true (assoc cache-table* module-name =module)])))) (return (&/T [false cache-table*]))))) diff --git a/luxc/src/lux/compiler/core.clj b/luxc/src/lux/compiler/core.clj index 8367678c3..d3fc0d9af 100644 --- a/luxc/src/lux/compiler/core.clj +++ b/luxc/src/lux/compiler/core.clj @@ -4,7 +4,7 @@ [clojure.java.io :as io] [clojure.core.match :as M :refer [matchv]] clojure.core.match.array - (lux [base :as & :refer [|let |do return* return fail*]]) + (lux [base :as & :refer [|case |let |do return* return fail*]]) (lux.analyser [base :as &a] [module :as &a-module]) (lux.compiler.cache [type :as &&&type] @@ -44,7 +44,7 @@ (defn generate-module-descriptor [file-hash] (|do [module-name &/get-module-name - module-anns (&a-module/get-anns module-name) + ?module-anns (&a-module/get-anns module-name) defs &a-module/defs imports &a-module/imports tag-groups &a-module/tag-groups @@ -75,7 +75,12 @@ (Long/toUnsignedString file-hash) import-entries tag-entries - (&&&ann/serialize module-anns) + (|case ?module-anns + (&/$Some module-anns) + (&&&ann/serialize module-anns) + + (&/$None _) + "...") def-entries) (&/|interpose section-separator) (&/fold str ""))]] diff --git a/new-luxc/source/luxc/lang/module.lux b/new-luxc/source/luxc/lang/module.lux index 62e20fa9a..58bf94571 100644 --- a/new-luxc/source/luxc/lang/module.lux +++ b/new-luxc/source/luxc/lang/module.lux @@ -19,6 +19,7 @@ (exception: #export Cannot-Define-More-Than-Once) (exception: #export Cannot-Define-In-Unknown-Module) (exception: #export Can-Only-Change-State-Of-Active-Module) +(exception: #export Cannot-Set-Module-Annotations-More-Than-Once) (def: (new-module hash) (-> Nat Module) @@ -28,18 +29,27 @@ #.imports (list) #.tags (list) #.types (list) - #.module-annotations (' {}) + #.module-annotations #.None #.module-state #.Active}) (def: #export (set-annotations annotations) (-> Code (Meta Unit)) (do macro.Monad<Meta> - [self macro.current-module-name] - (function [compiler] - (#e.Success [(update@ #.modules - (&.pl-update self (set@ #.module-annotations annotations)) - compiler) - []])))) + [self-name macro.current-module-name + self macro.current-module] + (case (get@ #.module-annotations self) + #.None + (function [compiler] + (#e.Success [(update@ #.modules + (&.pl-put self-name (set@ #.module-annotations (#.Some annotations) self)) + compiler) + []])) + + (#.Some old) + (macro.fail (Cannot-Set-Module-Annotations-More-Than-Once + (format " Module: " self-name "\n" + "Old annotations: " (%code old) "\n" + "New annotations: " (%code annotations) "\n")))))) (def: #export (import module) (-> Text (Meta Unit)) diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index c1d94e53b..4ec6e1ea1 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -599,7 +599,7 @@ ## #imports (List Text) ## #tags (List [Text [Nat (List Ident) Bool Type]]) ## #types (List [Text [(List Ident) Bool Type]]) -## #module-anns Anns +## #module-anns (Maybe Anns) ## #module-state Module-State}) ("lux def" Module (#Named ["lux" "Module"] @@ -625,7 +625,7 @@ Type))) List) (#Product ## "lux.module-annotations" - Code + (#Apply Code Maybe) Module-State)) )))))) (record$ (#Cons [(tag$ ["lux" "tags"]) |