macro-stepper: fetch mark lists directly
This commit is contained in:
parent
ed88b9dd1a
commit
472b5ecdc0
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
#lang scheme/base
|
#lang scheme/base
|
||||||
(require scheme/class
|
(require scheme/class
|
||||||
syntax/boundmap
|
syntax/boundmap
|
||||||
syntax/stx
|
syntax/stx
|
||||||
"interfaces.ss")
|
"interfaces.rkt"
|
||||||
|
"../util/stxobj.rkt")
|
||||||
(provide new-bound-partition
|
(provide new-bound-partition
|
||||||
partition%
|
partition%
|
||||||
identifier=-choices)
|
identifier=-choices)
|
||||||
|
@ -79,18 +79,26 @@
|
||||||
;; bound-partition%
|
;; bound-partition%
|
||||||
(define bound-partition%
|
(define bound-partition%
|
||||||
(class* object% (partition<%>)
|
(class* object% (partition<%>)
|
||||||
;; numbers : bound-identifier-mapping[identifier => number]
|
|
||||||
(define numbers (make-bound-identifier-mapping))
|
;; simplified : hash[(listof nat) => nat]
|
||||||
|
(define simplified (make-hash))
|
||||||
|
|
||||||
|
;; unsimplified : hash[(listof nat) => nat]
|
||||||
|
(define unsimplified (make-hash))
|
||||||
|
|
||||||
|
;; next-number : nat
|
||||||
(define next-number 0)
|
(define next-number 0)
|
||||||
|
|
||||||
(define/public (get-partition stx)
|
(define/public (get-partition stx)
|
||||||
(let* ([r (representative stx)]
|
(let ([umarks (get-marks stx)])
|
||||||
[n (bound-identifier-mapping-get numbers r (lambda _ #f))])
|
(or (hash-ref unsimplified umarks #f)
|
||||||
(or n
|
(let ([smarks (simplify-marks umarks)])
|
||||||
(begin0 next-number
|
(or (hash-ref simplified smarks #f)
|
||||||
(bound-identifier-mapping-put! numbers r next-number)
|
(let ([n next-number])
|
||||||
#;(printf "primary partition new stx:~n~s~n~s~n" stx (syntax->datum stx))
|
(hash-set! simplified smarks n)
|
||||||
(set! next-number (add1 next-number))))))
|
(hash-set! unsimplified umarks n)
|
||||||
|
(set! next-number (add1 n))
|
||||||
|
n))))))
|
||||||
|
|
||||||
(define/public (same-partition? a b)
|
(define/public (same-partition? a b)
|
||||||
(= (get-partition a) (get-partition b)))
|
(= (get-partition a) (get-partition b)))
|
||||||
|
@ -98,9 +106,6 @@
|
||||||
(define/public (count)
|
(define/public (count)
|
||||||
next-number)
|
next-number)
|
||||||
|
|
||||||
(define/private (representative stx)
|
|
||||||
(datum->syntax stx representative-symbol))
|
|
||||||
|
|
||||||
(get-partition unmarked-syntax)
|
(get-partition unmarked-syntax)
|
||||||
(super-new)))
|
(super-new)))
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
[send/i send:])
|
[send/i send:])
|
||||||
"interfaces.ss"
|
"interfaces.ss"
|
||||||
"util.ss"
|
"util.ss"
|
||||||
"../util/mpi.ss")
|
"../util/mpi.ss"
|
||||||
|
"../util/stxobj.rkt")
|
||||||
(provide properties-view%
|
(provide properties-view%
|
||||||
properties-snip%)
|
properties-snip%)
|
||||||
|
|
||||||
|
@ -206,7 +207,8 @@
|
||||||
(define/public (display-stxobj-info stx)
|
(define/public (display-stxobj-info stx)
|
||||||
(display-source-info stx)
|
(display-source-info stx)
|
||||||
(display-extra-source-info stx)
|
(display-extra-source-info stx)
|
||||||
(display-symbol-property-info stx))
|
(display-symbol-property-info stx)
|
||||||
|
(display-marks stx))
|
||||||
|
|
||||||
;; display-source-info : syntax -> void
|
;; display-source-info : syntax -> void
|
||||||
(define/private (display-source-info stx)
|
(define/private (display-source-info stx)
|
||||||
|
@ -244,7 +246,13 @@
|
||||||
(display "No additional properties available.\n" n/a-sd))
|
(display "No additional properties available.\n" n/a-sd))
|
||||||
(when (pair? keys)
|
(when (pair? keys)
|
||||||
(for-each (lambda (k) (display-subkv/value k (syntax-property stx k)))
|
(for-each (lambda (k) (display-subkv/value k (syntax-property stx k)))
|
||||||
keys))))
|
keys))
|
||||||
|
(display "\n" #f)))
|
||||||
|
|
||||||
|
;; display-marks : syntax -> void
|
||||||
|
(define/private (display-marks stx)
|
||||||
|
(display "Marks: " key-sd)
|
||||||
|
(display (format "~s\n" (simplify-marks (get-marks stx))) #f))
|
||||||
|
|
||||||
;; display-kv : any any -> void
|
;; display-kv : any any -> void
|
||||||
(define/private (display-kv key value)
|
(define/private (display-kv key value)
|
||||||
|
|
30
collects/macro-debugger/util/stxobj.rkt
Normal file
30
collects/macro-debugger/util/stxobj.rkt
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#lang racket
|
||||||
|
(require (rename-in racket/contract [-> c:->])
|
||||||
|
ffi/unsafe)
|
||||||
|
|
||||||
|
(define lib (ffi-lib #f))
|
||||||
|
|
||||||
|
(define get-marks
|
||||||
|
(get-ffi-obj "scheme_stx_extract_marks" lib
|
||||||
|
(_fun _scheme -> _scheme)))
|
||||||
|
|
||||||
|
(define (simplify-marks marklist)
|
||||||
|
(simplify* (sort marklist <)))
|
||||||
|
|
||||||
|
(define (simplify* marklist)
|
||||||
|
(cond [(null? marklist) marklist]
|
||||||
|
[(null? (cdr marklist)) marklist]
|
||||||
|
[(= (car marklist) (cadr marklist))
|
||||||
|
(simplify* (cddr marklist))]
|
||||||
|
[else
|
||||||
|
(let ([result (simplify* (cdr marklist))])
|
||||||
|
(if (eq? result (cdr marklist))
|
||||||
|
marklist
|
||||||
|
(cons (car marklist) result)))]))
|
||||||
|
|
||||||
|
(provide/contract
|
||||||
|
[get-marks
|
||||||
|
;; syntax? check needed for safety!
|
||||||
|
(c:-> syntax? any)])
|
||||||
|
|
||||||
|
(provide simplify-marks)
|
Loading…
Reference in New Issue
Block a user