macro debugger: reorg, minor bug fixes
svn: r12825 original commit: 12216b15aaabdc69615ec38a5886c90579af6718
This commit is contained in:
parent
fdd704dd9e
commit
c715df4d97
|
@ -5,7 +5,8 @@
|
|||
"interfaces.ss"
|
||||
"../util/notify.ss"
|
||||
"../util/misc.ss")
|
||||
(provide syntax-prefs-base%
|
||||
(provide prefs-base%
|
||||
syntax-prefs-base%
|
||||
syntax-prefs%
|
||||
syntax-prefs/readonly%)
|
||||
|
||||
|
@ -19,7 +20,7 @@
|
|||
(pref:get/set pref:props-percentage SyntaxBrowser:PropertiesPanelPercentage)
|
||||
(pref:get/set pref:props-shown? SyntaxBrowser:PropertiesPanelShown)
|
||||
|
||||
(define syntax-prefs-base%
|
||||
(define prefs-base%
|
||||
(class object%
|
||||
;; columns : number
|
||||
(field/notify columns (new notify-box% (value 60)))
|
||||
|
@ -41,6 +42,10 @@
|
|||
"indigo" "purple"
|
||||
"orange" "salmon" "darkgoldenrod" "olive"))))
|
||||
|
||||
(super-new)))
|
||||
|
||||
(define syntax-prefs-base%
|
||||
(class prefs-base%
|
||||
;; width, height : number
|
||||
(notify-methods width)
|
||||
(notify-methods height)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
(module syntax-snip mzscheme
|
||||
(require mzlib/class
|
||||
#lang scheme/base
|
||||
(require scheme/class
|
||||
scheme/match
|
||||
scheme/list
|
||||
mzlib/string
|
||||
mred
|
||||
framework
|
||||
mzlib/match
|
||||
mzlib/list
|
||||
mzlib/string
|
||||
"../util/notify.ss"
|
||||
"interfaces.ss"
|
||||
"display.ss"
|
||||
|
@ -19,33 +19,22 @@
|
|||
syntax-value-snip%)
|
||||
|
||||
(define syntax-snip-config-base%
|
||||
(class object%
|
||||
(class prefs-base%
|
||||
(notify-methods props-shown?)
|
||||
(super-new)))
|
||||
|
||||
(define syntax-snip-config%
|
||||
(class syntax-snip-config-base%
|
||||
(define/override (init-props-shown?) (new notify-box% (value #f)))
|
||||
(super-new)))
|
||||
|
||||
(define dumb-host%
|
||||
(class object%
|
||||
(define controller (new controller%))
|
||||
(define config (new syntax-snip-config%))
|
||||
(super-new)
|
||||
(define/public (get-controller) controller)
|
||||
(define/public (get-config) config)
|
||||
(define/public (add-keymap text snip)
|
||||
(send text set-keymap
|
||||
(new syntax-keymap%
|
||||
(controller controller)
|
||||
(editor text)
|
||||
(config config))))))
|
||||
|
||||
;; syntax-value-snip%
|
||||
(define syntax-value-snip%
|
||||
(class* editor-snip% (readable-snip<%>)
|
||||
(init-field ((stx syntax)))
|
||||
(init-field (host (new dumb-host%)))
|
||||
(init-field (controller (new controller%)))
|
||||
(init-field (config (new syntax-snip-config%)))
|
||||
|
||||
(inherit set-margin
|
||||
set-inset)
|
||||
|
||||
|
@ -60,18 +49,25 @@
|
|||
(send text begin-edit-sequence)
|
||||
(send text change-style (make-object style-delta% 'change-alignment 'top))
|
||||
(define display
|
||||
(print-syntax-to-editor stx text
|
||||
(send host get-controller)
|
||||
(send host get-config)))
|
||||
(print-syntax-to-editor stx text controller config))
|
||||
(send text lock #t)
|
||||
(send text end-edit-sequence)
|
||||
(send text hide-caret #t)
|
||||
|
||||
(send host add-keymap text this)
|
||||
(setup-keymap text)
|
||||
|
||||
(define/public (setup-keymap text)
|
||||
(new syntax-keymap%
|
||||
(controller controller)
|
||||
(config config)
|
||||
(editor text)))
|
||||
|
||||
;; snip% Methods
|
||||
(define/override (copy)
|
||||
(new syntax-value-snip% (host host) (syntax stx)))
|
||||
(new syntax-value-snip%
|
||||
(config config)
|
||||
(controller controller)
|
||||
(syntax stx)))
|
||||
|
||||
;; read-special : any number/#f number/#f number/#f -> syntax
|
||||
;; Produces 3D syntax to preserve eq-ness of syntax
|
||||
|
@ -167,15 +163,17 @@
|
|||
(define syntax-snip%
|
||||
(class* clicky-snip% (readable-snip<%>)
|
||||
(init-field ((stx syntax)))
|
||||
(init-field (host (new dumb-host%)))
|
||||
(define config (send host get-config))
|
||||
(init-field [controller (new controller%)])
|
||||
(init-field [config (new syntax-snip-config%)])
|
||||
|
||||
(inherit set-snipclass
|
||||
refresh-contents)
|
||||
|
||||
(define the-syntax-snip
|
||||
(new syntax-value-snip%
|
||||
(syntax stx)
|
||||
(host host)))
|
||||
(controller controller)
|
||||
(config config)))
|
||||
(define the-summary
|
||||
(let* ([t (new text%)]
|
||||
[es (new editor-snip% (editor t) (with-border? #f))])
|
||||
|
@ -186,7 +184,7 @@
|
|||
|
||||
(define properties-snip
|
||||
(new properties-container-snip%
|
||||
(controller (send host get-controller))))
|
||||
(controller controller)))
|
||||
|
||||
(define/override (closed-contents)
|
||||
(list the-summary))
|
||||
|
@ -211,8 +209,8 @@
|
|||
(lambda (?) (refresh-contents)))
|
||||
|
||||
(super-new)
|
||||
(set-snipclass snip-class)))
|
||||
|
||||
(set-snipclass snip-class)
|
||||
))
|
||||
|
||||
(define properties-container-snip%
|
||||
(class clicky-snip%
|
||||
|
@ -316,11 +314,11 @@
|
|||
(column ,col)
|
||||
(span ,span)
|
||||
(original? ,original?)
|
||||
(properties ,@(properties ...))
|
||||
(properties . ,properties)
|
||||
(contents ,contents))
|
||||
(foldl
|
||||
add-properties
|
||||
(datum->syntax-object
|
||||
(datum->syntax
|
||||
#'here ;; ack
|
||||
(unmarshall-object contents)
|
||||
(list (unmarshall-object src)
|
||||
|
@ -359,5 +357,3 @@
|
|||
[(syntax) (unmarshall-syntax obj)]
|
||||
[else (unknown)])
|
||||
(unknown))))
|
||||
|
||||
)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
#lang mzscheme
|
||||
#lang scheme/base
|
||||
(require scheme/class
|
||||
mred
|
||||
framework/framework
|
||||
scheme/list
|
||||
scheme/match
|
||||
mzlib/kw
|
||||
syntax/boundmap
|
||||
"interfaces.ss"
|
||||
"controller.ss"
|
||||
|
@ -14,7 +13,8 @@
|
|||
"hrule-snip.ss"
|
||||
"properties.ss"
|
||||
"text.ss"
|
||||
"util.ss")
|
||||
"util.ss"
|
||||
"../util/mpi.ss")
|
||||
(provide widget%)
|
||||
|
||||
;; widget%
|
||||
|
@ -104,27 +104,27 @@
|
|||
(send -text set-clickback a b handler)
|
||||
(send -text change-style clickback-style a b)))))
|
||||
|
||||
(define/public add-syntax
|
||||
(lambda/kw (stx #:key [hi-stxs null] hi-color alpha-table [definites null]
|
||||
hi2-color [hi2-stxs null])
|
||||
(define/public (add-syntax stx
|
||||
#:alpha-table alpha-table
|
||||
#:definites [definites null]
|
||||
#:hi-colors [hi-colors null]
|
||||
#:hi-stxss [hi-stxss null])
|
||||
(define (get-binder id)
|
||||
(module-identifier-mapping-get alpha-table id (lambda () #f)))
|
||||
(when (and (pair? hi-stxs) (not hi-color))
|
||||
(error 'syntax-widget%::add-syntax "no highlight color specified"))
|
||||
(let ([display (internal-add-syntax stx)]
|
||||
[definite-table (make-hash-table)])
|
||||
(when (and hi2-color (pair? hi2-stxs))
|
||||
(send display highlight-syntaxes hi2-stxs hi2-color))
|
||||
(when (and hi-color (pair? hi-stxs))
|
||||
[definite-table (make-hasheq)])
|
||||
(for-each (lambda (hi-stxs hi-color)
|
||||
(send display highlight-syntaxes hi-stxs hi-color))
|
||||
(for-each (lambda (x) (hash-table-put! definite-table x #t)) definites)
|
||||
hi-stxss
|
||||
hi-colors)
|
||||
(for-each (lambda (x) (hash-set! definite-table x #t)) definites)
|
||||
(when alpha-table
|
||||
(let ([range (send display get-range)]
|
||||
[start (send display get-start-position)])
|
||||
(define (adjust n) (+ start n))
|
||||
(for-each
|
||||
(lambda (id)
|
||||
#; ;; DISABLED
|
||||
(when #f ;; DISABLED
|
||||
(match (identifier-binding id)
|
||||
[(list src-mod src-name nom-mod nom-name _)
|
||||
(for-each (lambda (id-r)
|
||||
|
@ -133,18 +133,17 @@
|
|||
(adjust (cdr id-r))
|
||||
(string-append "from "
|
||||
(mpi->string src-mod))
|
||||
(if (hash-table-get definite-table id #f)
|
||||
(if (hash-ref definite-table id #f)
|
||||
"blue"
|
||||
"purple")))
|
||||
(send range get-ranges id))]
|
||||
[_ (void)])
|
||||
|
||||
[_ (void)]))
|
||||
(let ([binder (get-binder id)])
|
||||
(when binder
|
||||
(for-each
|
||||
(lambda (binder-r)
|
||||
(for-each (lambda (id-r)
|
||||
(if (hash-table-get definite-table id #f)
|
||||
(if (hash-ref definite-table id #f)
|
||||
(send -text add-arrow
|
||||
(adjust (car binder-r))
|
||||
(adjust (cdr binder-r))
|
||||
|
@ -160,7 +159,7 @@
|
|||
(send range get-ranges id)))
|
||||
(send range get-ranges binder)))))
|
||||
(send range get-identifier-list))))
|
||||
display)))
|
||||
display))
|
||||
|
||||
(define/public (add-separator)
|
||||
(with-unlock -text
|
||||
|
|
246
collects/macro-debugger/view/step-display.ss
Normal file
246
collects/macro-debugger/view/step-display.ss
Normal file
|
@ -0,0 +1,246 @@
|
|||
|
||||
#lang scheme/base
|
||||
(require scheme/class
|
||||
scheme/unit
|
||||
scheme/list
|
||||
scheme/match
|
||||
scheme/gui
|
||||
framework/framework
|
||||
syntax/boundmap
|
||||
"interfaces.ss"
|
||||
"prefs.ss"
|
||||
"extensions.ss"
|
||||
"warning.ss"
|
||||
"hiding-panel.ss"
|
||||
"../model/deriv.ss"
|
||||
"../model/deriv-util.ss"
|
||||
"../model/deriv-find.ss"
|
||||
"../model/deriv-parser.ss"
|
||||
"../model/trace.ss"
|
||||
"../model/reductions-config.ss"
|
||||
"../model/reductions.ss"
|
||||
"../model/steps.ss"
|
||||
"../util/notify.ss"
|
||||
"cursor.ss"
|
||||
"debug-format.ss")
|
||||
#;
|
||||
(provide step-display%
|
||||
step-display<%>)
|
||||
(provide (all-defined-out))
|
||||
;; Struct for one-by-one stepping
|
||||
|
||||
(define-struct (prestep protostep) ())
|
||||
(define-struct (poststep protostep) ())
|
||||
|
||||
(define (prestep-term1 s) (state-term (protostep-s1 s)))
|
||||
(define (poststep-term2 s) (state-term (protostep-s1 s)))
|
||||
|
||||
|
||||
(define step-display<%>
|
||||
(interface ()
|
||||
;; add-syntax
|
||||
add-syntax
|
||||
|
||||
;; add-step
|
||||
add-step
|
||||
|
||||
;; add-error
|
||||
add-error
|
||||
|
||||
;; add-final
|
||||
add-final
|
||||
|
||||
;; add-internal-error
|
||||
add-internal-error))
|
||||
|
||||
(define step-display%
|
||||
(class* object% (step-display<%>)
|
||||
|
||||
(init-field config)
|
||||
(init-field ((sbview syntax-widget)))
|
||||
(super-new)
|
||||
|
||||
(define/public (add-internal-error part exn stx events)
|
||||
(send sbview add-text
|
||||
(if part
|
||||
(format "Macro stepper error (~a)" part)
|
||||
"Macro stepper error"))
|
||||
(when (exn? exn)
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-clickback "[details]"
|
||||
(lambda _ (show-internal-error-details exn events))))
|
||||
(send sbview add-text ". ")
|
||||
(when stx (send sbview add-text "Original syntax:"))
|
||||
(send sbview add-text "\n")
|
||||
(when stx (send sbview add-syntax stx)))
|
||||
|
||||
(define/private (show-internal-error-details exn events)
|
||||
(case (message-box/custom "Macro stepper internal error"
|
||||
(format "Internal error:\n~a" (exn-message exn))
|
||||
"Show error"
|
||||
"Dump debugging file"
|
||||
"Cancel")
|
||||
((1) (queue-callback
|
||||
(lambda ()
|
||||
(raise exn))))
|
||||
((2) (queue-callback
|
||||
(lambda ()
|
||||
(let ([file (put-file)])
|
||||
(when file
|
||||
(write-debug-file file exn events))))))
|
||||
((3 #f) (void))))
|
||||
|
||||
(define/public (add-error exn)
|
||||
(send sbview add-error-text (exn-message exn))
|
||||
(send sbview add-text "\n"))
|
||||
|
||||
(define/public (add-step step
|
||||
#:binders binders)
|
||||
(cond [(step? step)
|
||||
(show-step step binders)]
|
||||
[(misstep? step)
|
||||
(show-misstep step binders)]
|
||||
[(prestep? step)
|
||||
(show-prestep step binders)]
|
||||
[(poststep? step)
|
||||
(show-poststep step binders)]))
|
||||
|
||||
(define/public (add-syntax stx
|
||||
#:binders binders
|
||||
#:definites definites)
|
||||
(send sbview add-syntax stx
|
||||
#:alpha-table binders
|
||||
#:definites (or definites null)))
|
||||
|
||||
(define/public (add-final stx error
|
||||
#:binders binders
|
||||
#:definites definites)
|
||||
(when stx
|
||||
(send sbview add-text "Expansion finished\n")
|
||||
(send sbview add-syntax stx
|
||||
#:alpha-table binders
|
||||
#:definites (or definites null)))
|
||||
(when error
|
||||
(add-error error)))
|
||||
|
||||
;; show-lctx : Step -> void
|
||||
(define/private (show-lctx step binders)
|
||||
(define state (protostep-s1 step))
|
||||
(define lctx (state-lctx state))
|
||||
(when (pair? lctx)
|
||||
(send sbview add-text "\n")
|
||||
(for-each (lambda (bf)
|
||||
(send sbview add-text
|
||||
"while executing macro transformer in:\n")
|
||||
(insert-syntax/redex (bigframe-term bf)
|
||||
(bigframe-foci bf)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
(reverse lctx))))
|
||||
|
||||
;; separator : Step -> void
|
||||
(define/private (separator step)
|
||||
(insert-step-separator (step-type->string (protostep-type step))))
|
||||
|
||||
;; separator/small : Step -> void
|
||||
(define/private (separator/small step)
|
||||
(insert-step-separator/small
|
||||
(step-type->string (protostep-type step))))
|
||||
|
||||
;; show-step : Step -> void
|
||||
(define/private (show-step step binders)
|
||||
(show-state/redex (protostep-s1 step) binders)
|
||||
(separator step)
|
||||
(show-state/contractum (step-s2 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
(define/private (show-state/redex state binders)
|
||||
(insert-syntax/redex (state-term state)
|
||||
(state-foci state)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
|
||||
(define/private (show-state/contractum state binders)
|
||||
(insert-syntax/contractum (state-term state)
|
||||
(state-foci state)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
|
||||
;; show-prestep : Step -> void
|
||||
(define/private (show-prestep step binders)
|
||||
(separator/small step)
|
||||
(show-state/redex (protostep-s1 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
;; show-poststep : Step -> void
|
||||
(define/private (show-poststep step binders)
|
||||
(separator/small step)
|
||||
(show-state/contractum (protostep-s1 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
;; show-misstep : Step -> void
|
||||
(define/private (show-misstep step binders)
|
||||
(define state (protostep-s1 step))
|
||||
(show-state/redex state binders)
|
||||
(separator step)
|
||||
(send sbview add-error-text (exn-message (misstep-exn step)))
|
||||
(send sbview add-text "\n")
|
||||
(when (exn:fail:syntax? (misstep-exn step))
|
||||
(for-each (lambda (e)
|
||||
(send sbview add-syntax e
|
||||
#:alpha-table binders
|
||||
#:definites (or (state-uses state) null)))
|
||||
(exn:fail:syntax-exprs (misstep-exn step))))
|
||||
(show-lctx step binders))
|
||||
|
||||
;; insert-syntax/color : syntax syntaxes identifiers syntaxes string -> void
|
||||
(define/private (insert-syntax/color stx foci binders definites frontier hi-color)
|
||||
(define highlight-foci? (send config get-highlight-foci?))
|
||||
(define highlight-frontier? (send config get-highlight-frontier?))
|
||||
(send sbview add-syntax stx
|
||||
#:definites (or definites null)
|
||||
#:alpha-table binders
|
||||
#:hi-colors (list hi-color
|
||||
"WhiteSmoke")
|
||||
#:hi-stxss (list (if highlight-foci? foci null)
|
||||
(if highlight-frontier? frontier null))))
|
||||
|
||||
;; insert-syntax/redex : syntax syntaxes identifiers syntaxes -> void
|
||||
(define/private (insert-syntax/redex stx foci binders definites frontier)
|
||||
(insert-syntax/color stx foci binders definites frontier "MistyRose"))
|
||||
|
||||
;; insert-syntax/contractum : syntax syntaxes identifiers syntaxes -> void
|
||||
(define/private (insert-syntax/contractum stx foci binders definites frontier)
|
||||
(insert-syntax/color stx foci binders definites frontier "LightCyan"))
|
||||
|
||||
;; insert-step-separator : string -> void
|
||||
(define/private (insert-step-separator text)
|
||||
(send sbview add-text "\n ")
|
||||
(send sbview add-text
|
||||
(make-object image-snip%
|
||||
(build-path (collection-path "icons")
|
||||
"red-arrow.bmp")))
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
|
||||
;; insert-as-separator : string -> void
|
||||
(define/private (insert-as-separator text)
|
||||
(send sbview add-text "\n ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
|
||||
;; insert-step-separator/small : string -> void
|
||||
(define/private (insert-step-separator/small text)
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text
|
||||
(make-object image-snip%
|
||||
(build-path (collection-path "icons")
|
||||
"red-arrow.bmp")))
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
))
|
|
@ -13,6 +13,7 @@
|
|||
"warning.ss"
|
||||
"hiding-panel.ss"
|
||||
"term-record.ss"
|
||||
"step-display.ss"
|
||||
"../model/deriv.ss"
|
||||
"../model/deriv-util.ss"
|
||||
"../model/deriv-find.ss"
|
||||
|
@ -95,6 +96,7 @@
|
|||
(define/public (get-config) config)
|
||||
(define/public (get-controller) sbc)
|
||||
(define/public (get-view) sbview)
|
||||
(define/public (get-step-displayer) step-displayer)
|
||||
(define/public (get-warnings-area) warnings-area)
|
||||
(define/public (get-macro-hiding-prefs) macro-hiding-prefs)
|
||||
|
||||
|
@ -127,6 +129,9 @@
|
|||
(define sbview (new stepper-syntax-widget%
|
||||
(parent area)
|
||||
(macro-stepper this)))
|
||||
(define step-displayer (new step-display%
|
||||
(config config)
|
||||
(syntax-widget sbview)))
|
||||
(define sbc (send sbview get-controller))
|
||||
(define control-pane
|
||||
(new vertical-panel% (parent area) (stretchable-height #f)))
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"extensions.ss"
|
||||
"warning.ss"
|
||||
"hiding-panel.ss"
|
||||
"step-display.ss"
|
||||
"../model/deriv.ss"
|
||||
"../model/deriv-util.ss"
|
||||
"../model/deriv-find.ss"
|
||||
|
@ -26,23 +27,18 @@
|
|||
|
||||
(provide term-record%)
|
||||
|
||||
;; Struct for one-by-one stepping
|
||||
|
||||
(define-struct (prestep protostep) ())
|
||||
(define-struct (poststep protostep) ())
|
||||
|
||||
(define (prestep-term1 s) (state-term (protostep-s1 s)))
|
||||
(define (poststep-term2 s) (state-term (protostep-s1 s)))
|
||||
|
||||
;; TermRecords
|
||||
|
||||
(define term-record%
|
||||
(class object%
|
||||
(init-field stepper)
|
||||
(init-field [events #f])
|
||||
|
||||
(define config (send stepper get-config))
|
||||
(define sbview (send stepper get-view))
|
||||
(define displayer (send stepper get-step-displayer))
|
||||
|
||||
;; Data
|
||||
|
||||
(init-field [events #f])
|
||||
|
||||
(init-field [raw-deriv #f])
|
||||
(define raw-deriv-oops #f)
|
||||
|
@ -52,13 +48,15 @@
|
|||
(define binders #f)
|
||||
|
||||
(define raw-steps #f)
|
||||
(define raw-steps-estx #f)
|
||||
(define definites #f)
|
||||
(define error #f)
|
||||
(define raw-steps-estx #f) ;; #f if raw-steps-exn is exn
|
||||
(define raw-steps-exn #f) ;; #f if raw-steps-estx is syntax
|
||||
(define raw-steps-definites #f)
|
||||
(define raw-steps-oops #f)
|
||||
|
||||
(define steps #f)
|
||||
|
||||
;; --
|
||||
|
||||
(define steps-position #f)
|
||||
|
||||
(super-new)
|
||||
|
@ -76,8 +74,8 @@
|
|||
[get-deriv-hidden? deriv-hidden?]
|
||||
[get-binders binders])
|
||||
(define-guarded-getters (recache-raw-steps!)
|
||||
[get-definites definites]
|
||||
[get-error error]
|
||||
[get-raw-steps-definites raw-steps-definites]
|
||||
[get-raw-steps-exn raw-steps-exn]
|
||||
[get-raw-steps-oops raw-steps-oops])
|
||||
(define-guarded-getters (recache-steps!)
|
||||
[get-steps steps])
|
||||
|
@ -92,8 +90,8 @@
|
|||
(invalidate-steps!)
|
||||
(set! raw-steps #f)
|
||||
(set! raw-steps-estx #f)
|
||||
(set! definites #f)
|
||||
(set! error #f)
|
||||
(set! raw-steps-exn #f)
|
||||
(set! raw-steps-definites #f)
|
||||
(set! raw-steps-oops #f))
|
||||
|
||||
;; invalidate-synth! : -> void
|
||||
|
@ -158,8 +156,8 @@
|
|||
(reductions+ deriv))])
|
||||
(set! raw-steps raw-steps*)
|
||||
(set! raw-steps-estx estx*)
|
||||
(set! error error*)
|
||||
(set! definites definites*)))))))
|
||||
(set! raw-steps-exn error*)
|
||||
(set! raw-steps-definites definites*)))))))
|
||||
|
||||
;; recache-steps! : -> void
|
||||
(define/private (recache-steps!)
|
||||
|
@ -271,20 +269,18 @@
|
|||
|
||||
;; display-initial-term : -> void
|
||||
(define/public (display-initial-term)
|
||||
(add-syntax (wderiv-e1 deriv) #f null))
|
||||
(send displayer add-syntax (wderiv-e1 deriv) #f null))
|
||||
|
||||
;; display-final-term : -> void
|
||||
(define/public (display-final-term)
|
||||
(recache-steps!)
|
||||
(cond [(syntax? raw-steps-estx)
|
||||
(add-syntax raw-steps-estx binders definites)]
|
||||
[(exn? error)
|
||||
(add-error error)]
|
||||
[raw-steps-oops
|
||||
(add-internal-error "steps" raw-steps-oops #f)]
|
||||
[else
|
||||
(error 'term-record::display-final-term
|
||||
"internal error")]))
|
||||
(send displayer add-syntax raw-steps-estx
|
||||
#:binders binders
|
||||
#:definites raw-steps-definites)]
|
||||
[(exn? raw-steps-exn)
|
||||
(send displayer add-error raw-steps-exn)]
|
||||
[else (display-oops #f)]))
|
||||
|
||||
;; display-step : -> void
|
||||
(define/public (display-step)
|
||||
|
@ -292,191 +288,23 @@
|
|||
(cond [steps
|
||||
(let ([step (cursor:next steps)])
|
||||
(if step
|
||||
(add-step step binders)
|
||||
(add-final raw-steps-estx error binders definites)))]
|
||||
[raw-steps-oops
|
||||
(add-internal-error "steps" raw-steps-oops (wderiv-e1 deriv))]
|
||||
(send displayer add-step step
|
||||
#:binders binders)
|
||||
(send displayer add-final raw-steps-estx raw-steps-exn
|
||||
#:binders binders
|
||||
#:definites raw-steps-definites)))]
|
||||
[else (display-oops #t)]))
|
||||
|
||||
;; display-oops : boolean -> void
|
||||
(define/private (display-oops show-syntax?)
|
||||
(cond [raw-steps-oops
|
||||
(send displayer add-internal-error
|
||||
"steps" raw-steps-oops
|
||||
(and show-syntax? (wderiv-e1 deriv))
|
||||
events)]
|
||||
[raw-deriv-oops
|
||||
(add-internal-error "derivation" raw-deriv-oops #f)]
|
||||
(send displayer add-internal-error
|
||||
"derivation" raw-deriv-oops #f events)]
|
||||
[else
|
||||
(add-internal-error "derivation" #f)]))
|
||||
|
||||
(define/public (add-internal-error part exn stx)
|
||||
(send sbview add-text
|
||||
(if part
|
||||
(format "Macro stepper error (~a)" part)
|
||||
"Macro stepper error"))
|
||||
(when (exn? exn)
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-clickback "[details]"
|
||||
(lambda _ (show-internal-error-details exn))))
|
||||
(send sbview add-text ". ")
|
||||
(when stx (send sbview add-text "Original syntax:"))
|
||||
(send sbview add-text "\n")
|
||||
(when stx (send sbview add-syntax stx)))
|
||||
|
||||
(define/private (show-internal-error-details exn)
|
||||
(case (message-box/custom "Macro stepper internal error"
|
||||
(format "Internal error:\n~a" (exn-message exn))
|
||||
"Show error"
|
||||
"Dump debugging file"
|
||||
"Cancel")
|
||||
((1) (queue-callback
|
||||
(lambda ()
|
||||
(raise exn))))
|
||||
((2) (queue-callback
|
||||
(lambda ()
|
||||
(let ([file (put-file)])
|
||||
(when file
|
||||
(write-debug-file file exn events))))))
|
||||
((3 #f) (void))))
|
||||
|
||||
(define/public (add-error exn)
|
||||
(send sbview add-error-text (exn-message exn))
|
||||
(send sbview add-text "\n"))
|
||||
|
||||
(define/public (add-step step binders)
|
||||
(cond [(step? step)
|
||||
(show-step step binders)]
|
||||
[(misstep? step)
|
||||
(show-misstep step binders)]
|
||||
[(prestep? step)
|
||||
(show-prestep step binders)]
|
||||
[(poststep? step)
|
||||
(show-poststep step binders)]))
|
||||
|
||||
(define/public (add-syntax stx binders definites)
|
||||
(send sbview add-syntax stx
|
||||
'#:alpha-table binders
|
||||
'#:definites (or definites null)))
|
||||
|
||||
(define/private (add-final stx error binders definites)
|
||||
(when stx
|
||||
(send sbview add-text "Expansion finished\n")
|
||||
(send sbview add-syntax stx
|
||||
'#:alpha-table binders
|
||||
'#:definites (or definites null)))
|
||||
(when error
|
||||
(add-error error)))
|
||||
|
||||
;; show-lctx : Step -> void
|
||||
(define/private (show-lctx step binders)
|
||||
(define state (protostep-s1 step))
|
||||
(define lctx (state-lctx state))
|
||||
(when (pair? lctx)
|
||||
(send sbview add-text "\n")
|
||||
(for-each (lambda (bf)
|
||||
(send sbview add-text
|
||||
"while executing macro transformer in:\n")
|
||||
(insert-syntax/redex (bigframe-term bf)
|
||||
(bigframe-foci bf)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
(reverse lctx))))
|
||||
|
||||
;; separator : Step -> void
|
||||
(define/private (separator step)
|
||||
(insert-step-separator (step-type->string (protostep-type step))))
|
||||
|
||||
;; separator/small : Step -> void
|
||||
(define/private (separator/small step)
|
||||
(insert-step-separator/small
|
||||
(step-type->string (protostep-type step))))
|
||||
|
||||
;; show-step : Step -> void
|
||||
(define/private (show-step step binders)
|
||||
(show-state/redex (protostep-s1 step) binders)
|
||||
(separator step)
|
||||
(show-state/contractum (step-s2 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
(define/private (show-state/redex state binders)
|
||||
(insert-syntax/contractum (state-term state)
|
||||
(state-foci state)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
|
||||
(define/private (show-state/contractum state binders)
|
||||
(insert-syntax/contractum (state-term state)
|
||||
(state-foci state)
|
||||
binders
|
||||
(state-uses state)
|
||||
(state-frontier state)))
|
||||
|
||||
;; show-prestep : Step -> void
|
||||
(define/private (show-prestep step binders)
|
||||
(separator/small step)
|
||||
(show-state/redex (protostep-s1 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
;; show-poststep : Step -> void
|
||||
(define/private (show-poststep step binders)
|
||||
(separator/small step)
|
||||
(show-state/contractum (protostep-s1 step) binders)
|
||||
(show-lctx step binders))
|
||||
|
||||
;; show-misstep : Step -> void
|
||||
(define/private (show-misstep step binders)
|
||||
(define state (protostep-s1 step))
|
||||
(show-state/redex state binders)
|
||||
(separator step)
|
||||
(send sbview add-error-text (exn-message (misstep-exn step)))
|
||||
(send sbview add-text "\n")
|
||||
(when (exn:fail:syntax? (misstep-exn step))
|
||||
(for-each (lambda (e)
|
||||
(send sbview add-syntax e
|
||||
'#:alpha-table binders
|
||||
'#:definites (or (state-uses state) null)))
|
||||
(exn:fail:syntax-exprs (misstep-exn step))))
|
||||
(show-lctx step binders))
|
||||
|
||||
;; insert-syntax/color : syntax syntaxes identifiers syntaxes string -> void
|
||||
(define/private (insert-syntax/color stx foci binders definites frontier hi-color)
|
||||
(send sbview add-syntax stx
|
||||
'#:definites (or definites null)
|
||||
'#:alpha-table binders
|
||||
'#:hi-color hi-color
|
||||
'#:hi-stxs (if (send config get-highlight-foci?) foci null)
|
||||
'#:hi2-color "WhiteSmoke"
|
||||
'#:hi2-stxs (if (send config get-highlight-frontier?) frontier null)))
|
||||
|
||||
;; insert-syntax/redex : syntax syntaxes identifiers syntaxes -> void
|
||||
(define/private (insert-syntax/redex stx foci binders definites frontier)
|
||||
(insert-syntax/color stx foci binders definites frontier "MistyRose"))
|
||||
|
||||
;; insert-syntax/contractum : syntax syntaxes identifiers syntaxes -> void
|
||||
(define/private (insert-syntax/contractum stx foci binders definites frontier)
|
||||
(insert-syntax/color stx foci binders definites frontier "LightCyan"))
|
||||
|
||||
;; insert-step-separator : string -> void
|
||||
(define/private (insert-step-separator text)
|
||||
(send sbview add-text "\n ")
|
||||
(send sbview add-text
|
||||
(make-object image-snip%
|
||||
(build-path (collection-path "icons")
|
||||
"red-arrow.bmp")))
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
|
||||
;; insert-as-separator : string -> void
|
||||
(define/private (insert-as-separator text)
|
||||
(send sbview add-text "\n ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
|
||||
;; insert-step-separator/small : string -> void
|
||||
(define/private (insert-step-separator/small text)
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text
|
||||
(make-object image-snip%
|
||||
(build-path (collection-path "icons")
|
||||
"red-arrow.bmp")))
|
||||
(send sbview add-text " ")
|
||||
(send sbview add-text text)
|
||||
(send sbview add-text "\n\n"))
|
||||
|
||||
|
||||
(error 'term-record::display-oops "internal error")]))
|
||||
))
|
||||
|
|
Loading…
Reference in New Issue
Block a user