home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
ISR
/
isr2.lisp
< prev
next >
Wrap
Lisp/Scheme
|
1995-04-11
|
9KB
|
249 lines
;;; -*- Mode:Common-Lisp; Package:isr2; Base:10 -*-
;;;------------------------------------------------------------------------
;;; ISR2.LISP - testing
;;; Created: Thursday the seventh of April, 1988; 3:57:40 pm
;;; Author: Robert Heller (Original: Bruce Draper, John Brolio, et. al.)
;;;------------------------------------------------------------------------
;;; Copyright (c) University of Massachusetts 1988
;;;------------------------------------------------------------------------
(in-package "ISR2")
(unless (find-package 'isr2)
(make-package 'isr2))
#+:LUCID
(eval-when (load eval compile)
(when (find-package 'clim)
(shadowing-import '(clim::format))))
#+:allegro
(eval-when (load eval compile)
(import '(cltl1::string-char)))
(unless (find-package 'isr) (make-package 'isr))
(unless (find-package 'tv) (make-package 'tv))
(unless (find-package 'w) (make-package 'w))
#+:EXPLORER
(unless (fboundp 'user::cdefvar)
(defmacro cdefvar (variable &optional (initial-value nil) (docstring nil))
"do defvar unless variable is already bound"
;;-- Bob Collins 5/20
;;john brolio 1/7/88 -- to get rid of unspecial variable problem in compiling
`(eval-when (compile eval load)
(proclaim '(special ,variable))
(unless (variable-boundp ,variable)
(setf ,variable ,initial-value)
(setf (documentation ',variable 'variable) ,docstring)))))
(proclaim '(special isr2::*version*))
(eval-when (load)
(setf isr2::*version* 'B1.8)
(pushnew :isr2 *features*)
)
(export '(handle-canonical-path handle-p handle-type))
;;;; This macro is commonly used throughout the ISR2
#+:EXPLORER
(defmacro cdefvar (variable &optional (initial-value nil) (docstring nil))
"do defvar unless variable is already bound"
;;john brolio 1/7/88 -- to get rid of unspecial variable problem in compiling
`(eval-when (compile eval load)
(proclaim '(special ,variable))
(unless (variable-boundp ,variable)
(setf ,variable ,initial-value)
(setf (documentation ',variable 'variable) ,docstring))))
#-:EXPLORER
(defmacro isr2::with-lock ((locator . options) &body body)
(declare (ignore locator options))
`(progn ,@body))
;;;;
;;;; DEBUGGING macro
;;;;
#+:EXPLORER
(cdefvar *DEBUG-ON* nil)
#-:EXPLORER
(defvar *DEBUG-ON* nil)
(defmacro DEBUGGING (format &rest args)
(if *debug-on*
`(format *debug-io* ,format ,@args)
'(progn)))
(defmacro DEBUG-DESCRIBE (item)
(if *debug-on*
`(let ((*standard-output* *debug-io*))
(describe ,item))
'(progn)))
(defmacro DEBUG-ISR-DESCRIBE (item)
(if *debug-on*
`(let ((*standard-output* *debug-io*))
(isr2::describe-??? ,item))
'(progn)))
;;;
;;;isr2.lisp
;;;
;;; prototype shell for testing of isr2 structures
(defstruct (handle (:print-function print-handle))
"ISR HANDLE Structure: This structure is used to represent a path prefix
and provides a \"hook\" into the ISR tree structure."
type
frame
token
feature
fdescr
token-existence-array
last-picked
sort-order
)
(defun print-handle (handle stream ignore)
"Print function for HANDLE structures. These structures print as if there were
strings describing the canonical path to/through the handle. The only exception
is a token-(sub)sequence handle. This is allways printed using #<> notation."
(declare (ignore ignore))
(case (handle-type handle)
(:frame (format stream "#<Frame-Handle ~A>" (frame-path (handle-frame handle))))
(:token (format stream "#<Token-handle ~A<~A>>" (frame-path (handle-frame handle))
(handle-token handle)))
(:frame-feature (format stream "#<Frame-Feature-Handle ~A$~A>"
(frame-path (handle-frame handle))
(handle-feature handle)))
(:token-feature (format stream "#<Token-Feature-Handle ~A<~A>~A>"
(frame-path (handle-frame handle))
(handle-token handle) (handle-feature handle)))
(:token-subset (format stream "#<Token-Subset-Handle ~A>"
(frame-path (handle-frame handle))))
(:token-sort (format stream "#<Token-Sort-Handle ~A, :key ~A, :order :~A>"
(frame-path (handle-frame handle))
(handle-feature handle)
(handle-sort-order handle)
))
))
(defun handle-canonical-path (handle)
"HANDLE-CANONICAL-PATH handle - Returns the canonical path of a handle as
a list of strings."
(unless (handle-p handle)
(error "Argument is not a handle: ~S" handle))
(case (handle-type handle)
(:frame (frame-path-as-list (handle-frame handle)))
(:token (nconc (frame-path-as-list (handle-frame handle))
(let ((index (handle-token handle)))
(if (integerp index)
(list (format nil "<~D>" index))
(list "<?>")))))
(:frame-feature (nconc (frame-path-as-list (handle-frame handle))
(list (handle-feature handle))))
(:token-feature (nconc (frame-path-as-list (handle-frame handle))
(let ((index (handle-token handle)))
(if (integerp index)
(list (format nil "<~D>" index))
(list "<?>")))
(list (handle-feature handle))))
((:token-subset :token-sort)
(error "Cannot return a canonical path list for ~S")
handle))
)
(defstruct (frame (:print-function print-frame)(:constructor %make-frame))
"ISR FRAME Structure - this structure is the basic structure in the ISR.
It is used to hold frame features, tokens, and token features."
name
documentation
source-file-list
(is-loaded-p t)
parent
path-list
feature-alist
token-set-feature-vector
token-set-existence-vector
token-set-globalp-vector
)
(defun print-frame (frame stream ignore)
"Print function for FRAME structures."
(declare (ignore ignore))
(format stream "#<FRAME ~A>" (frame-path frame)))
(defun frame-path (frame &aux elt (result ""))
"FRAME-PATH frame - return (as a string) the frames's canonical path"
(do ((path-elt-list (frame-path-list frame) (rest path-elt-list)))
((null path-elt-list))
(setf elt (first path-elt-list))
(when (integerp elt) (setf elt (format nil "<~d>" elt)))
(if (and (rest path-elt-list)
(not (integerp (second path-elt-list)))
(not (integerp (first path-elt-list))))
(setf result (concatenate 'string result elt "$"))
(setf result (concatenate 'string result elt)))
)
result)
(defun frame-path-as-list (frame &aux elt (result nil))
"FRAME-PATH frame - return (as a string) the frames's canonical path"
(do ((path-elt-list (frame-path-list frame) (rest path-elt-list)))
((null path-elt-list))
(setf elt (first path-elt-list))
(when (integerp elt) (setf elt (format nil "<~d>" elt)))
(setf result (nconc result (list elt)))
)
result)
(defun make-frame (name &key (documentation "") (parent nil))
"MAKE-FRAME name &key (documentation \"\") (parent nil) - primitive function
to build a frame structure."
;; argument coercing
(setf name (string-upcase name)
documentation (string documentation))
;; build a basic frame structure and parse the parent path
(let ((new-frame (%make-frame :name name :documentation documentation))
(parsed-parent (make-canonical-path-list (parse-token-name parent)))
)
;; fill in additional slots:
(setf (frame-parent new-frame) parent ; the parent
; the canonical path
(frame-path-list new-frame) (append parsed-parent (list name))
; and an empty token existence vector
(frame-token-set-existence-vector new-frame)
(make-2index-vector-vector 0)
(frame-token-set-globalp-vector new-frame)
(make-2index-vector-vector 0)
)
new-frame))
(defun make-canonical-path-list (parent)
"MAKE-CANONICAL-PATH-LIST parent - make a canonical path list by back traversining
the pathlist of the parent path."
(cond ((null parent) nil)
((handle-p (first parent))
(case (handle-type (first parent))
(:frame (append (frame-path-list (handle-frame (first parent)))
(make-canonical-path-list (rest parent))))
(:token (append (frame-path-list (handle-frame (first parent)))
(list (handle-token (first parent)))
(make-canonical-path-list (rest parent))))
(:frame-feature (append (frame-path-list
(handle-frame (first parent)))
(list (handle-feature (first parent)))
(make-canonical-path-list (rest parent))))
(:token-feature (append (frame-path-list
(handle-frame (first parent)))
(list (handle-token (first parent))
(handle-feature (first parent)))
(make-canonical-path-list (rest parent))))
))
(t (cons (first parent) (make-canonical-path-list (rest parent)))))
)