Add support for contracts on identifier tables.
This commit is contained in:
parent
7291e1a24d
commit
54b82871ab
|
@ -69,7 +69,8 @@
|
|||
[idtbl-map (s '-map)]
|
||||
[idtbl-for-each (s '-for-each)]
|
||||
[idtbl-mutable-methods (s '-mutable-methods)]
|
||||
[idtbl-immutable-methods (s '-immutable-methods)])
|
||||
[idtbl-immutable-methods (s '-immutable-methods)]
|
||||
[idtbl/c (s '/c)])
|
||||
#'(begin
|
||||
|
||||
;; Struct defs at end, so that dict methods can refer to earlier procs
|
||||
|
@ -119,6 +120,29 @@
|
|||
(list idtbl-immutable-methods
|
||||
dict-contract-methods))
|
||||
|
||||
(define (mutable-idtbl/c value/c)
|
||||
(struct/c mutable-idtbl
|
||||
(hash/c any/c
|
||||
(listof (cons/c any/c value/c))
|
||||
#:immutable #f)
|
||||
any/c))
|
||||
|
||||
(define (immutable-idtbl/c value/c)
|
||||
(struct/c immutable-idtbl
|
||||
(hash/c any/c
|
||||
(listof (cons/c any/c value/c))
|
||||
#:immutable #t)
|
||||
any/c))
|
||||
|
||||
|
||||
(define (idtbl/c value/c #:immutable (immutable 'dont-care))
|
||||
(case immutable
|
||||
((dont-care) (or/c (mutable-idtbl/c value/c)
|
||||
(immutable-idtbl/c value/c)))
|
||||
((#t) (immutable-idtbl/c value/c))
|
||||
((#f) (mutable-idtbl/c value/c))))
|
||||
|
||||
|
||||
(provide/contract
|
||||
[make-idtbl
|
||||
(->* () (dict? #:phase (or/c #f exact-integer?)) mutable-idtbl?)]
|
||||
|
@ -153,7 +177,11 @@
|
|||
[idtbl-map
|
||||
(-> idtbl? (-> identifier? any/c any) list?)]
|
||||
[idtbl-for-each
|
||||
(-> idtbl? (-> identifier? any/c any) any)]))))]))
|
||||
(-> idtbl? (-> identifier? any/c any) any)]
|
||||
[idtbl/c
|
||||
(->* (contract?)
|
||||
(#:immutable (or/c 'dont-care #t #f))
|
||||
contract?)]))))]))
|
||||
|
||||
(make-code bound-id-table)
|
||||
(make-code free-id-table)
|
||||
|
|
|
@ -154,6 +154,12 @@ identifier table (free or bound, mutable or immutable), @racket[#f]
|
|||
otherwise.
|
||||
}
|
||||
|
||||
@defproc[(free-id-table/c [val contract?]
|
||||
[#:immutable immutable (or/c #t #f 'dont-care) 'dont-care])
|
||||
contract?]{
|
||||
|
||||
Like @racket[hash/c], but more limited. It only supports contracts on the values in the identifier table.
|
||||
}
|
||||
|
||||
@;{----------}
|
||||
@section{Dictionaries for @racket[bound-identifier=?]}
|
||||
|
@ -204,6 +210,9 @@ etc) can be used on bound-identifier tables.
|
|||
void?]
|
||||
@defproc[(bound-id-table-count [table bound-id-table?])
|
||||
exact-nonnegative-integer?]
|
||||
@defproc[(bound-id-table/c [val contract?]
|
||||
[#:immutable immutable (or/c #t #f 'dont-care) 'dont-care])
|
||||
contract?]
|
||||
@;{
|
||||
@defproc[(bound-id-table-iterate-first [table bound-id-table?])
|
||||
id-table-position?]
|
||||
|
|
Loading…
Reference in New Issue
Block a user