Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Dan Holtby
uwaterloo-racket
Commits
09786019
Commit
09786019
authored
Nov 14, 2020
by
Dan Holtby
Browse files
Make trace work with local (and other lifting transforms)
parent
69cece4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
trace.rkt
View file @
09786019
...
...
@@ -3,22 +3,6 @@
(
require
racket/trace
(
for-syntax
racket/base
))
(
provide
define/trace
)
;; maps the hidden names to the original names
(
define
cs135-tracemap
(
make-hasheq
))
;; alters trace so that when printing name, it consults the cs135-tracemap
(
let
([
default-trace-res
(
current-trace-print-results
)]
[
default-trace-args
(
current-trace-print-args
)])
(
current-trace-print-results
(
λ
(
name
results
depth
)
(
default-trace-res
(
hash-ref
cs135-tracemap
name
name
)
results
depth
)))
(
current-trace-print-args
(
λ
(
name
args
kw-names
kw-values
depth
)
(
default-trace-args
(
hash-ref
cs135-tracemap
name
name
)
args
kw-names
kw-values
depth
))))
(
define-syntax
(
define/trace
stx
)
(
syntax-case
stx
()
[(
_
(
f
)
body
extra-part
...
)
;; put this first since arg ... means 0 or more
...
...
@@ -30,13 +14,14 @@
; break hygiene to snag define from the current lexical context
([
student-define
(
datum->syntax
stx
'define
)]
; generate a fake name for the real function. temporaries are always distinct
[(
f1
)
(
generate-temporaries
#'
(
f
))])
[
f1
(
syntax-local-lift-expression
(
syntax/loc
stx
(
letrec
([
f
(
λ
(
arg
...
)
body
)])
(
trace
f
)
f
)))])
(
syntax/loc
stx
(
begin
(
define
(
f1
arg
...
)
body
)
(
trace
f1
)
(
hash-set!
cs135-tracemap
'f1
'f
)
(
student-define
(
f
arg
...
)
(
f1
arg
...
)))))]
(
student-define
(
f
arg
...
)
(
f1
arg
...
))))]
[(
_
name
value
)
; if they try to use it to define a constant
(
raise-syntax-error
'define/trace
"define/trace can only be used to define functions"
stx
)]
[(
_
arg
...
)
; other cases it just maps to a define so that that syntax can raise its own errors
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment