Added terminal sc contracts, and made optimizer use them.
This commit is contained in:
parent
dcb8fa2b5e
commit
9b9ec7fd5a
|
@ -35,6 +35,8 @@
|
|||
[(define (sc-map v f) v)
|
||||
(define (sc->contract v f) (length-contract-syntax v))
|
||||
(define (sc->constraints v f) 'flat)]
|
||||
#:methods gen:terminal-sc
|
||||
[(define (terminal-sc-kind v) 'flat)]
|
||||
#:methods gen:custom-write [(define write-proc length-contract-write-proc)])
|
||||
|
||||
(define (list-length/sc n)
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
[(define (sc-map v f) v)
|
||||
(define (sc->contract v f) (simple-contract-syntax v))
|
||||
(define (sc->constraints v f) (simple-contract-restrict (simple-contract-kind v)))]
|
||||
#:methods gen:terminal-sc
|
||||
[(define (terminal-sc-kind v) (simple-contract-kind v))]
|
||||
#:methods gen:custom-write [(define write-proc simple-contract-write-proc)])
|
||||
|
||||
(define (flat/sc ctc) (simple-contract ctc 'flat))
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
[(arr/sc: args rest (list (any/sc:) ...))
|
||||
(arr/sc args rest #f)]
|
||||
[(none/sc:) any/sc]
|
||||
[(? flat/sc?) any/sc]
|
||||
[(app terminal-sc-kind 'flat) any/sc]
|
||||
[else sc]))
|
||||
|
||||
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
[sc-map (static-contract? (static-contract? variance/c . -> . static-contract?) . -> . static-contract?)]
|
||||
[sc->contract (static-contract? (static-contract? . -> . syntax?) . -> . syntax?)]
|
||||
[sc->constraints (static-contract? (static-contract? . -> . contract-restrict?) . -> . contract-restrict?)]
|
||||
[terminal-sc-kind (static-contract? . -> . (or/c #f contract-kind?))]
|
||||
[sc? predicate/c]
|
||||
)
|
||||
|
||||
|
||||
prop:combinator-name
|
||||
gen:sc)
|
||||
gen:sc
|
||||
gen:terminal-sc)
|
||||
|
||||
(define variance/c (or/c 'covariant 'contravariant 'invariant))
|
||||
|
||||
|
@ -103,6 +105,16 @@
|
|||
;; The function argument should be used for sub parts of the static contract.
|
||||
[sc->constraints sc f])
|
||||
|
||||
;; Functionality that terminal static contracts should support
|
||||
;; Terminal static contracts are ones without any sub static contracts
|
||||
(define-generics terminal-sc
|
||||
;; terminal-sc-kind: terminal-static-contract? -> (or/c #f contract-kind?)
|
||||
;; Returns the kind of contract that this represents
|
||||
;; Returns #f if it is not a terminal contract
|
||||
[terminal-sc-kind terminal-sc]
|
||||
#:defaults ([(λ (v) #t)
|
||||
(define (terminal-sc-kind v) #f)]))
|
||||
|
||||
;; Super struct of static contracts
|
||||
(struct static-contract ()
|
||||
#:transparent
|
||||
|
|
Loading…
Reference in New Issue
Block a user