From a6afe8aaa95fb8685a402709c1ddcd5bee7219d6 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 26 Nov 2016 18:03:00 -0400 Subject: - Now better catching any runtime errors related to compiled defs. - The hashes of def-names will always be "nats" now. - Changed the way host types are turned into text. --- src/lux/analyser/host.clj | 1 + src/lux/compiler/lux.clj | 17 +++++++++++++++-- src/lux/host.clj | 2 +- src/lux/type.clj | 4 ++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj index 180e3ef54..209e36d0e 100644 --- a/src/lux/analyser/host.clj +++ b/src/lux/analyser/host.clj @@ -2,6 +2,7 @@ ;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ;; If a copy of the MPL was not distributed with this file, ;; You can obtain one at http://mozilla.org/MPL/2.0/. + (ns lux.analyser.host (:require (clojure [template :refer [do-template]] [string :as string]) diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj index 9d5837fe2..5dc8becc0 100644 --- a/src/lux/compiler/lux.clj +++ b/src/lux/compiler/lux.clj @@ -243,6 +243,17 @@ _ optim)) +(defn ^:private throwable->text [^Throwable t] + (let [base (->> t + .getStackTrace + (map str) + (cons (.getMessage t)) + (interpose "\n") + (apply str))] + (if-let [cause (.getCause t)] + (str base "\n\n" "Caused by: " (throwable->text cause)) + base))) + (let [class-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) field-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC)] (defn compile-def [compile ?name ?body ?meta] @@ -374,8 +385,10 @@ _ false) - def-meta ?meta - def-value (-> def-class (.getField &/value-field) (.get nil))] + def-meta ?meta] + def-value (try (return (-> def-class (.getField &/value-field) (.get nil))) + (catch Throwable t + (&/assert! false (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)]) diff --git a/src/lux/host.clj b/src/lux/host.clj index 3c8cef536..39e659964 100644 --- a/src/lux/host.clj +++ b/src/lux/host.clj @@ -159,7 +159,7 @@ (&/T [(.getName =method) (&/|map #(.getName ^Class %) (&/->list (seq (.getParameterTypes =method))))])))))) (defn def-name [name] - (str (&/normalize-name name) "_" (hash name))) + (str (&/normalize-name name) "_" (Long/toUnsignedString (hash name)))) (defn location [scope] (let [scope (&/$Cons (def-name (&/|head scope)) diff --git a/src/lux/type.clj b/src/lux/type.clj index ad76fbadc..d387053dc 100644 --- a/src/lux/type.clj +++ b/src/lux/type.clj @@ -422,10 +422,10 @@ (&/$HostT name params) (|case params (&/$Nil) - (str "(^ " name ")") + (str "(host " name ")") _ - (str "(^ " name " " (->> params (&/|map show-type) (&/|interpose " ") (&/fold str "")) ")")) + (str "(host " name " " (->> params (&/|map show-type) (&/|interpose " ") (&/fold str "")) ")")) (&/$VoidT) "Void" -- cgit v1.2.3