macro-stepper: added api for macro "remarks" (no docs yet)

original commit: 2068acc22b65415072d753828d182e970b7def0b
This commit is contained in:
Ryan Culpepper 2010-06-09 16:04:28 -06:00
parent 50d21a212d
commit cedc2417f4
8 changed files with 72 additions and 3 deletions

View File

@ -0,0 +1,22 @@
#lang racket/base
(require racket/contract/base)
(provide/contract
[emit-remark
(->* () (#:unmark? any/c) #:rest (listof (or/c string? syntax?))
any)])
(define current-expand-observe
(dynamic-require ''#%expobs 'current-expand-observe))
(define (emit-remark #:unmark? [unmark? #t] . args)
(let ([observe (current-expand-observe)])
(when observe
(let ([args
(if unmark?
(for/list ([arg (in-list args)])
(if (syntax? arg)
(syntax-local-introduce arg)
arg))
args)])
(observe 'local-remark args)))))

View File

@ -40,6 +40,8 @@
(define-struct local-lift-require (req expr mexpr) #:transparent) (define-struct local-lift-require (req expr mexpr) #:transparent)
(define-struct local-lift-provide (prov) #:transparent) (define-struct local-lift-provide (prov) #:transparent)
(define-struct local-bind (names ?1 renames bindrhs) #:transparent) (define-struct local-bind (names ?1 renames bindrhs) #:transparent)
(define-struct local-remark (contents) #:transparent)
;; contents : (listof (U string syntax))
;; A PrimDeriv is one of ;; A PrimDeriv is one of
(define-struct (prule base) () #:transparent) (define-struct (prule base) () #:transparent)

View File

@ -202,6 +202,8 @@
(make local-bind $1 $2 $3 #f)] (make local-bind $1 $2 $3 #f)]
[(local-bind rename-list (? BindSyntaxes)) [(local-bind rename-list (? BindSyntaxes))
(make local-bind $1 #f $2 $3)] (make local-bind $1 #f $2 $3)]
[(local-remark)
(make local-remark $1)]
;; -- Not really local actions, but can occur during evaluation ;; -- Not really local actions, but can occur during evaluation
;; called 'expand' (not 'local-expand') within transformer ;; called 'expand' (not 'local-expand') within transformer
[(start (? EE)) #f] [(start (? EE)) #f]

View File

@ -59,6 +59,8 @@
top-begin ; identifier top-begin ; identifier
top-non-begin ; . top-non-begin ; .
local-remark ; (listof (U string syntax))
)) ))
(define-tokens renames-tokens (define-tokens renames-tokens
@ -93,6 +95,7 @@
(#f start ,token-start) (#f start ,token-start)
(#f top-begin ,token-top-begin) (#f top-begin ,token-top-begin)
(#f top-non-begin ,token-top-non-begin) (#f top-non-begin ,token-top-non-begin)
(#f local-remark ,token-local-remark)
;; Standard signals ;; Standard signals
(0 visit ,token-visit) (0 visit ,token-visit)

View File

@ -60,6 +60,9 @@
[#:foci1 syntaxish? #:foci2 syntaxish?] [#:foci1 syntaxish? #:foci2 syntaxish?]
. ->* . step?)] . ->* . step?)]
[stumble ([syntaxish? exn?] [#:focus syntaxish?] . ->* . misstep?)] [stumble ([syntaxish? exn?] [#:focus syntaxish?] . ->* . misstep?)]
[walk/talk
(-> (or/c symbol? string?) (listof (or/c syntax? string? 'arrow))
remarkstep?)]
[current-pass-hides? (parameterlike/c boolean?)] [current-pass-hides? (parameterlike/c boolean?)]
@ -343,6 +346,11 @@
(current-state-with stx focus) (current-state-with stx focus)
exn)) exn))
(define (walk/talk type contents)
(make remarkstep type
(current-state-with #f null)
contents))
(define (foci x) (define (foci x)
(cond [(syntax? x) (cond [(syntax? x)
(list x)] (list x)]

View File

@ -419,7 +419,15 @@
;; FIXME: add action ;; FIXME: add action
(R [#:do (take-lift!)] (R [#:do (take-lift!)]
[#:binders ids] [#:binders ids]
[#:reductions (list (walk expr ids 'local-lift))])] [#:reductions
(list
(walk/talk 'local-lift
(list "The macro lifted an expression"
""
"Expression:"
expr
"Identifiers:"
(datum->syntax #f ids))))])]
[(struct local-lift-end (decl)) [(struct local-lift-end (decl))
;; (walk/mono decl 'module-lift) ;; (walk/mono decl 'module-lift)
@ -436,7 +444,9 @@
[R [! ?1] [R [! ?1]
;; FIXME: use renames ;; FIXME: use renames
[#:binders names] [#:binders names]
[#:when bindrhs => (BindSyntaxes bindrhs)]]])) [#:when bindrhs => (BindSyntaxes bindrhs)]]]
[(struct local-remark (contents))
(R [#:reductions (list (walk/talk 'remark contents))])]))
;; List : ListDerivation -> RST ;; List : ListDerivation -> RST
(define (List ld) (define (List ld)

View File

@ -1,10 +1,10 @@
#lang scheme/base #lang scheme/base
(require "deriv.ss" (require "deriv.ss"
"deriv-util.ss") "deriv-util.ss")
(provide (struct-out protostep) (provide (struct-out protostep)
(struct-out step) (struct-out step)
(struct-out misstep) (struct-out misstep)
(struct-out remarkstep)
(struct-out state) (struct-out state)
(struct-out bigframe) (struct-out bigframe)
context-fill context-fill
@ -22,9 +22,11 @@
;; A Step is one of ;; A Step is one of
;; - (make-step StepType State State) ;; - (make-step StepType State State)
;; - (make-misstep StepType State exn) ;; - (make-misstep StepType State exn)
;; - (make-remarkstep StepType State (listof (U string syntax 'arrow)))
(define-struct protostep (type s1) #:transparent) (define-struct protostep (type s1) #:transparent)
(define-struct (step protostep) (s2) #:transparent) (define-struct (step protostep) (s2) #:transparent)
(define-struct (misstep protostep) (exn) #:transparent) (define-struct (misstep protostep) (exn) #:transparent)
(define-struct (remarkstep protostep) (contents) #:transparent)
;; A State is ;; A State is
;; (make-state stx stxs Context BigContext (listof id) (listof id) (listof stx) nat/#f) ;; (make-state stx stxs Context BigContext (listof id) (listof id) (listof stx) nat/#f)
@ -89,6 +91,8 @@
(splice-lifts . "Splice definitions from lifted expressions") (splice-lifts . "Splice definitions from lifted expressions")
(splice-module-lifts . "Splice lifted module declarations") (splice-module-lifts . "Splice lifted module declarations")
(remark . "Macro made a remark")
(error . "Error"))) (error . "Error")))
(define (step-type->string x) (define (step-type->string x)

View File

@ -87,6 +87,8 @@
(show-step step shift-table)] (show-step step shift-table)]
[(misstep? step) [(misstep? step)
(show-misstep step shift-table)] (show-misstep step shift-table)]
[(remarkstep? step)
(show-remarkstep step shift-table)]
[(prestep? step) [(prestep? step)
(show-prestep step shift-table)] (show-prestep step shift-table)]
[(poststep? step) [(poststep? step)
@ -229,6 +231,22 @@
#:shift-table shift-table))) #:shift-table shift-table)))
(show-lctx step shift-table)) (show-lctx step shift-table))
(define/private (show-remarkstep step shift-table)
(define state (protostep-s1 step))
(for ([content (in-list (remarkstep-contents step))])
(cond [(string? content)
(send*: sbview sb:syntax-browser<%>
(add-text content)
(add-text "\n"))]
[(syntax? content)
(send*: sbview sb:syntax-browser<%>
(add-syntax content
#:binders (or (state-binders state) null)
#:definites (or (state-uses state) null)
#:shift-table shift-table)
(add-text "\n"))]))
(show-lctx step shift-table))
;; insert-syntax/color ;; insert-syntax/color
(define/private (insert-syntax/color stx foci binders shift-table (define/private (insert-syntax/color stx foci binders shift-table
definites frontier hi-color) definites frontier hi-color)