A peer-to-peer stack for code collaboration
Re-enable stack traces
Luke Palmer9f84d5894384
diff --git a/rad/prelude/exception.rad b/rad/prelude/exception.radindex f721782..4ae9089 100644--- a/rad/prelude/exception.rad+++ b/rad/prelude/exception.rad@@ -1,5 +1,5 @@(should-be "catch handles scope correctly";; Issue #191, catch used to accidentally use the lexical environment of;; the `throw` that generated the exception.- ((fn [body handler] (catch 'any (body) handler)) (fn [] (throw 'foo "foo")) (fn [e] #t))+ ((fn [body handler] (catch 'any (body) handler)) (fn [] (throw 'foo "foo")) (fn [e stack] #t))#t)diff --git a/rad/prelude/list.rad b/rad/prelude/list.radindex d374f0e..60c5e4a 100644--- a/rad/prelude/list.rad+++ b/rad/prelude/list.rad@@ -107,3 +107,16 @@(f (head x))(g))(g))))+++;; imperative for each++(def-rec for-each (fn [ls cb]+ (if (empty? ls)+ nil+ (do (cb (head ls))+ (for-each (tail ls) cb)))))++(def for-each-vec (fn [v cb]+ (for-each (range 0 (- (length v) 1)) (fn [i]+ (cb (nth i v))))))diff --git a/rad/prelude/test.rad b/rad/prelude/test.radindex 17cabf1..4b9bc30 100644--- a/rad/prelude/test.rad+++ b/rad/prelude/test.rad@@ -2,7 +2,7 @@(def is-test-env"True iff file is being run as part of the Haskell suite"- (catch 'any (eq? test-env__ #t) (fn [x] #f)))+ (catch 'any (eq? test-env__ #t) (fn [x stack] #f)));; Annoyingly verbose since we have neither the prelude nor pattern-matching.(def evaldiff --git a/rad/repl.rad b/rad/repl.radindex 9520d77..4716d1a 100644--- a/rad/repl.rad+++ b/rad/repl.rad@@ -2,6 +2,10 @@;; The Repl+(def render-exception! (fn [e stack]+ (put-str! (string-append "Exception: " (show e)))+ (for-each-vec stack put-str!)))+(def repl (fn [](def-rec repl-rec (fn [st](def line (get-expression! (keys (lookup :env st))))@@ -11,8 +15,8 @@(catch 'any (do (def ret (cur-eval (read line) st))(print! (head ret))(repl-rec (head (tail ret))))- (fn [e] (put-str! (string-append "Exception " (show e)))- (repl-rec st))))))+ (fn [e stack] (render-exception! e stack)+ (repl-rec st))))))(repl-rec (get-current-env))))(repl)diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 14ba487..befdf1e 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -26,6 +26,7 @@ import qualified Data.Sequence as Seqimport Generics.Eotimport qualified GHC.Exts as GhcExtsimport qualified Text.Megaparsec.Error as Par+import Text.Megaparsec.Pos (sourcePosPretty)import Radicle.Internal.Annotation (Annotated)import qualified Radicle.Internal.Annotation as Ann@@ -477,11 +478,10 @@ specialForms = Map.fromList $ first Ident <$>mlabel <- baseEval lhandlerclo <- baseEval handlercase mlabel of- -- TODO reify stack- Atom label -> baseEval form `catchError` \(LangError _stack e) -> do+ Atom label -> baseEval form `catchError` \(LangError stack e) -> do(thrownLabel, thrownValue) <- errorDataToValue eif thrownLabel == label || label == Ident "any"- then handlerclo $$ [thrownValue]+ then handlerclo $$ [thrownValue, toRad stack]else baseEval form_ -> throwErrorHere $ TypeError "catch: first argument must be atom"xs -> throwErrorHere $ WrongNumberOfArgs "catch" 3 (length xs))@@ -628,10 +628,13 @@ instance ToRad Ann.WithPos (Bindings m) where[ (Keyword $ Ident "env", toRad $ bindingsEnv x), (Keyword $ Ident "refs", List $ IntMap.elems (bindingsRefs x))]+instance (CPA t) => ToRad t Ann.SrcPos where+ toRad (Ann.SrcPos p) = toRad (toS (sourcePosPretty p) :: Text)+ toRad (Ann.InternalPos p) = toRad p+-- * Helpers--- Loc is the source location of the application.callFn :: Monad m => Value -> [Value] -> Lang m ValuecallFn f vs = case f ofLambda bnds body closure ->diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex 9ac7b57..eeff75e 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -353,7 +353,7 @@ test_eval =, testCase "'catch' catches thrown exceptions" $ dolet prog = [s|- (catch (quote exc) (throw (quote exc) #t) (fn [y] y))+ (catch (quote exc) (throw (quote exc) #t) (fn [y stack] y))|]prog `succeedsWith` Boolean True@@ -361,13 +361,13 @@ test_eval =let prog = [s|(def t #t)(def f #f)- (catch (quote exc) (throw (quote exc) f) (fn [y] t))+ (catch (quote exc) (throw (quote exc) f) (fn [y stack] t))|]prog `succeedsWith` Boolean True, testCase "'catch 'any' catches any exception" $ dolet prog = [s|- (catch 'any (throw (quote exc) #f) (fn [y] #t))+ (catch 'any (throw (quote exc) #f) (fn [y stack] #t))|]prog `succeedsWith` Boolean True@@ -619,7 +619,7 @@ test_repl_primops =, testCase "catch catches read-line errors" $ dolet prog = [s|- (catch 'any (read-line!) (fn [x] "caught"))+ (catch 'any (read-line!) (fn [x stack] "caught"))|]input = ["\"blah"]res = run input prog