Commit 09786019 authored by Dan Holtby's avatar Dan Holtby
Browse files

Make trace work with local (and other lifting transforms)

parent 69cece4c
......@@ -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)])
(λ (name results depth)
(default-trace-res (hash-ref cs135-tracemap name name) results depth)))
(λ (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))])
(syntax/loc stx
(letrec ([f (λ (arg ...) body)])
(trace f)
(syntax/loc stx
(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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment