/usr/share/festival/oo.scm is in festival-freebsoft-utils 0.10-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | ;;; Support of some object oriented features for Festival
;; Copyright (C) 2004 Brailcom, o.p.s.
;; Author: Milan Zamazal <pdm@brailcom.org>
;; COPYRIGHT NOTICE
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
(require 'util)
;;; General wrapping mechanism
(define (oo-first-wrapper-func wrappers)
(cdar wrappers))
(define (oo-wrapper-func wrappers name)
(cdr (assoc name wrappers)))
(define (oo-next-wrapper-func wrappers name)
(cond
((null? wrappers)
nil)
((equal? (car (first wrappers)) name)
(cdr (second wrappers)))
(t
(oo-next-wrapper-func (cdr wrappers) name))))
(define (oo-set-wrapper-func! wrappers-var name function)
(let* ((wrappers (symbol-value wrappers-var))
(spec (assoc name wrappers)))
(if spec
(set-cdr! spec function)
(set-symbol-value!
wrappers-var
(cons (cons name function) (symbol-value wrappers-var))))
nil))
(define (oo-wrapped-var funcname)
(intern (string-append funcname "!shadow")))
(define (oo-wrappers-var funcname)
(intern (string-append funcname "!wrappers")))
(define (oo-gen-wrapper wrappers-var)
(lambda args
(apply (oo-first-wrapper-func (symbol-value wrappers-var)) args)))
(define (oo-ensure-function-wrapped funcname)
(let ((shadow (oo-wrapped-var funcname)))
(when (or (not (boundp shadow))
(not (eq (symbol-value funcname)
(symbol-value shadow))))
(let ((wrapper (oo-gen-wrapper (oo-wrappers-var funcname)))
(wrappers-var (oo-wrappers-var funcname)))
(oo-set-wrapper-func! wrappers-var nil (symbol-value funcname))
(set-symbol-value! funcname wrapper)
(set-symbol-value! shadow wrapper)))))
(define (oo-unwrapped funcname)
(let ((wrappers-var (oo-wrappers-var funcname)))
(if (boundp wrappers-var)
(cdar (last (symbol-value wrappers-var)))
(symbol-value funcname))))
(defmac (define-wrapper form)
;; (define-wrapper (FUNCTION ARG ...) WRAPPER-NAME . BODY)
(let ((func (car (cadr form)))
(args (cdr (cadr form)))
(name (car (cddr form)))
(body (cdr (cddr form))))
(let ((wrappers-var (oo-wrappers-var func)))
(unless (boundp wrappers-var)
(set-symbol-value! wrappers-var (list (cons nil (symbol-value func))))
(oo-ensure-function-wrapped func))
`(oo-set-wrapper-func! (quote ,wrappers-var) (quote ,name)
(lambda ,args
(let ((next-func (lambda ()
(oo-next-wrapper-func ,wrappers-var
(quote ,name)))))
,@body))))))
;;; Parameter wrapping
(define (oo-param-wrappers-var param-name)
(when (consp param-name)
(set! param-name (car param-name)))
(intern (string-append param-name "!P!wrappers")))
(define oo-Param.get-wrapper-enabled t)
(define-wrapper (Param.get name) Param.get-wrapper
(let ((wrappers-var (oo-param-wrappers-var name)))
(if (and (boundp wrappers-var) oo-Param.get-wrapper-enabled)
((oo-first-wrapper-func (symbol-value wrappers-var)))
((next-func) name))))
(defmac (Param.wrap form)
;; (Param.wrap PARAM-NAME WRAPPER-NAME . BODY)
(let* ((param-name (nth 1 form))
(wrapper-name (nth 2 form))
(body (nth_cdr 3 form))
(wrappers-var (oo-param-wrappers-var param-name)))
(unless (boundp wrappers-var)
(set-symbol-value!
wrappers-var
(list (cons nil (lambda ()
(set! oo-Param.get-wrapper-enabled nil)
(unwind-protect*
(Param.get param-name)
(set! oo-Param.get-wrapper-enabled t)))))))
`(oo-set-wrapper-func! (quote ,wrappers-var) (quote ,wrapper-name)
(lambda ()
(let ((next-value
(lambda ()
((oo-next-wrapper-func ,wrappers-var
(quote ,wrapper-name))))))
,@body)))))
;;; Variables
(defvar oo-glet-stack '())
(define (oo-push-let-value var)
(push (cons var (symbol-value var)) oo-glet-stack))
(define (oo-pop-let-value var)
(cond
((null oo-glet-stack)
(error "No restore value on the variable stack"))
((not (eq? (caar oo-glet-stack) var))
(error "Variable stack mismatch"))
(t
(cdr (pop oo-glet-stack)))))
(defmac (glet* form)
(let ((bindings (nth 1 form))
(body (nth_cdr 2 form)))
(if bindings
(let* ((spec (car bindings))
(var (car spec))
(value (cadr spec)))
`(begin
(oo-push-let-value (quote ,var))
(unwind-protect*
(begin
(set! ,var ,value)
(glet* ,(cdr bindings) ,@body))
(set! ,var (oo-pop-let-value (quote ,var))))))
`(begin ,@body))))
;;; Announce
(provide 'oo)
|