|
|
@ -1,5 +1,5 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require (for-syntax racket/base racket/syntax br/syntax) br/define racket/class)
|
|
|
|
(require (for-syntax racket/base racket/syntax) racket/class)
|
|
|
|
(provide (all-defined-out))
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
|
|
|
|
(define string%
|
|
|
|
(define string%
|
|
|
@ -17,69 +17,79 @@
|
|
|
|
(super-new)
|
|
|
|
(super-new)
|
|
|
|
(define/public (addContent val) (make-object string% val))))
|
|
|
|
(define/public (addContent val) (make-object string% val))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (as-method ID)
|
|
|
|
(define-syntax (as-method stx)
|
|
|
|
(with-pattern ([PRIVATE-ID (generate-temporary #'ID)])
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
|
|
|
[(_ ID) (with-syntax ([PRIVATE-ID (generate-temporary #'ID)])
|
|
|
|
#'(begin
|
|
|
|
#'(begin
|
|
|
|
(public [PRIVATE-ID ID])
|
|
|
|
(public [PRIVATE-ID ID])
|
|
|
|
(define (PRIVATE-ID . args) (apply ID this args)))))
|
|
|
|
(define (PRIVATE-ID . args) (apply ID this args))))]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (as-methods ID ...)
|
|
|
|
(define-syntax-rule (as-methods ID ...)
|
|
|
|
#'(begin (as-method ID) ...))
|
|
|
|
(begin (as-method ID) ...))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-instance ID (MAKER BASE-CLASS . ARGS))
|
|
|
|
(define-syntax (define-instance stx)
|
|
|
|
(with-pattern ([ID-CLASS (prefix-id #'BASE-CLASS ":" #'ID)])
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
|
|
|
[(_ ID (MAKER BASE-CLASS . ARGS))
|
|
|
|
|
|
|
|
(with-syntax ([ID-CLASS (format-id stx "~a:~a" (syntax->datum #'BASE-CLASS) (syntax->datum #'ID))])
|
|
|
|
#'(define ID (let ([ID-CLASS (class BASE-CLASS (super-new))])
|
|
|
|
#'(define ID (let ([ID-CLASS (class BASE-CLASS (super-new))])
|
|
|
|
(MAKER ID-CLASS . ARGS)))))
|
|
|
|
(MAKER ID-CLASS . ARGS))))]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-class-predicates ID)
|
|
|
|
(define-syntax (define-class-predicates stx)
|
|
|
|
(with-pattern ([+ID (prefix-id "+" #'ID)]
|
|
|
|
(syntax-case stx ()
|
|
|
|
[ID? (suffix-id #'ID "?")])
|
|
|
|
[(_ ID)
|
|
|
|
|
|
|
|
(with-syntax ([+ID (format-id #'ID "+~a" (syntax->datum #'ID))]
|
|
|
|
|
|
|
|
[ID? (format-id #'ID "~a?" (syntax->datum #'ID))])
|
|
|
|
#'(begin (define (ID? x) (is-a? x ID))
|
|
|
|
#'(begin (define (ID? x) (is-a? x ID))
|
|
|
|
(define (+ID . args) (apply make-object ID args)))))
|
|
|
|
(define (+ID . args) (apply make-object ID args))))]))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-subclass*/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) . BODY)
|
|
|
|
(define-syntax-rule (define-subclass*/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) . BODY)
|
|
|
|
#'(begin
|
|
|
|
(begin
|
|
|
|
(define ID (class* SUPERCLASS INTERFACES (init-field . INIT-ARGS) . BODY))
|
|
|
|
(define ID (class* SUPERCLASS INTERFACES (init-field . INIT-ARGS) . BODY))
|
|
|
|
(define-class-predicates ID)))
|
|
|
|
(define-class-predicates ID)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-subclass/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) . BODY)
|
|
|
|
(define-syntax-rule (define-subclass/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) . BODY)
|
|
|
|
#'(define-subclass*/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) (super-new) . BODY))
|
|
|
|
(define-subclass*/interfaces SUPERCLASS INTERFACES (ID . INIT-ARGS) (super-new) . BODY))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-subclass* SUPERCLASS (ID . INIT-ARGS) . BODY)
|
|
|
|
(define-syntax-rule (define-subclass* SUPERCLASS (ID . INIT-ARGS) . BODY)
|
|
|
|
#'(define-subclass*/interfaces SUPERCLASS () (ID . INIT-ARGS) . BODY))
|
|
|
|
(define-subclass*/interfaces SUPERCLASS () (ID . INIT-ARGS) . BODY))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-subclass SUPERCLASS (ID . INIT-ARGS) . BODY)
|
|
|
|
(define-syntax-rule (define-subclass SUPERCLASS (ID . INIT-ARGS) . BODY)
|
|
|
|
#'(define-subclass* SUPERCLASS (ID . INIT-ARGS) (super-new) . BODY))
|
|
|
|
(define-subclass* SUPERCLASS (ID . INIT-ARGS) (super-new) . BODY))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (push-field! FIELD O EXPR)
|
|
|
|
(define-syntax-rule (push-field! FIELD O EXPR)
|
|
|
|
#'(set-field! FIELD O (cons EXPR (get-field FIELD O))))
|
|
|
|
(set-field! FIELD O (cons EXPR (get-field FIELD O))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (push-end-field! FIELD O EXPR)
|
|
|
|
(define-syntax-rule (push-end-field! FIELD O EXPR)
|
|
|
|
#'(set-field! FIELD O (append (get-field FIELD O) (list EXPR))))
|
|
|
|
(set-field! FIELD O (append (get-field FIELD O) (list EXPR))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (pop-field! FIELD O)
|
|
|
|
(define-syntax-rule (pop-field! FIELD O)
|
|
|
|
#'(let ([xs (get-field FIELD O)])
|
|
|
|
(let ([xs (get-field FIELD O)])
|
|
|
|
(set-field! FIELD O (cdr xs))
|
|
|
|
(set-field! FIELD O (cdr xs))
|
|
|
|
(car xs)))
|
|
|
|
(car xs)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro-cases increment-field!
|
|
|
|
(define-syntax (increment-field! stx)
|
|
|
|
|
|
|
|
(syntax-case stx ()
|
|
|
|
[(_ FIELD O) #'(increment-field! FIELD O 1)]
|
|
|
|
[(_ FIELD O) #'(increment-field! FIELD O 1)]
|
|
|
|
[(_ FIELD O EXPR)
|
|
|
|
[(_ FIELD O EXPR)
|
|
|
|
#'(begin (set-field! FIELD O (+ (get-field FIELD O) EXPR)) (get-field FIELD O))])
|
|
|
|
#'(begin (set-field! FIELD O (+ (get-field FIELD O) EXPR)) (get-field FIELD O))]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (getter-field/override [ID . EXPRS])
|
|
|
|
(define-syntax (getter-field/override stx)
|
|
|
|
(syntax-property #'(getter-field [ID . EXPRS]) 'override #t))
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
|
|
|
[(_ [ID . EXPRS])
|
|
|
|
|
|
|
|
(syntax-property #'(getter-field [ID . EXPRS]) 'override #t)]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (getter-field [ID . EXPRS])
|
|
|
|
(define-syntax (getter-field stx)
|
|
|
|
(with-pattern ([_ID (prefix-id "_" #'ID)])
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
|
|
|
[(_ [ID . EXPRS])
|
|
|
|
|
|
|
|
(with-syntax ([_ID (format-id #'ID "_~a" (syntax->datum #'ID))])
|
|
|
|
#`(begin
|
|
|
|
#`(begin
|
|
|
|
(field [(ID _ID) . EXPRS])
|
|
|
|
(field [(ID _ID) . EXPRS])
|
|
|
|
(public (_ID ID))
|
|
|
|
(public (_ID ID))
|
|
|
|
(#,(if (syntax-property caller-stx 'override) #'define/override #'define) (_ID) ID))))
|
|
|
|
(#,(if (syntax-property stx 'override) #'define/override #'define) (_ID) ID)))]))
|