diff options
Diffstat (limited to 'luxc/src')
26 files changed, 144 insertions, 128 deletions
diff --git a/luxc/src/lux.clj b/luxc/src/lux.clj index 2daf0000a..3ca520576 100644 --- a/luxc/src/lux.clj +++ b/luxc/src/lux.clj @@ -31,4 +31,4 @@ target-dir) _ - (println "Can't understand command."))) + (println "Cannot understand command."))) diff --git a/luxc/src/lux/analyser.clj b/luxc/src/lux/analyser.clj index aaf441713..4090cfea8 100644 --- a/luxc/src/lux/analyser.clj +++ b/luxc/src/lux/analyser.clj @@ -197,7 +197,7 @@ (&&lux/analyse-apply analyse cursor exo-type macro-caller =fn parameters)))) _ - (&/fail-with-loc (str "[Analyser Error] Unknown syntax: " (prn-str (&/show-ast (&/T [(&/T ["" -1 -1]) token]))))) + (&/fail-with-loc (str "[Analyser Error] Unknown syntax: " (&/show-ast (&/T [(&/T ["" -1 -1]) token])))) ))) ;; [Resources] diff --git a/luxc/src/lux/analyser/base.clj b/luxc/src/lux/analyser/base.clj index 3f95e072a..f4718a67e 100644 --- a/luxc/src/lux/analyser/base.clj +++ b/luxc/src/lux/analyser/base.clj @@ -55,7 +55,7 @@ (return x) _ - (&/fail-with-loc "[Analyser Error] Can't expand to other than 1 element.")))) + (&/fail-with-loc "[Analyser Error] Macro cannot expand to more than 1 output.")))) (defn analyse-1 [analyse exo-type elem] (&/with-expected-type exo-type diff --git a/luxc/src/lux/analyser/case.clj b/luxc/src/lux/analyser/case.clj index a37b6ebf3..5b25115ea 100644 --- a/luxc/src/lux/analyser/case.clj +++ b/luxc/src/lux/analyser/case.clj @@ -180,7 +180,7 @@ (apply-type! =type-fun param)) _ - (&/fail-with-loc (str "[Type System] Not a type function:\n" (&type/show-type type-fn) "\n")))) + (&/fail-with-loc (str "[Type System] Not a type-function:\n" (&type/show-type type-fn) "\n")))) (defn adjust-type* [up type] "(-> (List (, (Maybe (List Type)) Int Type)) Type (Lux Type))" @@ -245,7 +245,7 @@ (return type) _ - (&/fail-with-loc (str "[Pattern-matching Error] Can't adjust type: " (&type/show-type type))) + (&/fail-with-loc (str "[Pattern-matching Error] Cannot pattern-match against type: " (&type/show-type type))) )) (defn adjust-type [type] @@ -335,9 +335,10 @@ (return (&/T [&/$Nil =kont]))) (&/|reverse (&/zip2 _tuple-types ?members)))] (return (&/T [($TupleTestAC =tests) =kont]))) - (&/fail-with-loc (str "[Pattern-matching Error] Pattern-matching mismatch. Require tuple[" (&/|length (&type/flatten-prod value-type*)) "]. Given tuple [" (&/|length ?members) "]" - " -- " (&/show-ast pattern) - " " (&type/show-type value-type*) " " (&type/show-type value-type))))) + (&/fail-with-loc (str "[Pattern-matching Error] Pattern-matching mismatch. Requires tuple[" (&/|length (&type/flatten-prod value-type*)) "]. Given tuple [" (&/|length ?members) "].\n" + " At: " (&/show-ast pattern) "\n" + "Expected type: " (&type/show-type value-type*) "\n" + " Actual type: " (&type/show-type value-type))))) _ (&/fail-with-loc (str "[Pattern-matching Error] Tuples require tuple-types: " (&type/show-type value-type)))))) @@ -523,7 +524,9 @@ (merge-total v (&/T [t ?body]))) ?values ?tests)] (return ($TupleTotal total? structs))) - (&/fail-with-loc "[Pattern-matching Error] Inconsistent tuple-size.")) + (&/fail-with-loc (str "[Pattern-matching Error] Inconsistent tuple-size.\n" + "Expected: " (&/|length ?values) "\n" + " Actual: " (&/|length ?tests)))) [($DefaultTotal total?) ($VariantTestAC ?tag ?count ?test)] (|do [sub-struct (merge-total ($DefaultTotal total?) @@ -533,7 +536,7 @@ (return list) (&/$None) - (&/fail-with-loc "[Pattern-matching Error] YOLO"))] + (assert false))] (return ($VariantTotal total? structs))) [($VariantTotal total? ?branches) ($VariantTestAC ?tag ?count ?test)] @@ -549,7 +552,7 @@ (return list) (&/$None) - (&/fail-with-loc "[Pattern-matching Error] YOLO"))] + (assert false))] (return ($VariantTotal total? structs))) ))) @@ -623,11 +626,11 @@ (|case value-type* (&/$ProdT _) (|let [num-elems (&/|length ?structs) - [_shorter _tuple-types] (&type/tuple-types-for (&/|length ?structs) value-type*)] - (if (= num-elems _shorter) - (|do [totals (&/map2% check-totality _tuple-types ?structs)] - (return (&/fold #(and %1 %2) true totals))) - (&/fail-with-loc (str "[Pattern-maching Error] Tuple-mismatch. Require tuple[" (&/|length (&type/flatten-prod value-type*)) "]. Given tuple [" (&/|length ?structs) "]")))) + [_shorter _tuple-types] (&type/tuple-types-for (&/|length ?structs) value-type*) + _ (&/assert! (= num-elems _shorter) + (&/fail-with-loc (str "[Pattern-maching Error] Tuple-mismatch. Require tuple[" (&/|length (&type/flatten-prod value-type*)) "]. Given tuple [" (&/|length ?structs) "]")))] + (|do [totals (&/map2% check-totality _tuple-types ?structs)] + (return (&/fold #(and %1 %2) true totals)))) _ (&/fail-with-loc (str "[Pattern-maching Error] Tuple is not total." " - " (&type/show-type value-type*))))))))) @@ -655,7 +658,6 @@ &/$Nil branches) struct (&/fold% merge-total ($DefaultTotal false) patterns) - ? (check-totality value-type struct)] - (if ? - (return patterns) - (&/fail-with-loc "[Pattern-maching Error] Pattern-matching is non-total.")))) + ? (check-totality value-type struct) + _ (&/assert! ? "[Pattern-maching Error] Pattern-matching is not total.")] + (return patterns))) diff --git a/luxc/src/lux/analyser/env.clj b/luxc/src/lux/analyser/env.clj index 90fa39dfb..b8027a048 100644 --- a/luxc/src/lux/analyser/env.clj +++ b/luxc/src/lux/analyser/env.clj @@ -62,7 +62,7 @@ (fn [state] (|case (&/get$ &/$scopes state) (&/$Nil) - ((&/fail-with-loc "[Analyser Error] Can't obtain captured vars without environments.") + ((&/fail-with-loc "[Analyser Error] Cannot obtain captured vars without environments.") state) (&/$Cons env _) diff --git a/luxc/src/lux/analyser/lux.clj b/luxc/src/lux/analyser/lux.clj index 1eecaf577..989ccb591 100644 --- a/luxc/src/lux/analyser/lux.clj +++ b/luxc/src/lux/analyser/lux.clj @@ -27,7 +27,7 @@ _ 0)) -;; TODO: This technique won't work if the body of the type contains +;; TODO: This technique will not work if the body of the type contains ;; nested quantifications that cannot be directly counted. (defn ^:private next-bound-type [type] "(-> Type Type)" @@ -169,7 +169,7 @@ (return x) _ - (&/fail-with-loc "[Analyser Error] Can't expand to other than 1 element.")))) + (&/fail-with-loc "[Analyser Error] Macro cannot expand to more than 1 output.")))) (defn analyse-variant [analyse ?exo-type idx is-last? ?values] (|case ?exo-type @@ -235,15 +235,15 @@ (&/map% (partial &&/clean-analysis $var) =exprs)))) _ - (&/fail-with-loc (str "[Analyser Error] Can't create variant if the expected type is " (&type/show-type exo-type*) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))) + (&/fail-with-loc (str "[Analyser Error] Cannot create variant if the expected type is " (&type/show-type exo-type*) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))) (fn [err] (|case exo-type (&/$VarT ?id) (|do [=exo-type (&type/deref ?id)] - (&/fail-with-loc (str err "\n" "[Analyser Error] Can't create variant if the expected type is " (&type/show-type =exo-type) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))) + (&/fail-with-loc (str err "\n" "[Analyser Error] Cannot create variant if the expected type is " (&type/show-type =exo-type) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))) _ - (&/fail-with-loc (str err "\n" "[Analyser Error] Can't create variant if the expected type is " (&type/show-type exo-type) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))))) + (&/fail-with-loc (str err "\n" "[Analyser Error] Cannot create variant if the expected type is " (&type/show-type exo-type) " " idx " " (->> ?values (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))))) ))) (defn analyse-record [analyse exo-type ?elems] @@ -293,7 +293,7 @@ state) _ - ((&/fail-with-loc "[Analyser Error] Can't have anything other than a global def in the global environment.") + ((&/fail-with-loc "[Analyser Error] Cannot have anything other than a global def in the global environment.") state)) ((&/fail-with-loc (str "[Analyser Error] Unknown global definition: " name)) state)) @@ -363,9 +363,9 @@ (return (&/T [=output-t (&/$Cons =arg =args)]))) _ - (&/fail-with-loc (str "[Analyser Error] Can't apply a non-function: " (&type/show-type ?fun-type*)))) + (&/fail-with-loc (str "[Analyser Error] Cannot apply a non-function: " (&type/show-type ?fun-type*)))) (fn [err] - (&/fail-with-loc (str err "\n" "[Analyser Error] Can't apply function " (&type/show-type fun-type) " to args: " (->> ?args (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))))) + (&/fail-with-loc (str err "\n" "[Analyser Error] Cannot apply function " (&type/show-type fun-type) " to args: " (->> ?args (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))))) )) (defn ^:private do-analyse-apply [analyse exo-type =fn ?args] @@ -390,10 +390,11 @@ ((&/fail-with-loc error) state))) ;; module-name &/get-module-name ;; :let [[r-prefix r-name] real-name - ;; _ (->> (&/|map &/show-ast macro-expansion) - ;; (&/|interpose "\n") - ;; (&/fold str "") - ;; (println 'macro-expansion (&/ident->text real-name) "@" module-name))] + ;; _ (when (= "syntax:" r-name) + ;; (->> (&/|map &/show-ast macro-expansion) + ;; (&/|interpose "\n") + ;; (&/fold str "") + ;; (println 'macro-expansion (&/ident->text real-name) "@" module-name)))] ] (&/flat-map% (partial analyse exo-type) macro-expansion)) @@ -406,7 +407,7 @@ (defn analyse-case [analyse exo-type ?value ?branches] (|do [:let [num-branches (&/|length ?branches)] - _ (&/assert! (> num-branches 0) "[Analyser Error] Can't have empty branches in \"case\" expression.") + _ (&/assert! (> num-branches 0) "[Analyser Error] Cannot have empty branches in \"case\" expression.") _ (&/assert! (even? num-branches) "[Analyser Error] Unbalanced branches in \"case\" expression.") =value (&&/analyse-1+ analyse ?value) :let [var?? (|case =value @@ -548,25 +549,24 @@ (defn analyse-def [analyse optimize eval! compile-def ?name ?value ?meta] (|do [_ &/ensure-statement module-name &/get-module-name - ? (&&module/defined? module-name ?name)] - (if ? - (&/fail-with-loc (str "[Analyser Error] Can't re-define " (str module-name ";" ?name))) - (|do [=value (&/without-repl-closure - (&/with-scope ?name - (&&/analyse-1+ analyse ?value))) - =meta (&&/analyse-1 analyse &type/Anns ?meta) - ==meta (eval! (optimize =meta)) - _ (&&module/test-type module-name ?name ==meta (&&/expr-type* =value)) - _ (&&module/test-macro module-name ?name ==meta (&&/expr-type* =value)) - _ (compile-def ?name (optimize =value) ==meta) - ;; TODO: Make the call to &type/reset-mappings unnecessary. - ;; It shouldn't be necessary to reset the mappings of the - ;; type-vars, because those mappings shouldn't stay around - ;; after being cleaned-up. - ;; I must figure out why they're staying around. - _ &type/reset-mappings] - (return &/$Nil)) - ))) + ? (&&module/defined? module-name ?name) + _ (&/assert! (not ?) + (&/fail-with-loc (str "[Analyser Error] Cannot re-define " (str module-name ";" ?name)))) + =value (&/without-repl-closure + (&/with-scope ?name + (&&/analyse-1+ analyse ?value))) + =meta (&&/analyse-1 analyse &type/Anns ?meta) + ==meta (eval! (optimize =meta)) + _ (&&module/test-type module-name ?name ==meta (&&/expr-type* =value)) + _ (&&module/test-macro module-name ?name ==meta (&&/expr-type* =value)) + _ (compile-def ?name (optimize =value) ==meta) + ;; TODO: Make the call to &type/reset-mappings unnecessary. + ;; It should not be necessary to reset the mappings of the + ;; type-vars, because those mappings should not stay around + ;; after being cleaned-up. + ;; I must figure out why they're staying around. + _ &type/reset-mappings] + (return &/$Nil))) (defn ^:private merge-module-states "(-> Host Host Host)" @@ -596,7 +596,7 @@ (&/get$ &&module/$defs) &/|length (= 0))) - ;; Don't modify the entry of the current module, to + ;; Do not modify the entry of the current module, to ;; avoid overwritting it's data in improper ways. ;; Since it's assumed the "original" old module ;; contains all the proper own-module information. @@ -635,13 +635,14 @@ (|let [[path alias] _import] (&/without-repl (&/save-module - (|do [_ (if (= current-module path) - (&/fail-with-loc (str "[Analyser Error] Module can't import itself: " path)) - (return nil)) + (|do [_ (&/assert! (not (= current-module path)) + (&/fail-with-loc (str "[Analyser Error] Module cannot import itself: " path))) already-compiled? (&&module/exists? path) active? (&&module/active-module? path) + ;; TODO: Enrich this error-message + ;; to explicitly show the cyclic dependency. _ (&/assert! (not active?) - (str "[Analyser Error] Can't import a module that is mid-compilation: " path " @ " current-module)) + (str "[Analyser Error] Cannot import a module that is mid-compilation { cyclic dependency }: " path " @ " current-module)) _ (&&module/add-import path) ?async (if (not already-compiled?) (compile-module path) @@ -658,7 +659,7 @@ ;; the environment forever, making type-checking slower. ;; The merging process for compilers more-or-less "fixes" the ;; problem by resetting the typing enviroment, but ideally - ;; those type-vars shouldn't survive in the first place. + ;; those type-vars should not survive in the first place. ;; TODO: MUST FIX _ (&/fold% (fn [compiler _async] (|case @_async diff --git a/luxc/src/lux/analyser/module.clj b/luxc/src/lux/analyser/module.clj index 9df1054c8..0a7e336aa 100644 --- a/luxc/src/lux/analyser/module.clj +++ b/luxc/src/lux/analyser/module.clj @@ -81,7 +81,7 @@ (|do [current-module &/get-module-name] (fn [state] (if (&/|member? module (->> state (&/get$ &/$modules) (&/|get current-module) (&/get$ $imports))) - ((&/fail-with-loc (str "[Analyser Error] Can't import module " (pr-str module) " twice @ " current-module)) + ((&/fail-with-loc (str "[Analyser Error] Cannot import module " (pr-str module) " twice @ " current-module)) state) (return* (&/update$ &/$modules (fn [ms] @@ -122,7 +122,7 @@ nil) _ - ((&/fail-with-loc (str "[Analyser Error] Can't create a new global definition outside of a global environment: " module ";" name)) + ((&/fail-with-loc (str "[Analyser Error] Cannot create a new global definition outside of a global environment: " module ";" name)) state)))) (defn def-type @@ -182,10 +182,10 @@ (fn [state] (let [_module_ (->> state (&/get$ &/$modules) (&/|get module))] (if (&/|member? module (->> _module_ (&/get$ $imports))) - ((&/fail-with-loc (str "[Analyser Error] Can't create alias that is the same as a module nameL " (pr-str alias) " for " reference)) + ((&/fail-with-loc (str "[Analyser Error] Cannot create alias that is the same as a module nameL " (pr-str alias) " for " reference)) state) (if-let [real-name (->> _module_ (&/get$ $module-aliases) (&/|get alias))] - ((&/fail-with-loc (str "[Analyser Error] Can't re-use alias \"" alias "\" @ " module)) + ((&/fail-with-loc (str "[Analyser Error] Cannot re-use alias \"" alias "\" @ " module)) state) (return* (->> state (&/update$ &/$modules @@ -247,11 +247,11 @@ (return* state (&/T [(&/T [module name]) $def])) _ - ((&/fail-with-loc (str "[Analyser Error @ find-def] Can't use unexported definition: " (str module &/+name-separator+ name))) + ((&/fail-with-loc (str "[Analyser Error @ find-def] Cannot use unexported definition: " (str module &/+name-separator+ name))) state)))) ((&/fail-with-loc (str "[Analyser Error @ find-def] Definition does not exist: " (str module &/+name-separator+ name))) state)) - ((&/fail-with-loc (str "[Analyser Error @ find-def] Module doesn't exist: " module)) + ((&/fail-with-loc (str "[Analyser Error @ find-def] Module does not exist: " module)) state)) ((&/fail-with-loc (str "[Analyser Error @ find-def] Unknown module: " module)) state)) @@ -311,7 +311,7 @@ (|do [tags-table (tags-by-module module) _ (&/map% (fn [tag] (if (&/|get tag tags-table) - (&/fail-with-loc (str "[Analyser Error] Can't re-declare tag: " (&/ident->text (&/T [module tag])))) + (&/fail-with-loc (str "[Analyser Error] Cannot re-declare tag: " (&/ident->text (&/T [module tag])))) (return nil))) tags)] (return nil))) @@ -319,7 +319,7 @@ (defn ensure-undeclared-type [module name] (|do [types-table (types-by-module module) _ (&/assert! (nil? (&/|get name types-table)) - (str "[Analyser Error] Can't re-declare type: " (&/ident->text (&/T [module name]))))] + (str "[Analyser Error] Cannot re-declare type: " (&/ident->text (&/T [module name]))))] (return nil))) (defn declare-tags @@ -329,7 +329,7 @@ type-name (&type/type-name type) :let [[_module _name] type-name] _ (&/assert! (= module _module) - (str "[Module Error] Can't define tags for a type belonging to a foreign module: " (&/ident->text type-name))) + (str "[Module Error] Cannot define tags for a type belonging to a foreign module: " (&/ident->text type-name))) _ (ensure-undeclared-type _module _name)] (fn [state] (if-let [=module (->> state (&/get$ &/$modules) (&/|get module))] @@ -361,7 +361,7 @@ (if (or ?exported (= module current-module)) (return* state &/unit-tag) - ((&/fail-with-loc (str "[Analyser Error] Can't access tag #" (&/ident->text (&/T [module tag-name])) " from module " current-module)) + ((&/fail-with-loc (str "[Analyser Error] Cannot access tag #" (&/ident->text (&/T [module tag-name])) " from module " current-module)) state))) ((&/fail-with-loc (str "[Module Error] Unknown tag: " (&/ident->text (&/T [module tag-name])))) state)) @@ -408,7 +408,7 @@ (|case (&meta/meta-get <tag> meta) (&/$Some (&/$BoolA true)) (&/try-all% (&/|list (&type/check <type> type) - (&/fail-with-loc (str "[Analyser Error] Can't tag as lux;" <desc> "? if it's not a " <desc> ": " (str module ";" name))))) + (&/fail-with-loc (str "[Analyser Error] Cannot tag as lux;" <desc> "? if it's not a " <desc> ": " (str module ";" name))))) _ (return nil))) @@ -428,7 +428,7 @@ (return (&/T [_module _alias])) _ - (&/fail-with-loc "[Analyser Error] Wrong import syntax."))) + (&/fail-with-loc "[Analyser Error] Incorrect import syntax."))) _parts) _ diff --git a/luxc/src/lux/analyser/proc/js.clj b/luxc/src/lux/analyser/proc/js.clj index 2d36dd0d9..ff6a21c11 100644 --- a/luxc/src/lux/analyser/proc/js.clj +++ b/luxc/src/lux/analyser/proc/js.clj @@ -89,5 +89,5 @@ "null" (analyse-js-null analyse exo-type ?values) "undefined" (analyse-js-undefined analyse exo-type ?values) ;; else - (&/fail-with-loc (str "[Analyser Error] Unknown JS procedure: " proc))) + (&/fail-with-loc (str "[Analyser Error] Unknown host procedure: " ["js" proc]))) ) diff --git a/luxc/src/lux/analyser/proc/jvm.clj b/luxc/src/lux/analyser/proc/jvm.clj index 1d6075136..ec14aabb0 100644 --- a/luxc/src/lux/analyser/proc/jvm.clj +++ b/luxc/src/lux/analyser/proc/jvm.clj @@ -45,7 +45,7 @@ (ensure-object type*)) _ - (&/fail-with-loc (str "[Analyser Error] Expecting object: " (&type/show-type type))))) + (&/fail-with-loc (str "[Analyser Error] Was expecting object type. Instead got: " (&type/show-type type))))) (defn ^:private as-object [type] "(-> Type Type)" @@ -119,7 +119,9 @@ gvars targs)] (&host-type/instance-param &type/existential gtype-env gtype)) - (&/fail-with-loc (str "[Type Error] Mismatched number of type-parameters: " (&/|length gvars) " - " (&type/show-type obj-type)))) + (&/fail-with-loc (str "[Type Error] Mismatched number of type-parameters for " (&type/show-type obj-type) "\n" + "Expected: " (&/|length targs) "\n" + " Actual: " (&/|length gvars)))) _ (&/fail-with-loc (str "[Type Error] Type is not an object type: " (&type/show-type obj-type))))) @@ -181,7 +183,7 @@ (&/$GenericTypeVar var-name) (if-let [ex (&/|get var-name env)] (return ex) - (&/fail-with-loc (str "[Analysis Error] Unknown type var: " var-name))) + (&/fail-with-loc (str "[Analysis Error] Unknown type-var: " var-name))) (&/$GenericClass name params) (case name @@ -987,7 +989,7 @@ "b2l" (analyse-jvm-b2l analyse exo-type ?values) "s2l" (analyse-jvm-s2l analyse exo-type ?values) ;; else - (->> (&/fail-with-loc (str "[Analyser Error] Unknown JVM procedure: " proc)) + (->> (&/fail-with-loc (str "[Analyser Error] Unknown host procedure: " ["jvm" proc])) (if-let [[_ _def-code] (re-find #"^interface:(.*)$" proc)] (|do [[_module _line _column] &/cursor] (&reader/with-source (str "interface@" "(" _module "," _line "," _column ")") _def-code diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj index 582e2c96f..da6dcbf0a 100644 --- a/luxc/src/lux/base.clj +++ b/luxc/src/lux/base.clj @@ -722,7 +722,7 @@ +init-bindings+] )) -(do-template [<tag> <host> <ask> <change> <with>] +(do-template [<tag> <host-desc> <host> <ask> <change> <with>] (do (def <host> (fn [compiler] (|case (get$ $host compiler) @@ -730,7 +730,8 @@ (return* compiler host-data) _ - ((fail-with-loc "[Error] Wrong host.") compiler)))) + ((fail-with-loc (str "[Error] Wrong host.\nExpected: " <host-desc>)) + compiler)))) (def <ask> (fn [compiler] @@ -753,8 +754,8 @@ new-val (<change> slot (fn [_] old-val))] (return ?output-val)))) - $Jvm jvm-host jvm? change-jvm-host-slot with-jvm-host-slot - $Js js-host js? change-js-host-slot with-js-host-slot + $Jvm "JVM" jvm-host jvm? change-jvm-host-slot with-jvm-host-slot + $Js "JS" js-host js? change-js-host-slot with-js-host-slot ) (do-template [<name> <slot>] @@ -774,7 +775,7 @@ (return writer) _ - (fail-with-loc "[Error] Writer hasn't been set.")))) + (fail-with-loc "[Error] Writer has not been set.")))) (defn with-writer [writer body] (with-jvm-host-slot $writer (fn [_] ($Some writer)) body)) @@ -879,7 +880,8 @@ (try (let [top (|head (get$ $scopes state))] (return* state top)) (catch Throwable _ - ((fail-with-loc "[Error] No local environment.") state))))) + ((fail-with-loc "[Error] No local environment.") + state))))) (def gen-id (fn [state] @@ -908,7 +910,8 @@ (fn [state] (|case (|reverse (get$ $scopes state)) ($Nil) - ((fail-with-loc "[Analyser Error] Can't get the module-name without a module.") state) + ((fail-with-loc "[Analyser Error] Cannot get the module-name without a module.") + state) ($Cons ?global _) (return* state (|head (get$ $name ?global)))))) @@ -918,7 +921,8 @@ (fn [state] (if-let [module (|get name (get$ $modules state))] (return* state module) - ((fail-with-loc (str "[Error] Unknown module: " name)) state)))) + ((fail-with-loc (str "[Error] Unknown module: " name)) + state)))) (def get-current-module "(Lux (Module Compiler))" @@ -1061,7 +1065,8 @@ (return* state unit-tag) ($Some _) - ((fail-with-loc "[Error] All statements must be top-level forms.") state)))) + ((fail-with-loc "[Error] All statements must be top-level forms.") + state)))) (def cursor ;; (Lux Cursor) @@ -1250,7 +1255,7 @@ (return init) [_ _] - (assert false "Lists don't match in size."))) + (assert false "Lists do not match in size."))) (defn map2% [f xs ys] (|case [xs ys] @@ -1263,7 +1268,7 @@ (return $Nil) [_ _] - (assert false "Lists don't match in size."))) + (assert false "Lists do not match in size."))) (defn map2 [f xs ys] (|case [xs ys] diff --git a/luxc/src/lux/compiler/cache/ann.clj b/luxc/src/lux/compiler/cache/ann.clj index 5256fa0af..b71d6707b 100644 --- a/luxc/src/lux/compiler/cache/ann.clj +++ b/luxc/src/lux/compiler/cache/ann.clj @@ -148,7 +148,7 @@ (deserialize-ident input) (deserialize-list input) (deserialize-dict input) - (assert false "[Cache error] Can't deserialize annocation."))) + (assert false "[Cache error] Cannot deserialize annocation."))) (defn deserialize-anns "(-> Text Text)" diff --git a/luxc/src/lux/compiler/cache/type.clj b/luxc/src/lux/compiler/cache/type.clj index 6bddef9c1..26a08e193 100644 --- a/luxc/src/lux/compiler/cache/type.clj +++ b/luxc/src/lux/compiler/cache/type.clj @@ -156,4 +156,4 @@ (deserialize-univq input) (deserialize-exq input) (deserialize-host input) - (assert false (str "[Cache error] Can't deserialize type. --- " input)))) + (assert false (str "[Cache error] Cannot deserialize type. --- " input)))) diff --git a/luxc/src/lux/compiler/core.clj b/luxc/src/lux/compiler/core.clj index 15f03ea6e..a43a6ff48 100644 --- a/luxc/src/lux/compiler/core.clj +++ b/luxc/src/lux/compiler/core.clj @@ -22,7 +22,7 @@ ;; [Utils] (defn write-file [^String file-name ^bytes data] - (do (assert (not (.exists (File. file-name))) (str "Can't overwrite file: " file-name)) + (do (assert (not (.exists (File. file-name))) (str "Cannot overwrite file: " file-name)) (with-open [stream (BufferedOutputStream. (FileOutputStream. file-name))] (.write stream data) (.flush stream)))) diff --git a/luxc/src/lux/compiler/io.clj b/luxc/src/lux/compiler/io.clj index f129fd3f0..46a3fdfd7 100644 --- a/luxc/src/lux/compiler/io.clj +++ b/luxc/src/lux/compiler/io.clj @@ -37,4 +37,4 @@ (return (&/T [host-file-name code])) (if-let [code (get @!libs lux-file-name)] (return (&/T [lux-file-name code])) - (&/fail-with-loc (str "[I/O Error] Module doesn't exist: " module-name))))))) + (&/fail-with-loc (str "[I/O Error] Module does not exist: " module-name))))))) diff --git a/luxc/src/lux/compiler/js.clj b/luxc/src/lux/compiler/js.clj index be405ad33..68d4e0997 100644 --- a/luxc/src/lux/compiler/js.clj +++ b/luxc/src/lux/compiler/js.clj @@ -139,7 +139,7 @@ (let [compiler-step (&analyser/analyse &optimizer/optimize eval! compile-module!! all-compilers)] (|do [module-exists? (&a-module/exists? name)] (if module-exists? - (&/fail-with-loc (str "[Compiler Error] Can't re-define a module: " name)) + (&/fail-with-loc (str "[Compiler Error] Cannot re-define a module: " name)) (|do [_ (&&cache/delete name) _ (&&/init-buffer) _ (&a-module/create-module name file-hash) diff --git a/luxc/src/lux/compiler/js/lux.clj b/luxc/src/lux/compiler/js/lux.clj index bf188803c..d066dff17 100644 --- a/luxc/src/lux/compiler/js/lux.clj +++ b/luxc/src/lux/compiler/js/lux.clj @@ -97,7 +97,7 @@ (defn compile-iter [compile register-offset ?args] ;; Can only optimize if it is a simple expression. - ;; Won't work if it's inside an 'if', unlike on the JVM. + ;; Will not work if it's inside an 'if', unlike on the JVM. ;; (|do [[updates _] (&/fold% (fn [updates+offset ?arg] ;; (|let [[updates offset] updates+offset ;; already-set? (|case ?arg @@ -368,7 +368,7 @@ (return nil)) [false (&/$Some _)] - (&/fail-with-loc "[Compiler Error] Can't define tags for non-type.") + (&/fail-with-loc "[Compiler Error] Cannot define tags for non-type.") [true (&/$Some _)] (&/fail-with-loc "[Compiler Error] Incorrect format for tags.") diff --git a/luxc/src/lux/compiler/js/proc/common.clj b/luxc/src/lux/compiler/js/proc/common.clj index 4fdff5f21..eb4e27857 100644 --- a/luxc/src/lux/compiler/js/proc/common.clj +++ b/luxc/src/lux/compiler/js/proc/common.clj @@ -604,4 +604,4 @@ ) ;; else - (&/fail-with-loc (str "[Compiler Error] Unknown host procedure: " [category proc])))) + (&/fail-with-loc (str "[Compiler Error] Unknown procedure: " [category proc])))) diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj index 6c4731e16..150ec54f4 100644 --- a/luxc/src/lux/compiler/jvm.clj +++ b/luxc/src/lux/compiler/jvm.clj @@ -180,7 +180,7 @@ (let [compiler-step (&analyser/analyse &optimizer/optimize eval! compile-module!! all-compilers)] (|do [module-exists? (&a-module/exists? name)] (if module-exists? - (&/fail-with-loc "[Compiler Error] Can't re-define a module!") + (&/fail-with-loc (str "[Compiler Error] Cannot re-define a module: " name)) (|do [_ (&&cache/delete name) _ (&a-module/create-module name file-hash) _ (&a-module/flag-active-module name) diff --git a/luxc/src/lux/compiler/jvm/lux.clj b/luxc/src/lux/compiler/jvm/lux.clj index 12a2f83c7..e14615946 100644 --- a/luxc/src/lux/compiler/jvm/lux.clj +++ b/luxc/src/lux/compiler/jvm/lux.clj @@ -310,7 +310,9 @@ def-meta ?meta] def-value (try (return (-> def-class (.getField &/value-field) (.get nil))) (catch Throwable t - (&/assert! "Error during value initialization." (throwable->text t)))) + (&/assert! false + (str "Error during value initialization:\n" + (throwable->text t))))) _ (&/without-repl-closure (&a-module/define module-name ?name def-type def-meta def-value)) _ (|case (&/T [is-type? (&a-meta/meta-get &a-meta/tags-tag def-meta)]) @@ -333,7 +335,7 @@ (return nil)) [false (&/$Some _)] - (&/fail-with-loc "[Compiler Error] Can't define tags for non-type.") + (&/fail-with-loc "[Compiler Error] Cannot define tags for non-type.") [true (&/$Some _)] (&/fail-with-loc "[Compiler Error] Incorrect format for tags.") @@ -377,7 +379,9 @@ def-meta ?meta] def-value (try (return (-> def-class (.getField &/value-field) (.get nil))) (catch Throwable t - (&/assert! "Error during value initialization." (throwable->text t)))) + (&/assert! false + (str "Error during value initialization:\n" + (throwable->text t))))) _ (&/without-repl-closure (&a-module/define module-name ?name def-type def-meta def-value)) _ (|case (&/T [is-type? (&a-meta/meta-get &a-meta/tags-tag def-meta)]) @@ -400,7 +404,7 @@ (return nil)) [false (&/$Some _)] - (&/fail-with-loc "[Compiler Error] Can't define tags for non-type.") + (&/fail-with-loc "[Compiler Error] Cannot define tags for non-type.") [true (&/$Some _)] (&/fail-with-loc "[Compiler Error] Incorrect format for tags.") diff --git a/luxc/src/lux/compiler/jvm/rt.clj b/luxc/src/lux/compiler/jvm/rt.clj index 9bc94427e..5d3a1ad09 100644 --- a/luxc/src/lux/compiler/jvm/rt.clj +++ b/luxc/src/lux/compiler/jvm/rt.clj @@ -254,7 +254,7 @@ ;; done to ensure variants were never created with null ;; values (this would interfere later with ;; pattern-matching). - ;; Since Lux itself doesn't have null values as part of + ;; Since Lux itself does not have null values as part of ;; the language, the burden of ensuring non-nulls was ;; shifted to library code dealing with host-interop, to ;; ensure variant-making was as fast as possible. @@ -285,7 +285,7 @@ ;; (.visitLabel $is-null) ;; (.visitTypeInsn Opcodes/NEW "java/lang/IllegalStateException") ;; (.visitInsn Opcodes/DUP) - ;; (.visitLdcInsn "Can't create variant for null pointer") + ;; (.visitLdcInsn "Cannot create variant for null pointer") ;; (.visitMethodInsn Opcodes/INVOKESPECIAL "java/lang/IllegalStateException" "<init>" "(Ljava/lang/String;)V") ;; (.visitInsn Opcodes/ATHROW) (.visitMaxs 0 0) diff --git a/luxc/src/lux/host/generics.clj b/luxc/src/lux/host/generics.clj index 5dd95bb9b..9e0359760 100644 --- a/luxc/src/lux/host/generics.clj +++ b/luxc/src/lux/host/generics.clj @@ -172,7 +172,7 @@ (->bytecode-class-name name)) (&/$GenericArray param) - (assert false "gclass->bytecode-class-name* doesn't work on arrays.")))) + (assert false "gclass->bytecode-class-name* does not work on arrays.")))) (let [object-bc-name (->bytecode-class-name "java.lang.Object")] (defn gclass->bytecode-class-name [gclass] @@ -188,7 +188,7 @@ (->bytecode-class-name name) (&/$GenericArray param) - (assert false "gclass->bytecode-class-name doesn't work on arrays.")))) + (assert false "gclass->bytecode-class-name does not work on arrays.")))) (defn method-signatures [method-decl] (|let [[=name =anns =gvars =exceptions =inputs =output] method-decl diff --git a/luxc/src/lux/lexer.clj b/luxc/src/lux/lexer.clj index 2f9c0717e..58f8f95f7 100644 --- a/luxc/src/lux/lexer.clj +++ b/luxc/src/lux/lexer.clj @@ -101,7 +101,7 @@ (return pre-quotes**)) [pre-quotes post-quotes] (if (.endsWith pre-quotes* "\\") (if eol? - (&/fail-with-loc "[Lexer Error] Can't leave dangling back-slash \\") + (&/fail-with-loc "[Lexer Error] Cannot leave dangling back-slash \\") (if (if-let [^String back-slashes (re-find #"\\+$" pre-quotes*)] (odd? (.length back-slashes))) (|do [[_ eol?* _] (&reader/read-regex #"^([\"])") diff --git a/luxc/src/lux/optimizer.clj b/luxc/src/lux/optimizer.clj index a3ce2c089..9fc50646e 100644 --- a/luxc/src/lux/optimizer.clj +++ b/luxc/src/lux/optimizer.clj @@ -25,7 +25,7 @@ ;; These other tags represent higher-order constructs that manifest ;; themselves as patterns in the code. - ;; Lux doesn't formally provide these features, but some macros + ;; Lux does not formally provide these features, but some macros ;; expose ways to implement them in terms of the other (primitive) ;; features. ;; The optimizer looks for those usage patterns and transforms them @@ -59,7 +59,7 @@ ;; (possibly) branching path, where each step along the path ;; corresponds to a value, the ends of the path are the jumping-off ;; points for the bodies of branches, and branching decisions can be -;; backtracked, if they don't result in a valid jump. +;; backtracked, if they do not result in a valid jump. (defvariant ;; Throw away the current data-node (CDN). It's useless. ("PopPM" 0) @@ -213,7 +213,7 @@ (&a-case/$TupleTestAC _sub-tests) (|case _sub-tests - ;; An empty tuple corresponds to unit, which can't be tested in + ;; An empty tuple corresponds to unit, which cannot be tested in ;; any meaningful way, so it's just popped. (&/$Nil) (&/|list $PopPM) @@ -844,7 +844,7 @@ ;; [[Loop Optimizations]] -;; Lux doesn't offer any looping constructs, relying instead on +;; Lux does not offer any looping constructs, relying instead on ;; recursion. ;; Some common usages of recursion can be written more efficiently ;; just using regular loops/iteration. diff --git a/luxc/src/lux/parser.clj b/luxc/src/lux/parser.clj index 3323dadfc..3f0a95653 100644 --- a/luxc/src/lux/parser.clj +++ b/luxc/src/lux/parser.clj @@ -45,9 +45,9 @@ :let [elems (&/fold &/|++ &/$Nil elems*)]] (|case token [meta (&lexer/$Close_Brace _)] - (if (even? (&/|length elems)) - (return (&/$RecordS (&/|as-pairs elems))) - (&/fail-with-loc base-uneven-record-error)) + (|do [_ (&/assert! (even? (&/|length elems)) + (&/fail-with-loc base-uneven-record-error))] + (return (&/$RecordS (&/|as-pairs elems)))) _ (&/fail-with-loc "[Parser Error] Unbalanced braces.") diff --git a/luxc/src/lux/type.clj b/luxc/src/lux/type.clj index dd2e536bb..47b4b9c38 100644 --- a/luxc/src/lux/type.clj +++ b/luxc/src/lux/type.clj @@ -178,7 +178,7 @@ (&/$None) (return* state false)) - ((&/fail-with-loc (str "[Type Error] <bound?> Unknown type-var: " id)) + ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id)) state)))) (defn deref [id] @@ -191,7 +191,7 @@ (&/$None) ((&/fail-with-loc (str "[Type Error] Unbound type-var: " id)) state)) - ((&/fail-with-loc (str "[Type Error] <deref> Unknown type-var: " id)) + ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id)) state)))) (defn deref+ [type] @@ -210,7 +210,7 @@ (&/$Some bound) (if (type= type bound) (return* state nil) - ((&/fail-with-loc (str "[Type Error] Can't re-bind type var: " id " | Current type: " (show-type bound))) + ((&/fail-with-loc (str "[Type Error] Cannot re-bind type var: " id " | Current type: " (show-type bound))) state)) (&/$None) @@ -218,7 +218,7 @@ ts)) state) nil)) - ((&/fail-with-loc (str "[Type Error] <set-var> Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) + ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) state)))) (defn reset-var [id type] @@ -228,7 +228,7 @@ ts)) state) nil) - ((&/fail-with-loc (str "[Type Error] <set-var> Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) + ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) state)))) (defn unset-var [id] @@ -238,7 +238,7 @@ ts)) state) nil) - ((&/fail-with-loc (str "[Type Error] <set-var> Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) + ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id " | " (->> state (&/get$ &/$type-vars) (&/get$ &/$mappings) &/|length))) state)))) ;; [Exports] @@ -422,7 +422,7 @@ _ (&/fail-with-loc (str "[Type Error] Type is not a " <desc> ": " (show-type type)))))) - &/$SumT flatten-sum sum-at "Sum" + &/$SumT flatten-sum sum-at "Sum" &/$ProdT flatten-prod prod-at "Product" ) @@ -583,9 +583,9 @@ (|do [=expected (show-type+ expected) =actual (show-type+ actual)] (&/fail-with-loc (str (if (= "" err) err (str err "\n")) - "[Type Checker]\n" + "[Type Checker Error]\n" "Expected: " =expected "\n\n" - "Actual: " =actual + " Actual: " =actual "\n")))) (defn beta-reduce [env type] diff --git a/luxc/src/lux/type/host.clj b/luxc/src/lux/type/host.clj index 40a3373f0..e2f7c1c1f 100644 --- a/luxc/src/lux/type/host.clj +++ b/luxc/src/lux/type/host.clj @@ -114,9 +114,10 @@ (let [gvar (.getName ^TypeVariable refl-type)] (if-let [m-type (&/|get gvar matchings)] (return m-type) - (&/fail-with-loc (str "[Type Error] Unknown generic type variable: " gvar " -- " (->> matchings - (&/|map &/|first) - &/->seq))))) + (&/fail-with-loc (str "[Host Error] Unknown generic type-variable: " gvar "\n" + "Available type-variables: " (->> matchings + (&/|map &/|first) + &/->seq))))) (instance? WildcardType refl-type) (if-let [bound (->> ^WildcardType refl-type .getUpperBounds seq first)] @@ -175,9 +176,10 @@ (&/$GenericTypeVar var-name) (if-let [m-type (&/|get var-name matchings)] (return m-type) - (&/fail-with-loc (str "[Type Error] Unknown generic type variable: " var-name " -- " (->> matchings - (&/|map &/|first) - &/->seq)))) + (&/fail-with-loc (str "[Host Error] Unknown generic type-variable: " var-name "\n" + "Available type-variables: " (->> matchings + (&/|map &/|first) + &/->seq)))) (&/$GenericWildcard) existential)) @@ -231,7 +233,7 @@ (let [lineage (trace-lineage sub-class+ super-class+)] (|do [[^Class sub-class* sub-params*] (raise existential lineage sub-class+ sub-params)] (return (&/$HostT (.getName sub-class*) sub-params*)))) - (&/fail-with-loc (str "[Type Error] Classes don't have a subtyping relationship: " sub-class " </= " super-class))))) + (&/fail-with-loc (str "[Host Error] Classes do not have a subtyping relationship: " sub-class " </= " super-class))))) (defn as-obj [class] (case class |