Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic stack traces #261

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wrk: up to macros
  • Loading branch information
doyougnu committed Jan 8, 2025
commit dae9ffeba44ec7a80d382a6b76ca99d64d027263
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User error; no such file: "/home/doyougnu/programming/klister/examples/non-examples/stack-traces/doyougnu@7thChamber.38408:1735135986"
6 changes: 6 additions & 0 deletions examples/non-examples/stack-traces/error-in-cons-head.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/home/doyougnu/programming/klister/examples/non-examples/stack-traces/error-in-cons-head.kl:12:11:
|
12 | [(l . j) (error 'Im-an-error)]
| ^
unexpected '.'
expecting "#%app", "#%integer-literal", "#%module", "#%string-literal", ",@", "...", '"', ''', '(', ')', '+', ',', '-', '[', '`', identifier-initial character, or integer (digits)
10 changes: 10 additions & 0 deletions examples/non-examples/stack-traces/error-in-cons-head.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#lang "prelude.kl"

(import "lambda-case.kl")

-- TODO: DYG: how to test the pairs?
(define fail
(lambda (thing)
(car '(1 2 'something-else))))

(example (fail 3))
2 changes: 2 additions & 0 deletions examples/non-examples/stack-traces/error-in-list.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Internal error during expansion! This is a bug in the implementation.
All patterns should be identifier-headed
13 changes: 13 additions & 0 deletions examples/non-examples/stack-traces/error-in-list.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#lang "prelude.kl"

(import "defun.kl")
(import "list.kl")

(define thing 'nothing)
(define the-error (error 'Im-an-error))

(defun fail (thing) (+ 1 thing))

-- TODO: DYG: how to test
-- (example `(list-syntax (,thing (fail the-error) ()) thing))
(example `('a 'b ,the-error))
4 changes: 2 additions & 2 deletions src/Evaluator.hs
Original file line number Diff line number Diff line change
@@ -159,8 +159,8 @@ data Kont where
InDataCaseScrut :: ![(ConstructorPattern, Core)] -> !SrcLoc -> !VEnv -> !Kont -> Kont
InTypeCaseScrut :: ![(TypePattern, Core)] -> !SrcLoc -> !VEnv -> !Kont -> Kont

{- Note [InCasePattern
In case pattern is strictly not necessary, we could do this evalaution in
{- Note [InCasePattern]
In case pattern is strictly not necessary, we could do this evaluation in
the host's runtime instead of in the evaluator but doing so would mean that
the debugger would not be able to capture the pattern that was matched.
-}
81 changes: 74 additions & 7 deletions src/Expander/Error.hs
Original file line number Diff line number Diff line change
@@ -303,18 +303,30 @@ printStack e (Er err _env k) =
printStack _ Up{} = hang 2 $ text "up"
printStack _ Down{} = hang 2 $ text "down"

-- the basics
printKont _ Halt = text "Halt"
printKont e (InFun arg _env k) = text "with arg" <+> pp e arg <> pp e k
printKont e (InArg fun _env k) = text "with function" <+> pp e fun <> pp e k
printKont e (InLetDef name var body _env k) = text "in let" <+> pp e name
printKont e (InLetDef name _var body _env k) = text "in let" <+> pp e name
<> pp e body <> pp e k

-- constructors
printKont e (InCtor field_vals con _f_to_process _env k) =
let position = length field_vals + 1
in text "in constructor" <+>
align (vsep [pp e con, text "in field" <+> viaShow position]) <> pp e k

-- cases
printKont e (InCaseScrut cases loc _env k) =
let do_case c = (fst $ ppBind e (fst c)) <> pp e (snd c)
in text "in case" <> pp e loc <> foldMap do_case cases <> pp e k
-- TODO: DYG: is data|type case different than case in the concrete syntax?
printKont e (InDataCaseScrut cases loc _env k) =
let do_case c = (fst $ ppBind e (fst c)) <> pp e (snd c)
in text "in data case" <> pp e loc <> foldMap do_case cases <> pp e k
printKont e (InTypeCaseScrut cases loc _env k) =
let do_case c = (fst $ ppBind e (fst c)) <> pp e (snd c)
in text "in type case" <> pp e loc <> foldMap do_case cases <> pp e k
printKont e (InCasePattern p k) =
let ppPattern = \case
SyntaxPatternIdentifier i _ -> pp e i
@@ -333,11 +345,66 @@ printKont e (InDataCasePattern p k) =
<> ppPattern (unConstructorPattern p)
<> pp e k

-- printErr :: EvalError -> Doc ann
-- printErr = pretty
-- pairs
-- TODO: DYG: how to test the cons?
printKont e (InConsHd scope hd _env k) =
vsep [ text "in head of pair"
, nest 2 $ pp e hd
, text "in scope"
, nest 2 $ pp e scope
]
<> pp e k
printKont e (InConsTl scope hd _env k) =
vsep [ text "in tail of pair"
, nest 2 $ pp e hd
, text "in scope"
, nest 2 $ pp e scope
]
<> pp e k

-- lists
printKont e (InList scope _todos dones _env k) =
vsep [ text "in list"
, nest 2 $ foldMap (pp e) dones
, text "in scope"
, nest 2 $ pp e scope
]
<> pp e k

-- idents
-- TODO: DYG: how to report?
printKont e (InIdent scope _env k) =
vsep [ text "in ident"
, text "in scope"
, nest 2 $ pp e scope
]
<> pp e k
printKont e (InIdentEqL _how scope _env k) =
vsep [ text "in ident eq left"
, text "in scope"
, nest 2 $ pp e scope
]
<> pp e k
printKont e (InIdentEqR other _how _env k) =
vsep [ text "in ident eq right, comparing: " <> pp e other
]
<> pp e k

-- macros
printKont e (InPureMacro env k) =
vsep [ text "in pure macro" -- TODO: needs a passthrough?
]
<> pp e k
printKont e (InBindMacroHd tl env k) =
vsep [ text "in bind macro head" -- TODO: needs a passthrough?
, pp e tl
]
<> pp e k
printKont e (InBindMacroTl action env k) =
vsep [ text "in bind macro tail" -- TODO: needs a passthrough?
, pp e action
]
<> pp e k

-- printEnv :: VEnv -> Doc ann
-- printEnv = pretty

-- START: implement printer for the rest of kont indentation was clobbered by
-- the 'group' operation
-- START: figure out how to test the cons cases