remove spec and realize
They were too much surface for a language this small: a nominal contract layer, per-type default synthesis and a pub interface of their own. Type introspection and macros are the intended replacement, so the storage, the forms and the tests that pin them go; the ops method registry they leaned on stays. The implementation is kept at tag 0.0.1.
This commit is contained in:
39
types.scm
39
types.scm
@@ -34,12 +34,6 @@
|
||||
variant-fields
|
||||
reset-declarations!
|
||||
|
||||
add-spec!
|
||||
get-spec
|
||||
spec-parameter
|
||||
spec-methods
|
||||
add-realization!
|
||||
realizes?
|
||||
normalize-fields
|
||||
|
||||
add-method!
|
||||
@@ -324,43 +318,14 @@
|
||||
((memq (car type) '(const volatile)) (ops-key (cadr type)))
|
||||
(else #f)))
|
||||
|
||||
;;; A spec is a parameter and a list of methods, each of which either
|
||||
;;; declares a signature or also carries a default body:
|
||||
;;;
|
||||
;;; (spec (printable T) (fn show ((self (* const T))) void))
|
||||
;;; -> printable -> (T (fn show ((self (* const T))) void))
|
||||
;;;
|
||||
;;; And a realization is only ever asked whether it exists -- the
|
||||
;;; methods it provides land in +ops-db+ like any others.
|
||||
(define +spec-db+ (make-hash-table))
|
||||
(define +realize-db+ (make-hash-table))
|
||||
|
||||
(define (add-spec! name parameter methods)
|
||||
(hash-table-set! +spec-db+ name (cons parameter methods)))
|
||||
|
||||
(define (get-spec name)
|
||||
(hash-table-ref/default +spec-db+ name #f))
|
||||
|
||||
(define (spec-parameter spec) (car spec))
|
||||
(define (spec-methods spec) (cdr spec))
|
||||
|
||||
(define (add-realization! spec type)
|
||||
(hash-table-set! +realize-db+ (cons spec (type-key type)) #t))
|
||||
|
||||
;;; What a generic macro asks before it expands: (realizes? 'ord 'circle)
|
||||
(define (realizes? spec type)
|
||||
(known type (hash-table-exists? +realize-db+ (cons spec (type-key type)))))
|
||||
|
||||
;;; Sums, constructors, methods and specs refuse a second declaration
|
||||
;;; Sums, constructors and methods refuse a second declaration
|
||||
;;; of the same name, which is per translation unit rather than per
|
||||
;;; process -- so a process that compiles two units has to start the
|
||||
;;; second one clean.
|
||||
(define (reset-declarations!)
|
||||
(set! +sum-db+ (make-hash-table))
|
||||
(set! +constructor-db+ (make-hash-table))
|
||||
(set! +ops-db+ (make-hash-table))
|
||||
(set! +spec-db+ (make-hash-table))
|
||||
(set! +realize-db+ (make-hash-table)))
|
||||
(set! +ops-db+ (make-hash-table)))
|
||||
|
||||
;;; Type matcher macro
|
||||
;;; (type-match type
|
||||
|
||||
Reference in New Issue
Block a user