Codebase list cafeobj / 93cfe1b
Add type delcarations for future enhancements. tswd 5 years ago
11 changed file(s) with 471 addition(s) and 342 deletion(s). Raw diff Collapse all Expand all
248248
249249 ;;; ----------------------------------------
250250 ;;; BASIC PROCS for REWRITE RULE APPLICATION
251
252 (declaim (inline print-trace-in))
253 (defun print-trace-in ()
254 (format *error-output* "~%~d>[~a] " *trace-level* (1+ *rule-count*)))
255
256 (declaim (inline print-trace-out))
257 (defun print-trace-out ()
258 (format *error-output* "~%~d<[~a] " *trace-level* *rule-count*))
251259
252260 (declaim (inline term-replace-dd-simple))
253261 (defun term-replace-dd-simple (old new)
378386 (type symbol next-match-method))
379387 (multiple-value-bind (global-state subst no-match E-equal)
380388 ;; first we find matching rewrite rule
381 (funcall (or (rule-first-match-method rule)
389 (funcall (or (the symbol (rule-first-match-method rule))
382390 (progn
383391 (when *chaos-verbose*
384392 (with-output-chaos-warning ()
386394 (print-next)
387395 (print-axiom-brief rule)))
388396 (compute-rule-method rule)
389 (rule-first-match-method rule)))
397 (symbol-function (the symbol (rule-first-match-method rule)))))
390398 (rule-lhs rule)
391399 term)
392400 (declare (type global-state global-state)
461469 (multiple-value-setq (global-state subst no-match)
462470 (progn
463471 (incf $$matches)
464 (funcall next-match-method global-state)))
472 (funcall (symbol-function next-match-method) global-state)))
465473 (when no-match
466474 ;; no more match, we failed
467475 (return-from the-end nil))
10381046 ;;; in this case "term" is also modified.
10391047 ;;;
10401048 ;;;
1041 (defun print-trace-in ()
1042 (format *trace-output* "~%~d>[~a] " *trace-level* (1+ *rule-count*)))
1043
1044 (defun print-trace-out ()
1045 (format *trace-output* "~%~d<[~a] " *trace-level* *rule-count*))
1046
10471049 (defun cafein-pattern-match (pat term)
10481050 (declare (type term pat term)
10491051 (optimize (speed 3) (safety 0))
7979 (setf (get 'rewrite-rule :print) 'print-rule-internal))
8080
8181 (defun print-rule-object (obj stream &rest ignore)
82 (declare (ignore ignore))
82 (declare (type rewrite-rule obj)
83 (type stream stream)
84 (ignore ignore))
8385 (if *current-module*
8486 (progn
8587 (format stream ":rule[~S: " (addr-of obj))
10281028 ;;; The intent is that the following be used with uncanonicalized module
10291029 ;;; name's.; case in particular -- creation of parameters for module
10301030 ;;;
1031 ;;; (declaim (inline equal-top-level))
1032 #-gcl
10331031 (defun equal-top-level (x y)
10341032 (cond ((stringp x) (string= x y))
1035 ((atom x) (eql x y))
1036 ((atom y) nil)
1037 (t (and (equal-top-level (car x) (car y))
1038 (equal-top-level (cdr x) (cdr y))))))
1039
1040 #+gcl
1041 (si::define-inline-function equal-top-level (x y)
1042 (cond ((stringp x) (equal x y))
10431033 ((atom x) (eql x y))
10441034 ((atom y) nil)
10451035 (t (and (equal-top-level (car x) (car y))
10561046 ;;; used in eval-module
10571047 ;;;
10581048 (defun modexp-update-name (modexp modval)
1049 (declare (type modexp modexp)
1050 (type module modval))
10591051 (let ((entry (rassoc modval *modules-so-far-table*)))
10601052 (when entry
10611053 (setf (car entry) modexp)
6464 (defmacro object-info (_obj _info)
6565 `(getf (object-misc-info ,_obj) ,_info))
6666
67 ;;; GET-CONTEXT-MODULE
68 (declaim (inline get-context-module))
69 (defun get-context-module (&optional no-error)
70 (declare (type (or null (not null)) no-error)
71 (optimize (speed 3) (safety 0)))
72 (or *current-module*
73 (if no-error
74 nil
75 (with-output-chaos-error ('no-context)
76 (format t "No context module is set.")))))
77
78 ;;; RESET-CONTEXT-MODULE
79 (declaim (inline reset-context-module))
80 (defun reset-context-module (&optional (mod nil))
81 (setf *current-module* mod))
82
83 ;;; GET-OBJECT-CONTEXT object -> null | module
84 ;;;
85 (declaim (inline get-object-context))
86 (defun get-object-context (obj)
87 (declare (optimize (speed 3) (safety 0)))
88 (or (get-context-module t) (object-context-mod obj)))
89
90 (declaim (inline set-object-context-module))
6791 (defun set-object-context-module (obj &optional (context-mod (get-context-module)))
92 (declare (optimize (speed 3) (safety 0)))
6893 (setf (object-context-mod obj) context-mod))
6994
7095 ;;; *********
426451
427452 ;;; AXIOM SET
428453 (defun print-axiom-set (obj stream &rest ignore)
429 (declare (ignore ignore))
454 (declare (type axiom-set obj)
455 (type stream stream)
456 (ignore ignore))
430457 (let ((mod (axiom-set$module obj)))
458 (declare (type module mod))
431459 (format stream "':axset[\"~a\"]" (module-print-name mod))))
432460
433461 ;;; ***
587615 (unknowns nil :type list))
588616
589617 (defun canonicalize-object-name (nm)
618 (declare (optimize (speed 3) (safety 0)))
590619 (cond ((stringp nm)
591620 (intern nm))
592621 ((consp nm)
601630
602631 (defun symbol-table-add (table nm obj)
603632 (when (and (module-p obj)
604 (module-is-parameter-theory obj))
633 (module-is-parameter-theory (the module obj)))
605634 (setq nm (car (module-name obj))))
606635 (let ((name (canonicalize-object-name nm)))
607636 (pushnew name (symbol-table-names table) :test #'equal)
4242
4343 ;;; GET-CONTEXT : null | module
4444 (defun get-context ()
45 (declare (optimize (speed 3) (safety 0)))
4546 (if *current-module*
4647 (module-context *current-module*)
4748 nil))
4849
49 ;;; GET-CONTEXT-MODULE
50 (defun get-context-module (&optional no-error)
51 (or *current-module*
52 (if no-error
53 nil
54 (with-output-chaos-error ('no-context)
55 (format t "No context module is set.")))))
56
57 ;;; RESET-CONTEXT-MODULE
58 (defun reset-context-module (&optional (mod nil))
59 (setf *current-module* mod))
60
61 ;;; GET-OBJECT-CONTEXT object -> null | module
62 ;;;
63 (defun get-object-context (obj)
64 (or (get-context-module t) (object-context-mod obj)))
65
6650 ;;; BINDINGS *******************************************************************
6751
6852 ;;; GET-BOUND-VALUE : let-symbol -> value (a term) | null
6953
7054 (defun is-special-let-variable? (name)
71 (declare (values (or null t)))
55 (declare (type simple-string name))
7256 (and (>= (length (the simple-string name)) 3)
7357 (equal "$$" (subseq (the simple-string name) 0 2))))
7458
7559 (defun check-$$term-context (mod)
60 (declare (type module mod))
7661 (or (eq $$term-context mod)
7762 (member $$term-context
7863 (module-all-submodules mod)
8065 (eq x (car y))))))
8166
8267 (defun get-bound-value (let-sym &optional (mod (get-context-module)))
68 (declare (type module mod)
69 (type simple-string let-sym))
8370 (let ((bound-token (assoc let-sym (module-bindings mod) :test #'equal)))
8471 (if (and (null bound-token) *allow-$$term*)
8572 (cond ((equal let-sym "$$term")
5454 (declaim (special .printed-vars-so-far.))
5555 (defvar .printed-vars-so-far. nil)
5656
57 (declaim (special **print-var-sort**))
57 (declaim (special **print-var-sort**)
58 (type (or null (not null)) **print-var-sort**))
5859 (defvar **print-var-sort** t)
5960
6061
6162 ;;; VARIABLE
6263
6364 (defun print-variable (term &optional (stream *standard-output*))
65 (declare (type term term)
66 (type stream stream))
6467 (let ((*standard-output* stream)
6568 (body (term-body term)))
6669 (princ (string (variable$print-name body)))
7174 ;;;
7275
7376 (defun print-ast-vd (ast stream print-var-sort)
74 (declare (type stream stream))
77 (declare (type list ast)
78 (type stream stream)
79 (type (or null (not null)) print-var-sort))
7580 (print-check)
7681 (cond ((consp ast)
7782 (let ((flg nil))
8388 (princ ")")))
8489 (t (princ ast))))
8590
91 (declaim (inline is-ast))
8692 (defun is-ast (obj)
93 (declare (optimize (speed 3) (safety 0)))
8794 (and (consp obj)
8895 (let ((cat (car obj)))
8996 (and (symbolp cat)
99106 ;;; returns t if pure varible or pconstant.
100107 ;;;
101108 (defun pvariable-term? (term)
109 (declare (type term term))
102110 (or (term-is-variable? term)(term-is-pconstant? term)))
103111
104112 (defun pvariable-term-body? (term-body)
113 (declare (type term-body term-body))
105114 (or (term$is-variable? term-body) (term$is-pconstant? term-body)))
106115
107116 ;;; VARIABLE-PRINT-STRING: variable -> String
108117 ;;;
109118 (defun variable-print-string (term &optional (print-var-sort t)
110119 (vars-so-far (cons nil nil)))
120 (declare (type term term)
121 (type (or null (not null)) print-var-sort))
111122 (let ((name (if (numberp (variable-print-name term))
112123 (format nil "_v~d" (variable-print-name term))
113124 (string (variable-print-name term)))))
125 (declare (type simple-string name))
114126 (when print-var-sort
115127 (unless (or (member term (cdr vars-so-far)
116128 :test #'variable-eq)
134146 name))
135147
136148 (defun bconst-print-string (term)
149 (declare (type term term))
137150 (let ((val (term-builtin-value term)))
138151 (with-output-to-string (ss)
139152 (let ((*standard-output* ss))
156169 (defun term-to-sexpr (term &optional (print-var-sort t)
157170 (vars-so-far (cons nil nil))
158171 (as-tree nil))
159 (unless term
160 (princ "!! empty term !!")
161 (return-from term-to-sexpr nil))
172 (declare (type term term)
173 (type (or null (not null)) as-tree))
162174 (cond ((term-is-variable? term)
163175 (if as-tree
164176 (return-from term-to-sexpr
223235 (push i sexpr-so-far))))
224236 (return-from term-to-sexpr (nreverse sexpr-so-far)))))))))
225237
238 (declaim (inline is-self-terminating))
226239 (defun is-self-terminating (tok)
240 (declare (optimize (speed 3) (safety 0)))
227241 (and (stringp tok)
228242 (= (length tok) 1)
229243 (assoc (char tok 0) .default-single-chars.)))
231245 (defun term-print1 (term &optional (stream *standard-output*)
232246 (print-var-sort t)
233247 (vars-so-far (cons nil nil)))
234 (declare (type stream stream)
235 (type (or null t) print-var-sort)
236 (values t))
237 (unless (term? term)
238 (format stream " ~s " term)
239 (return-from term-print1))
248 (declare (type term term)
249 (type stream stream)
250 (type (or null (not null)) print-var-sort))
240251 (let ((*standard-output* stream)
241252 (body (term-body term))
242253 (*current-term-depth* (1+ *current-term-depth*))
243254 (.file-col. .file-col.))
244 ;;
255 (declare (type term-body body))
245256 (when (and *term-print-depth*
246257 (> *current-term-depth*
247258 (the fixnum *term-print-depth*)))
314325 &optional (stream *standard-output*)
315326 (print-var-sort t)
316327 (vars-so-far (cons nil nil)))
317 (declare (type (or null term) term)
328 (declare (type term term)
318329 (type fixnum prec)
319330 (type stream stream)
320 (type (or null t) print-var-sort))
321 (unless (term? term)
322 (format stream " ~s " term)
323 (return-from term-print2))
331 (type (or null (not null)) print-var-sort))
324332 (let ((*standard-output* stream)
325333 (*current-term-depth* (1+ *current-term-depth*))
326334 (.file-col. .file-col.))
329337 (the fixnum *term-print-depth*)))
330338 (princ " ... " stream)
331339 (return-from term-print2 nil))
332 ;;
333340 (when (print-check .file-col. 0 stream) ; 20??
334341 (setq .file-col. (file-column stream)))
335 ;;
336342 (when (and *print-term-color* (term-is-red term))
337343 (princ "r::" stream))
338
339 (cond ((pvariable-term? term)
344 (cond (;; pconstant
345 (pvariable-term? term)
340346 (let ((vstr (variable-print-string term
341347 print-var-sort
342348 vars-so-far)))
343349 (princ vstr stream)))
350 ;; system object
344351 ((term-is-system-object? term)
345352 (let ((obj (term-system-object term)))
346353 (when (chaos-list-p obj)
352359 (dolist (x obj)
353360 (term-print2 x prec stream print-var-sort vars-so-far))
354361 (princ "]" stream)))))
362 ;; built-in constant
355363 ((term-is-builtin-constant? term)
356364 (let ((bstr (bconst-print-string term)))
357365 (princ bstr stream)))
358 ;;
366 ;; lisp-form
359367 ((term-is-lisp-form? term)
360368 (let ((*print-pretty* t))
361369 (if (term-is-simple-lisp-form? term)
404412 (when (or prec-test some-eql-form?)
405413 (princ "(" stream)
406414 (setq .file-col. (1+ .file-col.)))
407 ;;
415 ;; subterms
408416 (let ((subs (term-subterms term))
409417 (prv nil))
410418 (do* ((tseq token-seq (cdr tseq))
436444
437445 (defun term-print (term &optional (stream *standard-output*)
438446 (print-var-sort **print-var-sort**))
439 (declare (type (or null term) term)
440 (type (or t stream))
441 (type (or null t) print-var-sort)
442 (values t))
443 (unless *current-module*
444 (with-output-chaos-error ('no-context)
445 (format t "Internal error: printing term, no current context")))
446 (when (eq stream t)
447 (setq stream *standard-output*))
448 (let* ((vars-so-far (cons nil .printed-vars-so-far.))
449 (.file-col. (file-column stream))
450 (*print-indent* *print-indent*))
451 (case *print-xmode*
452 (:tree
453 (let ((*print-pretty* t))
454 (princ (term-to-sexpr term print-var-sort vars-so-far t)
455 stream)))
456 (:s-expr
457 (let ((*print-pretty* t))
458 (princ (term-to-sexpr term print-var-sort vars-so-far nil)
459 stream)))
460 (:fancy
461 (let ((*print-pretty* nil))
462 (term-print2 term
463 parser-max-precedence stream print-var-sort
464 vars-so-far)))
465 (:normal
466 (let ((*print-pretty* nil))
467 (term-print1 term stream print-var-sort vars-so-far)))
468 (otherwise
469 (with-output-chaos-error ('internal-error)
470 (princ "invalid print mode value ~s" *print-xmode*))))
471 ;;
472 (cdr vars-so-far)))
447 (declare (type term term)
448 (type (or t stream) stream)
449 (type (or null (not null)) print-var-sort))
450 (with-in-module ((get-context-module t))
451 (when (eq stream t)
452 (setq stream *standard-output*))
453 (let* ((vars-so-far (cons nil .printed-vars-so-far.))
454 (.file-col. (file-column stream))
455 (*print-indent* *print-indent*))
456 (case *print-xmode*
457 (:tree
458 (let ((*print-pretty* t))
459 (princ (term-to-sexpr term print-var-sort vars-so-far t)
460 stream)))
461 (:s-expr
462 (let ((*print-pretty* t))
463 (princ (term-to-sexpr term print-var-sort vars-so-far nil)
464 stream)))
465 (:fancy
466 (let ((*print-pretty* nil))
467 (term-print2 term
468 parser-max-precedence stream print-var-sort
469 vars-so-far)))
470 (:normal
471 (let ((*print-pretty* nil))
472 (term-print1 term stream print-var-sort vars-so-far)))
473 (otherwise
474 (with-output-chaos-error ('internal-error)
475 (princ "invalid print mode value ~s" *print-xmode*))))
476 (cdr vars-so-far))))
473477
474478 (defun term-print-with-sort (term &optional (stream *standard-output*))
475 (declare (type (or null term) term)
476 (type stream stream)
477 (values t))
479 (declare (type term term)
480 (type stream stream))
478481 (let ((*print-indent* (+ *print-indent* 2))
479482 (**print-var-sort** t)
480483 (paren? nil))
497500 (eq *print-xmode* :normal))
498501 (pvariable-term? term))
499502 (setq **print-var-sort** nil))
500 ;;
501503 (when paren? (princ "(" stream))
502504 (term-print term stream)
503505 (when paren? (princ ")" stream))
508510
509511 (defun term-print-with-sort-string (term &optional
510512 (print-var-sort *print-with-sort*))
511 (declare (ignore print-var-sort))
513 (declare (type term term)
514 (ignore print-var-sort))
512515 (let ((str (make-array '(0)
513516 :element-type 'base-char
514517 :fill-pointer 0
670673 ;;; SOME SPECIFIC PRINTERS
671674 ;;;-----------------------------------------------------------------------------
672675 (defun print-theory-brief (thy &optional (stream *standard-output*))
676 (declare (type op-theory thy)
677 (type stream stream))
673678 (let ((th-info (theory-info thy))
674679 (flag nil)
675680 (val (theory-zero thy)))
676 ;; (when (theory-info-is-empty-for-matching th-info)
677 ;; (princ "empty")
678 ;; (return-from print-theory-brief nil))
681 (declare (type theory-info th-info)
682 (type (or null (not null)) flag))
679683 (when (or (theory-info-is-AC th-info)
680684 (theory-info-is-A th-info)
681685 (theory-info-is-AI th-info)
712716 (term-print (car val) stream))))
713717
714718 (defun print-theory (th)
719 (declare (type op-theory th))
715720 (print-theory-info (theory-info th))
716721 (princ " zero: ")
717722 (let* ((zs (theory-zero th))
727732 (princ "NONE"))))
728733
729734 (defun print-theory-info (thinf)
735 (declare (type theory-info thinf))
730736 (prin1 (theory-info-name thinf))
731737 (princ "[") (prin1 (theory-info-code thinf)) (princ ",")
732738 (print-check)
7777 ;;; zero)
7878 (deftype op-theory () 'cons)
7979
80 (declaim (inline theory-make))
8081 (defun theory-make (info zero)
8182 (cons info zero))
8283
8384 (defmacro theory-info (_th_) `(car ,_th_))
8485 (defmacro theory-zero (_th_) `(cdr ,_th_))
8586
87 (declaim (inline zero-rule-only))
8688 (defun zero-rule-only (th)
87 (declare (type op-theory th)
88 (values (or null t)))
89 (declare (type op-theory th))
8990 (let ((val (theory-zero th)))
9091 (and val (cdr val))))
9192
118119 (defmacro theory-info-code (_th_)
119120 `(the fixnum (svref ,_th_ 1)))
120121 (defmacro theory-info-empty-for-unify (_th_)
121 `(the (or null t) (svref ,_th_ 2)))
122 `(the (or null (not null)) (svref ,_th_ 2)))
122123 (defmacro theory-info-empty-for-matching (_th_)
123 `(the (or null t) (svref ,_th_ 2)))
124 `(the (or null (not null)) (svref ,_th_ 2)))
124125 (defmacro theory-info-match-equal-fun (_th_)
125126 `(the symbol (svref ,_th_ 3)))
126127 (defmacro theory-info-match-init-fun (_th_)
156157 th))
157158
158159 (defun pr-theory-info (th-info)
160 (declare (type theory-info th-info))
159161 (format t "~%#<Theory ~s : init = ~s"
160162 (theory-info-name th-info)
161163 (theory-info-match-init-fun th-info)))
162164
163165 (defun pr-optheory-internal (opth stream &rest ignore)
164 (declare (ignore ignore))
166 (declare (type op-theory opth)
167 (type stream stream)
168 (ignore ignore))
165169 (format stream "#<Theory ~s : zero = ~s>"
166170 (theory-info-name (theory-info opth))
167171 (theory-zero opth)))
171175 (values (or null t)))
172176 (and (consp object)
173177 (typep (car object) 'vector)
174 (= 9 (length (the vector (car object))))))
178 (= 9 (the fixnum (length (the vector (car object)))))))
175179
176180 ;;; theory-info accessors via operator theory ---------------
177181
513517 (defmacro theory-info-is-ACIZ (_theory-info)
514518 `(eq the-ACIZ-property ,_theory-info))
515519
520 (declaim (inline theory-info-is-restriction-of))
516521 (defun theory-info-is-restriction-of (thn1 thn2)
517 (= 0 (logandc2 (theory-info-code thn1) (theory-info-code thn2))))
518
522 (declare (type theory-info thn1 thn2)
523 (optimize (speed 3) (safety 0)))
524 (= 0 (logandc2 (theory-info-code thn1)
525 (theory-info-code thn2))))
526
527 (declaim (inline theory-info-is-restiction-of-ignoring-id))
519528 (defun theory-info-is-restriction-of-ignoring-id (thn1 thn2)
529 (declare (type theory-info thn1 thn2)
530 (optimize (speed 3) (safety 0)))
520531 (= 0 (logandc2 (theory-info-code thn1)
521532 (logior .Z. (theory-info-code thn2)))))
522533
535546 (defmacro E-equal-in-theory (_th _t1 _t2 &optional (_unify? nil))
536547 (if _unify?
537548 `(funcall (theory-info-unify-equal-fun (theory-info ,_th)) ,_t1 ,_t2)
538 `(funcall (theory-info-match-equal-fun (theory-info ,_th)) ,_t1 ,_t2)))
539
540 #|| not used
541 (defun E-equal-in-theory-direct (th t1 t2 &optional (unify? nil))
542 (let ((theory-info (theory-info th)))
543 (cond ((or (theory-info-is-empty theory-info)
544 (theory-info-is-Z theory-info)
545 (theory-info-is-I theory-info)
546 (theory-info-is-IZ theory-info))
547 (if unify?
548 (unify-empty-equal t1 t2)
549 (match-empty-equal t1 t2)))
550 ((or (theory-info-is-AC theory-info)
551 (theory-info-is-ACI theory-info)
552 (theory-info-is-ACZ theory-info)
553 (theory-info-is-ACIZ theory-info))
554 (if unify?
555 (unify-AC-equal t1 t2)
556 (match-AC-equal t1 t2)))
557 ((or (theory-info-is-A theory-info)
558 (theory-info-is-AI theory-info)
559 (theory-info-is-AZ theory-info)
560 (theory-info-is-AIZ theory-info))
561 (if unify?
562 (unify-A-equal t1 t2)
563 (match-A-equal t1 t2)))
564 ((or (theory-info-is-C theory-info)
565 (theory-info-is-CI theory-info)
566 (theory-info-is-CZ theory-info)
567 (theory-info-is-CIZ theory-info))
568 (if unify?
569 (unify-C-equal t1 t2)
570 (match-C-equal t1 t2))))))
571
572 ||#
549 `(funcall (theory-info-match-equal-fun (theory-info ,_th)) ,_t1 ,_t2)))
573550
574551 ;;; ************************
575552 ;;; THEORY PROPERTY TESTERS ____________________________________________________
613590 `(test-theory .AC. (theory-info-code (theory-info ,*th))))
614591
615592 (defun theory-contains-AC-direct (th)
593 (declare (type op-theory th)
594 (optimize (speed 3) (safety 0)))
616595 (let ((theory-info (theory-info th)))
596 (declare (type theory-info theory-info))
617597 (or (theory-info-is-AC theory-info)
618598 (theory-info-is-ACZ theory-info)
619599 (theory-info-is-ACI theory-info)
625605 `(test-theory .I. (theory-info-code (theory-info ,*th))))
626606
627607 (defun theory-contains-idempotency-direct (th)
608 (declare (type op-theory th))
628609 (let ((theory-info (theory-info th)))
610 (declare (type theory-info theory-info))
629611 (or (theory-info-is-I theory-info)
630612 (theory-info-is-CI theory-info)
631613 (theory-info-is-IZ theory-info)
641623 `(test-theory .Z. (theory-info-code (theory-info ,*th))))
642624
643625 (defun theory-contains-identity-direct (th)
626 (declare (type op-theory th))
644627 (let ((theory-info (theory-info th)))
628 (declare (type theory-info theory-info))
645629 (or (theory-info-is-Z theory-info)
646630 (theory-info-is-CZ theory-info)
647631 (theory-info-is-AZ theory-info)
7474
7575 ;;; SORT DECLARATION
7676 (defun print-sort-decl (ast &optional (stream *standard-output*))
77 (declare (type stream stream))
7778 (format stream "(%sort-decl ~s ~s)" (%sort-decl-name ast)
7879 (%sort-decl-hidden ast)))
7980
8081 ;;; SUBSORT DECLARATION
8182 (defun print-subsort-decl (ast &optional (stream *standard-output*))
83 (declare (type %subsort-decl ast)
84 (type stream stream))
8285 (fresh-line)
8386 (let ((s-seq (remove nil (mapcar #'(lambda (x)
8487 (if (atom x)
8992
9093 ;;; BSORT DECLARATION
9194 (defun print-bsort-decl (ast &optional (stream *standard-output*))
95 (declare (type %bsort-decl)
96 (type stream stream))
9297 (let ((tp (%bsort-decl-token-predicate ast))
9398 (tc (%bsort-decl-term-creator ast))
9499 (tpr (%bsort-decl-term-printer ast))
99104
100105 ;;; PRINCIPAL-SORT-DECLARATION
101106 (defun print-psort-decl (ast &optional (stream *standard-output*))
107 (declare (type %psort-decl ast)
108 (type stream stream))
102109 (format stream "~&(%psort-decl ~s)" (%psort-decl-sort ast)))
103110
104111 ;;; Operator Reference
105112 ;;;-----------------------------------------------------------------------------
106113 (defun print-opref (ast &optional (stream *standard-output*))
114 (declare (type %opref ast)
115 (type stream stream))
107116 (format stream "~s ~s ~s" (%opref-name ast)
108117 (%opref-module ast)
109118 (%opref-num-args ast)))
110119
111120 (defun print-opref-simple (ast &optional (stream *standard-output*))
121 (declare (type %opref ast)
122 (type stream stream))
112123 (let ((*standard-output* stream)
113124 (name (%opref-name ast))
114125 (module (%opref-module ast)))
122133 ;;; Operator Declaration *TODO*
123134 ;;;-----------------------------------------------------------------------------
124135 (defun print-op-decl-ast (ast &optional (stream *standard-output*))
136 (declare (type %op-decl ast)
137 (type stream stream))
125138 (let ((*standard-output* stream)
126139 (name (%op-decl-name ast))
127140 (arity (%op-decl-arity ast))
148161 ;;; Operator Attribute declarations
149162 ;;;-----------------------------------------------------------------------------
150163 (defun print-opattrs-ast (ast &optional (stream *standard-output*))
164 (declare (type %opattrs ast)
165 (type stream stream))
151166 (let ((theory (%opattrs-theory ast))
152167 (assoc (%opattrs-assoc ast))
153168 (prec (%opattrs-prec ast))
169184 (when constr
170185 (format stream "~& - constr is specified"))
171186 (when coherent
172 (format stream "~& - coherent is specified"))
173 ))
187 (format stream "~& - coherent is specified"))))
174188
175189 ;;; Variable Declaration
176190 ;;;-----------------------------------------------------------------------------
177191 (defun print-var-decl (ast &optional (stream *standard-output*))
192 (declare (type %var-decl ast)
193 (type stream stream))
178194 (let* ((*standard-output* stream)
179195 (names (%var-decl-names ast))
180196 (sort-ref (%var-decl-sort ast))
181197 (sort-name (%sort-ref-name sort-ref))
182198 (sort-qual (%sort-ref-qualifier sort-ref)))
199 (declare (type list names)
200 (type %sort-ref sort-ref)
201 (type simple-string sort-name))
183202 (format t "~%Variable declaration : names =~{ ~a~}" names)
184203 (format t "~& Sort = ~a" sort-name)
185204 (when sort-qual
187206 (print-modexp sort-qual stream t t))))
188207
189208 (defun print-pvar-decl (ast &optional (stream *standard-output*))
209 (declare (type %pvar-decl ast)
210 (type stream stream))
190211 (let* ((*standard-output* stream)
191212 (names (%pvar-decl-names ast))
192213 (sort-ref (%pvar-decl-sort ast))
201222 ;;; LET DECLARATOIN
202223 ;;;-----------------------------------------------------------------------------
203224 (defun print-let-decl (ast &optional (stream *standard-output*))
225 (declare (type %let ast)
226 (type stream stream))
204227 (let ((sym (%let-sym ast))
205228 (value (%let-value ast)))
206229 (format stream "~%let declaration: ")
210233 ;;; MACRO DECLARATION
211234 ;;;-----------------------------------------------------------------------------
212235 (defun print-macro-decl (ast &optional (stream *standard-output*))
236 (declare (type %macro ast)
237 (type stream stream))
213238 (let ((lhs (%macro-lhs ast))
214239 (rhs (%macro-rhs ast)))
215240 (format stream "~%macro declaration:")
219244 ;;; AXIOM DECLARATION
220245 ;;;-----------------------------------------------------------------------------
221246 (defun print-axiom-decl-form (ast &optional (stream *standard-output*))
247 (declare (type %axiom-decl ast)
248 (type stream stream))
222249 (let ((type (%axiom-decl-type ast))
223250 (labels (%axiom-decl-labels ast))
224251 (lhs (%axiom-decl-lhs ast))
235262 ;;; IMPORT-DECLARATION
236263 ;;;-----------------------------------------------------------------------------
237264 (defun print-import-decl (ast &optional (stream *standard-output*))
265 (declare (type %import ast)
266 (type stream stream))
238267 (let ((mode (%import-mode ast))
239268 (mod (%import-module ast))
240269 (as (%import-alias ast)))
249278 ;;; MODULE NAME
250279 ;;;-----------------------------------------------------------------------------
251280 (defun get-module-print-name (module)
252 (unless (module-p module) (break "internal error, get-module-print-name"))
281 (declare (type module module))
253282 (let ((name (module-name module)))
254283 (if (modexp-is-simple-name name)
255284 name
256 (or (module-decl-form module) name))))
257
258 (defun make-module-print-name (mod &optional (abbrev t))
259 (with-output-to-string (name-string)
260 (print-mod-name mod name-string abbrev)
261 name-string))
285 (or (module-decl-form module) name))))
286
287 (defun print-mod-name-internal (val abbrev &optional (no-param nil))
288 (declare (type (or null (not null)) abbrev no-param))
289 (if (stringp val)
290 (princ val)
291 (if (and (consp val) (not (chaos-ast? val)))
292 (if (modexp-is-parameter-theory val)
293 ;; parameter theory
294 (if abbrev
295 (progn
296 (format t "~a" (car val))
297 (princ ".")
298 (print-mod-name (car (last val))
299 *standard-output*
300 abbrev
301 no-param))
302 (let ((cntxt (fourth val)))
303 (if (and cntxt
304 (not (eq (get-context-module) cntxt)))
305 (progn (format t "~a." (car val))
306 (print-mod-name cntxt *standard-output* t t)
307 (princ " :: "))
308 (format t "~a :: " (car val)))
309 (print-mod-name (caddr val) *standard-output* nil t)))
310 (print-chaos-object val))
311 (print-modexp val *standard-output* abbrev no-param))))
262312
263313 (defun print-mod-name (arg &optional
264314 (stream *standard-output*)
265315 (abbrev nil)
266316 (no-param nil))
267 (declare (values t))
268317 (let ((*standard-output* stream))
269318 (if (module-p arg)
270319 (let ((modname (get-module-print-name arg)))
276325 (let ((params (get-module-parameters arg)))
277326 (when (and params (not no-param))
278327 (let ((flg nil))
279 ;; (princ "[")
280328 (princ "(")
281329 (dolist (param params)
282330 (let ((theory (get-parameter-theory
287335 (eq arg (parameter-context param)))
288336 (princ (parameter-arg-name param))
289337 (progn
290 ;; (format t "~a@" (parameter-arg-name param))
291338 (format t "~a." (parameter-arg-name param))
292339 (print-mod-name (parameter-context param)
293340 stream
294341 abbrev
295342 t)))
296 ;; patch-begin
297 ;; (princ "::")
298 ;; (print-mod-name theory stream abbrev t)
299 ;; patch-end
300343 (setq flg t)))
301 ;; (princ "]")
302 (princ ")")
303 ))))
304 (print-chaos-object arg)
305 )))
306
307 (defun print-mod-name-internal (val abbrev
308 &optional
309 (no-param nil))
310 (declare (values t))
311 (if (stringp val)
312 (princ val)
313 (if (and (consp val) (not (chaos-ast? val)))
314 (if (modexp-is-parameter-theory val)
315 ;; (equal "::" (cadr val))
316 ;; parameter theory
317 (if abbrev
318 (progn
319 (format t "~a" (car val))
320 (princ ".")
321 (print-mod-name (car (last val))
322 *standard-output*
323 abbrev
324 no-param))
325 ;;
326 (let ((cntxt (fourth val)))
327 (if (and cntxt
328 (not (eq *current-module* cntxt)))
329 (progn (format t "~a." (car val))
330 (print-mod-name cntxt *standard-output* t t)
331 (princ " :: "))
332 (format t "~a :: " (car val)))
333 (print-mod-name (caddr val) *standard-output* nil t)))
334 (print-chaos-object val))
335 (print-modexp val *standard-output* abbrev no-param))))
344 (princ ")")))))
345 (print-chaos-object arg))))
346
347 (defun make-module-print-name (mod &optional (abbrev t))
348 (declare (type module mod)
349 (type (or null (not null)) abbrev))
350 (with-output-to-string (name-string)
351 (print-mod-name mod name-string abbrev)
352 name-string))
336353
337354 (defun print-simple-mod-name (module &optional (stream *standard-output*))
355 (declare (type stream stream))
338356 (if (and *open-module*
339357 (equal "%" (get-module-print-name module)))
340358 (progn
341359 (princ "%" stream)
342360 (print-mod-name *open-module* stream t nil))
343361 (print-mod-name module stream t nil)))
344
345 (defun make-module-print-name2 (mod)
346 (with-output-to-string (name-string)
347 (print-mod-name2 mod name-string t)
348 name-string))
349362
350363 (defun print-mod-name2 (arg &optional
351364 (stream *standard-output*)
357370 (let ((info (getf (module-infos arg) 'rename-mod)))
358371 (print-mod-name2 (car info) stream no-param)
359372 (princ "*DUMMY"))
360 (print-mod-name-internal2 modname no-param))
373 (print-mod-name-internal2 modname no-param))
361374 (let ((params (get-module-parameters arg)))
362375 (when (and params (not no-param))
363376 (let ((flg nil))
368381 (if flg (princ ", "))
369382 (if (eq arg (parameter-context param))
370383 (princ (parameter-arg-name param))
371 (progn
372 (format t "~a." (parameter-arg-name param))
373 (print-mod-name2 (parameter-context param)
374 stream
375 t)))
384 (progn
385 (format t "~a." (parameter-arg-name param))
386 (print-mod-name2 (parameter-context param)
387 stream
388 t)))
376389 (setq flg t)))
377 (princ ")")
378 ))))
379 ;; unknown object ...
380 (print-chaos-object arg)
381 )))
390 (princ ")")))))
391 ;; unknown object ...
392 (print-chaos-object arg))))
382393
383394 (defun print-mod-name-internal2 (val &optional (no-param nil))
384395 (if (stringp val)
392403 *standard-output*
393404 no-param))
394405 (print-chaos-object val))
395 (print-modexp val *standard-output* nil no-param))))
406 (print-modexp val *standard-output* nil no-param))))
407
408 (defun make-module-print-name2 (mod)
409 (with-output-to-string (name-string)
410 (print-mod-name2 mod name-string t)
411 name-string))
396412
397413 (defun get-parameter-theory (mod)
398414 (cond ((module-p mod)
430446 (defun print-parameter-theory-name (mod &optional (stream *standard-output*)
431447 (abbrev t)
432448 (no-param t))
449 (declare (type module mod)
450 (type stream stream)
451 (type (or null (not null)) abbrev no-param))
433452 (let ((theory (get-parameter-theory mod)))
434453 (cond ((module-p theory)
435454 (print-mod-name theory stream abbrev no-param))
442461 ;;; they may include internal objects (not AST).
443462 ;;;
444463 (defun print-modexp-simple (me &optional (stream *standard-output*))
464 (declare (type modexp me)
465 (type stream stream))
445466 (print-modexp me stream t t))
446467
447468 ;;; top level modexp printer ---------------------------------------------------
448469
449470 (declaim (inline get-context-name))
450471 (defun get-context-name (obj)
472 (declare (type object obj))
451473 (let ((context-mod (get-object-context obj)))
452474 (if context-mod
453475 (get-module-print-name context-mod)
454476 nil)))
455477
456478 (defun get-context-name-extended (obj &optional (context (get-context-module)))
479 (declare (type object obj)
480 (type module context))
457481 (let ((cmod (object-context-mod obj)))
458482 (declare (type (or null module) cmod))
459483 (unless cmod (return-from get-context-name-extended nil))
476500 (stream *standard-output*)
477501 (simple t)
478502 (no-param nil))
503 (declare (type modexp me)
504 (type stream stream)
505 (type (or null (not null)) simple no-param))
479506 (let ((.file-col. .file-col.)
480507 (*standard-output* stream))
481508 (if me
482509 (cond
483 ;;
484510 ;; The modexp internal..
485511 ((int-plus-p me) (pr-int-plus me stream simple no-param))
486512 ((int-rename-p me) (pr-int-rename me stream simple no-param))
519545 ((modexp-is-parameter-theory me)
520546 (let ((cntxt (fourth me)))
521547 (princ (car me))
522 (when (and cntxt (not (eq *current-module* cntxt)))
548 (when (and cntxt (not (eq (get-context-module) cntxt)))
523549 (princ ".")
524550 (print-mod-name cntxt stream t t)
525551 (print-check .file-col. 0 stream))))
546572
547573 ;;; *** PLUS ****
548574
549 (defun print-plus-modexp (me &optional stream simple no-param)
575 (defun print-plus-modexp (me &optional (stream *standard-output*) simple no-param)
576 (declare (type %+ me)
577 (type stream stream)
578 (type (or null (not null)) simple no-param))
550579 (let ((flg nil))
551580 (do* ((args (reverse (%plus-args me)) (cddr args))
552581 (l (car args) (car args))
566595 (print-modexp r stream simple no-param)
567596 (princ ")" stream)
568597 (decf .file-col.))
569 (print-modexp r stream simple no-param))))))
598 (print-modexp r stream simple no-param))))))
570599
571600 ;;; *** RENAME ***
572601
573 (defun print-rename-modexp (me &optional stream simple no-param)
602 (defun print-rename-modexp (me &optional (stream *standard-output*) simple no-param)
603 (declare (type modexp me)
604 (type stream stream)
605 (type (or null (not null)) simple no-param))
574606 (print-modexp (%rename-module me) stream simple no-param) (princ " * {")
575607 (print-check .file-col. 0 stream)
576608 (if simple
577609 (princ " ... " stream)
578 (print-rename-map (%rename-map me) stream)
579 )
610 (print-rename-map (%rename-map me) stream))
580611 (princ "}" stream))
581612
582613 ;;; *** INSTANTIATION ***
583614
584 (defun print-instantiation-modexp (me &optional stream simple no-param)
615 (defun print-instantiation-modexp (me &optional (stream *standard-output*)
616 simple
617 no-param)
618 (declare (type %! me)
619 (type stream stream)
620 (type (or null (not null)) simple no-param))
585621 (if (or (stringp (%instantiation-module me))
586622 (and (module-p (%instantiation-module me))
587623 (stringp (module-name (%instantiation-module me)))))
588624 (progn
589625 (print-modexp (%instantiation-module me) stream simple no-param))
590626 (progn
591 ;; (princ "(" stream)
592627 (print-modexp (%instantiation-module me) stream simple no-param)))
593628 (princ "(" stream)
594629 (incf .file-col.)
595630 (let ((flg nil)
596631 (pos-arg nil))
632 (declare (type (or null (not null)) flg pos-arg))
597633 (dolist (arg (%instantiation-args me))
598634 (let ((arg-name (%!arg-name arg))
599635 (view (%!arg-view arg)))
601637 (progn (princ ", " stream)
602638 (print-check .file-col. 0 stream))
603639 (setq flg t))
604 ;;
605640 (cond ((stringp arg-name) (princ arg-name stream))
606641 ((and (consp arg-name) (cdr arg-name))
607642 ;; (format t "~a@" (car arg-name))
619654 (unless pos-arg
620655 (princ " <= " stream))
621656 (print-view-modexp-abbrev view stream simple))))
622 ;; (princ "]" stream)
623657 (princ ")" stream)
624658 (decf .file-col.))
625659
626660 ;;; *** Sort renaming ***
627661
628662 (defun print-ren-sort (ast &optional (stream *standard-output*) pretty)
663 (declare (type %ren-sort ast)
664 (type stream stream)
665 (type (or null (not null)) pretty))
629666 (let ((*standard-output* stream)
630667 (p-flg nil))
668 (declare (type (or null (not null)) p-flg))
631669 (dolist (elt (%ren-sort-maps ast))
632670 (if p-flg
633671 (progn (princ ",")
643681 ;;; *** Operator renaming ***
644682
645683 (defun print-ren-op (ast &optional (stream *standard-output*) pretty)
684 (declare (type %ren-op ast)
685 (type stream stream)
686 (type (or null (not null)) pretty))
646687 (let ((*standard-output* stream)
647688 (p-flg nil))
648689 (dolist (elt (%ren-op-maps ast))
651692 (princ "op ")
652693 (if (%is-opref (car elt))
653694 (print-opref-simple (car elt))
654 (print-simple-princ-open (car elt)))
695 (print-simple-princ-open (car elt)))
655696 (print-check .file-col. 0 stream)
656697 (princ " -> ")
657698 (if (%is-opref (cadr elt))
658699 (print-opref-simple (cadr elt))
659 (print-simple-princ-open (cadr elt))))))
700 (print-simple-princ-open (cadr elt))))))
660701
661702 ;;; Parameter renaming
662703
663704 (defun print-ren-param (ast &optional (stream *standard-output*))
705 (declare (type %ren-param ast)
706 (type stream stream))
664707 (let ((*standard-output* stream)
665708 source
666709 target)
674717 ;;; vars in mapping
675718
676719 (defun print-vars-ast (ast &optional (stream *standard-output*) pretty)
720 (declare (type %vars ast)
721 (type stream stream)
722 (type (or null (not null)) pretty))
677723 (let ((p-flg nil))
724 (declare (type (or null (not null)) p-flg))
678725 (dolist (elt (%vars-elements ast))
679726 (let ((var-names (car elt))
680727 (sort (cadr elt)))
689736 ;;; *** RENAME MAP ***
690737
691738 (defun print-rename-map (rn &optional (stream *standard-output*) simple no-param pretty)
692 (declare (ignore simple no-param))
739 (declare (type stream stream)
740 (ignore simple no-param))
693741 (let ((*standard-output* stream))
694742 (cond ((null rn) (princ " ## EMPTY RENAME MAP ##")) ; for debugging.
695743 ((%is-rmap rn)
709757
710758 ;;; RENAME
711759 (defun pr-int-rename (obj &optional (stream *standard-output*) simple no-param)
712 ;; (declare (ignore simple no-param))
713 (declare (ignore no-param))
760 (declare (type stream stream)
761 (type (or null (not null)) simple)
762 (ignore no-param))
714763 (let ((*standard-output* stream))
715764 (print-modexp (int-rename-module obj) stream t t)
716765 (princ " *{ " stream)
743792
744793 ;;; PLUS
745794 (defun pr-int-plus (obj &optional (stream *standard-output*) simple no-param)
746 (declare (ignore simple no-param))
795 (declare (type stream stream)
796 (ignore simple no-param))
747797 (let ((*standard-output* stream))
748798 (let ((*print-indent* (+ *print-indent* 4))
749799 (flg nil))
750800 (dolist (mod (int-plus-args obj))
751801 (print-check)
752802 (when flg (princ " + "))
753 ;; (print-modexp mod stream simple no-param)
754803 (print-modexp mod stream t t)
755804 (setq flg t)))))
756805
758807 (defun pr-int-instantiation (obj &optional
759808 (stream *standard-output*)
760809 simple no-param)
761 (declare (ignore simple no-param))
810 (declare (type stream stream)
811 (ignore simple no-param))
762812 (let ((*standard-output* stream))
763813 (let ((*print-indent* (+ *print-indent* 4)))
764 ;; (print-modexp (int-instantiation-module obj) stream simple no-param)
765814 (print-modexp (int-instantiation-module obj) stream t t)
766 ;; (princ "[ ")
767815 (princ "(")
768816 (let ((flg nil))
769817 (dolist (arg (int-instantiation-args obj))
772820 (pos-arg nil))
773821 (cond ((stringp arg-name) (princ arg-name stream))
774822 ((and (consp arg-name) (cdr arg-name))
775 ;; (format t "~a@" (car arg-name))
776823 (format t "~a." (car arg-name))
777824 (print-chaos-object (cdr arg-name) stream))
778825 ((consp arg-name) (princ (car arg-name) stream))
788835 (unless pos-arg
789836 (princ " <= "))
790837 (let ((*print-indent* (+ *print-indent* 4)))
791 ;; (print-view (%!arg-view arg) stream simple no-param)
792 (print-view (%!arg-view arg) stream t t)
793 ))
838 (print-view (%!arg-view arg) stream t t)))
794839 (print-check)))
795 ;; (princ " ]")
796840 (princ ")"))))
797841
798842 ;;;-----------------------------------------------------------------------------
800844 ;;;-----------------------------------------------------------------------------
801845
802846 (defun print-view-internal (vw &optional (stream *standard-output*) &rest ignore)
803 (declare (ignore ignore))
847 (declare (type stream stream)
848 (ignore ignore))
804849 (print-view vw stream))
805850
806851 (defun print-view (vw &optional (stream *standard-output*) simple no-param
807852 (syntax *show-mode*))
853 (declare (type stream stream)
854 (type symbol syntax)
855 (type (or null (not null)) simple no-param))
808856 (if (eq syntax :cafeobj)
809857 (print-view-in-cafeobj-mode vw
810858 stream simple
815863 no-param)))
816864
817865 (defun print-view-in-cafeobj-mode (vw stream simple no-param)
866 (declare (type stream stream)
867 (type (or null (not null)) simple no-param))
818868 (cond ((and (not (stringp vw))
819869 (chaos-ast? vw)
820870 (memq (ast-type vw)
854904 ;;
855905 ((and (consp vw) (stringp (car vw))) (princ vw stream))
856906 ((atom vw) (princ vw stream))
857 (t (print-modexp vw stream simple no-param))
858 ))
907 (t (print-modexp vw stream simple no-param))))
859908
860909 (defun print-view-in-chaos-mode (vw stream &rest ignore)
861 (declare (ignore ignore))
910 (declare (type stream stream)
911 (ignore ignore))
862912 (let ((*print-pretty* t))
863913 (format stream "~%~s" (object-decl-form vw))))
864914
865915 (defun print-view-struct-maps (view stream &rest ignore)
866 (declare (ignore ignore))
916 (declare (type stream stream)
917 (ignore ignore))
867918 (let ((*print-indent* (+ *print-indent* 2))
868919 (sort-maps (view-sort-maps view))
869920 (op-maps (view-op-maps view))
888939 (princ "(")(print-chaos-object (term-head (cadr pm)))(princ ")"))))
889940
890941 (defun print-abs-view-mapping (map stream simple no-param pretty)
891 (declare (ignore simple no-param))
942 (declare (type stream stream)
943 (ignore simple no-param))
892944 (unless map (return-from print-abs-view-mapping nil))
893945 (let ((rmap (if (%is-rmap map)
894946 (%rmap-map map)
906958 (print-ren-op opmaps stream pretty)))))
907959
908960 (defun print-view-modexp (me &optional (stream *standard-output*) simple no-param)
961 (declare (type %view me)
962 (type stream stream)
963 (type (or null (not null)) simple no-param))
909964 (when (%view-map me)
910965 (if simple
911966 (princ "{ ... }" stream)
926981
927982 (defun print-view-modexp-abbrev (me &optional
928983 (stream *standard-output*) simple no-param)
984 (declare (type stream stream)
985 (type (or null (not null)) simple no-param))
929986 (let ((target (if (view-p me)
930987 (view-target me)
931988 (if (modexp-is-view me)
937994 (with-output-panic-message ()
938995 (format t "print-view, given invalid view : ")
939996 (prin1 me))))
940 ;; (chaos-error 'invalid-view))))
941997 (when (stringp me)
942998 (return-from print-view-modexp-abbrev nil))
943999 (when (and (not (view-p me)) (%view-map me))
9541010 (defun print-view-mapping (vwmap &optional
9551011 (stream *standard-output*) simple no-param
9561012 pretty)
1013 (declare (type stream stream)
1014 (type (or null (not null)) simple no-param pretty))
9571015 (unless vwmap (return-from print-view-mapping nil))
9581016 (print-rename-map vwmap stream simple no-param pretty))
9591017
9641022 ;;; OPERATOR **********
9651023
9661024 (defun print-operator-internal (op &optional (stream *standard-output*))
1025 (declare (type operator op)
1026 (type stream stream))
9671027 (format stream "~a/~a."
9681028 (operator-symbol op)
9691029 (operator-num-args op))
9701030 (print-mod-name (operator-module op) stream))
9711031
9721032 (defun print-op-name (op)
1033 (declare (type operator op))
9731034 (format t "~a/~a" (operator-symbol op) (operator-num-args op)))
9741035
9751036 ;;; SORT **************
9761037
9771038 (defun print-sort-internal (sort &optional (stream *standard-output*) ignore)
978 (declare (ignore ignore))
1039 (declare (type sort* sort)
1040 (type stream stream)
1041 (ignore ignore))
9791042 (print-sort-name sort (get-object-context sort) stream))
9801043
981 (defun print-record-internal (sort &optional (stream *standard-output*) ignore)
982 (declare (ignore ignore))
1044 (defun print-bsort-internal (sort &optional (stream *standard-output*) ignore)
1045 (declare (type bsort sort)
1046 (type stream stream)
1047 (ignore ignore))
9831048 (print-sort-name sort (get-object-context sort) stream))
9841049
985 (defun print-class-internal (sort &optional (stream *standard-output*) ignore)
986 (declare (ignore ignore))
1050 (defun print-and-sort-internal (sort &optional (stream *standard-output*) ignore)
1051 (declare (type and-sort sort)
1052 (type stream stream)
1053 (ignore ignore))
9871054 (print-sort-name sort (get-object-context sort) stream))
9881055
989 (defun print-bsort-internal (sort &optional (stream *standard-output*) ignore)
990 (declare (ignore ignore))
1056 (defun print-or-sort-internal (sort &optional (stream *standard-output*) ignore)
1057 (declare (type or-sort sort)
1058 (type stream stream)
1059 (ignore ignore))
9911060 (print-sort-name sort (get-object-context sort) stream))
9921061
993 (defun print-and-sort-internal (sort &optional (stream *standard-output*) ignore)
994 (declare (ignore ignore))
1062 (defun print-err-sort-internal (sort &optional (stream *standard-output*) ignore)
1063 (declare (type err-sort sort)
1064 (type stream stream)
1065 (ignore ignore))
9951066 (print-sort-name sort (get-object-context sort) stream))
9961067
997 (defun print-or-sort-internal (sort &optional (stream *standard-output*) ignore)
998 (declare (ignore ignore))
999 (print-sort-name sort (get-object-context sort) stream))
1000
1001 (defun print-err-sort-internal (sort &optional (stream *standard-output*) ignore)
1002 (declare (ignore ignore))
1003 (print-sort-name sort (get-object-context sort) stream))
1004
10051068 ;;; MODULE ************
10061069
10071070 (defun print-module-internal (module &optional (stream *standard-output*) ignore)
1008 (declare (ignore ignore))
1071 (declare (type module module)
1072 (type stream stream)
1073 (ignore ignore))
10091074 (print-mod-name module stream t nil))
10101075
10111076 ;;; AXIOM *************
10121077
10131078 (defun print-axiom-internal (ax &optional (stream *standard-output*) ignore)
1014 (declare (ignore ignore))
1079 (declare (type rewrite-rule ax)
1080 (type stream stream)
1081 (ignore ignore))
10151082 (print-axiom-brief ax stream))
10161083
10171084 ;;; REWRITE RULE *****
10181085 (defun print-rule-internal (rule &optional (stream *standard-output*) ignore)
1019 (declare (ignore ignore))
1086 (declare (type rewrite-rule rule)
1087 (type stream stream)
1088 (ignore ignore))
10201089 (let ((cnd (not (term-is-similar? *BOOL-true* (rule-condition rule))))
10211090 (.printed-vars-so-far. nil))
10221091 (when (rule-labels rule)
10501119 ;;; METHOD ************
10511120
10521121 (defun print-method-internal (meth &optional (stream *standard-output*) ignore)
1053 (declare (ignore ignore))
1122 (declare (type method meth)
1123 (type stream stream)
1124 (ignore ignore))
10541125 (let ((mod (get-object-context meth))
10551126 (.file-col. .file-col.))
1127 (declare (type module mod))
10561128 (format stream "~{~A~} :" (method-symbol meth))
10571129 (setq .file-col. (file-column stream))
10581130 (mapc #'(lambda (x)
10721144 ;;;-----------------------------------------------------------------------------
10731145
10741146 (defun print-modmorph (mppg)
1147 (declare (type modmorph mppg))
10751148 (format t "~%Module morphism:")
10761149 (format t "~& name: ") (print-chaos-object (modmorph-name mppg))
10771150 (format t "~& sort: ")
10981171 ;;;
10991172 (defun print-sort-name (s &optional (module (get-object-context s))
11001173 (stream *standard-output*))
1101 (unless (sort-struct-p s) (break "print-sort-name: given non sort: ~s" s))
1174 (declare (type sort* s)
1175 (type module module)
1176 (type stream stream))
11021177 (let ((*standard-output* stream)
11031178 (mod-name (get-module-print-name (sort-module s))))
11041179 (cond ((and module
11111186 (print-mod-name cntxt stream t t)))
11121187 (progn
11131188 (format t "~a." (string (sort-id s)))
1114 ;; (print-simple-mod-name (sort-module s))
11151189 (print-mod-name (sort-module s) stream t t))))
11161190 (t (format t "~a" (string (sort-id s)))))))
11171191
1118 (defun sort-print-name (sort &optional (with-mod-qualifier))
1192 (defun sort-print-name (sort &optional with-mod-qualifier)
1193 (declare (type sort* sort)
1194 (type (or null (not null)) with-mod-qualifier))
11191195 (with-output-to-string (str)
11201196 (let ((*standard-output* str))
11211197 (if with-mod-qualifier
11281204 ;;; PRINT-SORT-LIST
11291205 ;;;
11301206 (defun print-sort-list (lst &optional
1131 (module *current-module*)
1207 (module (get-context-module))
11321208 (stream *standard-output*))
1209 (declare (type list lst)
1210 (type module module)
1211 (type stream stream))
11331212 (let ((*standard-output* stream))
11341213 (let ((flag nil))
11351214 (dolist (s lst)
11371216 (if flag (princ " ") (setq flag t))
11381217 (print-sort-name s module)))))
11391218
1140 (defun print-sort-name2 (sort &optional (module *current-module*)
1141 (stream *standard-output*))
1219 (defun print-sort-name2 (sort &optional (module (get-context-module))
1220 (stream *standard-output*))
1221 (declare (type sort* sort)
1222 (type module module)
1223 (stream stream))
11421224 (let ((*standard-output* stream)
11431225 (*current-sort-order* (module-sort-order module)))
11441226 (let ((subs (subsorts sort))
11771259 (print-simple-princ (cadr qop))
11781260 (princ ".")
11791261 (print-qual-sort-name (caddr qop)))
1180 (if (consp qop)
1181 (let ((flag nil))
1182 (dolist (x qop)
1183 (if flag (princ " ") (setq flag t))
1184 (if (consp x) (print-qual-sort-name x)
1262 (if (consp qop)
1263 (let ((flag nil))
1264 (dolist (x qop)
1265 (if flag (princ " ") (setq flag t))
1266 (if (consp x) (print-qual-sort-name x)
11851267 (princ x))))
11861268 (print-simple-princ-open qop))))
11871269
11941276 (equal l (append iota '(0))))))
11951277
11961278 (defun print-check-bu-meth (method l)
1279 (declare (type method method))
11971280 (let ((iota (make-list-1-n (length (method-arity method)))))
11981281 (or (equal l iota)
11991282 (equal l (append iota '(0))))))
12001283
12011284 (defun print-method-brief (meth)
1202 (unless (method-p meth)
1203 (format t "[print-method-brief]: Illegal method given ~a" meth)
1204 (return-from print-method-brief nil))
1285 (declare (type method meth))
12051286 (let* ((*print-indent* (+ 4 *print-indent*))
12061287 (.file-col. *print-indent*)
12071288 (is-predicate (method-is-predicate meth)))
12171298 (setq .file-col. (1- (file-column *standard-output*)))
12181299 (when (method-arity meth)
12191300 (dolist (ar (method-arity meth))
1220 (print-sort-name ar *current-module*)
1301 (print-sort-name ar (get-context-module))
12211302 (princ " ")
12221303 (print-check .file-col. 0)))
12231304 (unless is-predicate
12241305 (princ "-> ")
1225 (print-sort-name (method-coarity meth) *current-module*))
1306 (print-sort-name (method-coarity meth) (get-context-module)))
12261307 (print-check .file-col. 0)
12271308 (print-method-attrs meth)))
12281309
12291310 (defun operator-decl-form-string (op)
1311 (declare (type method op))
12301312 (with-output-to-string (stream nil)
12311313 (let ((*standard-output* stream))
12321314 (print-method-brief op))
12341316
12351317 ;;; PRINT-OP-BRIEF operator
12361318 ;;;
1237 (defun print-op-brief (op &optional (module *current-module*)
1319 (defun print-op-brief (op &optional (module (get-context-module))
12381320 (all t)
12391321 (every nil)
12401322 (show-context nil))
1323 (declare (type operator op)
1324 (type module module)
1325 (type (or null (not null)) all every show-context))
12411326 (let* ((*print-indent* *print-indent*)
12421327 (opinfo (get-operator-info op (module-all-operators module)))
12431328 (methods (if all
12621347 ;;; PRINT-OP-METH
12631348 ;;;
12641349 (defun print-op-meth (op-meth mod &optional (all t))
1350 (declare (type module mod)
1351 (type list op-meth))
12651352 (let ((op (car op-meth))
12661353 (methods (if all
12671354 (cadr op-meth)
12801367 (print-method-brief meth)))))))
12811368
12821369 (defun print-op-meth2 (op-meth mod &optional (all t))
1370 (declare (type list op-meth)
1371 (type module mod)
1372 (type (or null (not null)) all))
12831373 (with-in-module (mod)
12841374 (let ((op (car op-meth))
12851375 (methods (if all
13111401 ;;; PRINT-TERM-HEAD : term module stream -> void
13121402 ;;;
13131403 (defun print-term-head (term &optional
1314 (module *current-module*)
1404 (module (get-context-module))
13151405 (stream *standard-output*))
1406 (declare (type term term)
1407 (type module module)
1408 (type stream stream))
13161409 (if (operator-method-p term)
13171410 (print-method term module stream)
1318 (if (term-is-builtin-constant? term)
1319 (print-bi-constant-method term module stream)
1320 (print-method (term-head term) module stream))))
1411 (if (term-is-builtin-constant? term)
1412 (print-bi-constant-method term module stream)
1413 (print-method (term-head term) module stream))))
13211414
13221415 ;;; PRINT-METHOD : method module stream -> void
13231416 ;;;
13241417 (defun print-method (method &optional
1325 (module *current-module*)
1418 (module (get-context-module))
13261419 (stream *standard-output*))
1420 (declare (type method method)
1421 (type module module)
1422 (type stream stream))
13271423 (format stream "~{~a~} : " (method-symbol method))
13281424 (print-sort-list (method-arity method) module stream)
13291425 (princ " -> " stream)
13311427
13321428 ;;; METHOD-PRINT-STRING
13331429 ;;;
1334 (defun method-print-string (meth &optional (module *current-module*))
1430 (defun method-print-string (meth &optional (module (get-context-module)))
1431 (declare (type method meth)
1432 (type module module))
13351433 (with-output-to-string (str)
13361434 (print-method meth module str)
13371435 str))
13391437 ;;; PRINT-BI-CONSTANT-METHOD (term &optional module stream)
13401438 ;;;
13411439 (defun print-bi-constant-method (term &optional
1342 (module *current-module*)
1440 (module (get-context-module))
13431441 (stream *standard-output*))
1442 (declare (type term term)
1443 (type module module)
1444 (type stream stream))
13441445 (princ (term-builtin-value term) stream)
13451446 (princ " : -> ")
13461447 (print-sort-name (term-sort term) module stream))
13471448
13481449
1349 ;;; BI-METHOD-PRINT-STRING (term &optional (module *current-module*))
1450 ;;; BI-METHOD-PRINT-STRING
13501451 ;;;
1351 (defun bi-method-print-string (term &optional (module *current-module*))
1452 (defun bi-method-print-string (term &optional (module (get-context-module)))
1453 (declare (type term term)
1454 (type module module))
13521455 (with-output-to-string (str)
13531456 (print-bi-constant-method term module)))
13541457
13571460 ;;;-----------------------------------------------------------------------------
13581461
13591462 (defun print-op-attrs (op)
1463 (declare (type operator op))
13601464 ;; print "attributes" -- for the moment ignore purely syntactic
13611465 ;; -- i.e. precedence and associativity .
13621466 (let ((strat (let ((val (operator-strategy op)))
13861490 (princ " }")))))
13871491
13881492 (defun print-method-attrs (method &optional header)
1493 (declare (type method method))
13891494 (let ((strat (let ((val (method-rewrite-strategy method)))
13901495 (if (print-check-bu-meth method val) nil val)))
13911496 (constr (method-constructor method))
14651570 (defun print-id-condition (x stream) (print-id-cond x 10) stream)
14661571
14671572 (defun print-id-cond (x p &optional (stream *standard-output*))
1468 (declare (type fixnum p))
1573 (declare (type fixnum p)
1574 (type stream stream))
14691575 (let ((*standard-output* stream))
14701576 (cond ((eq 'and (car x))
14711577 (let ((paren (< p 4)))
15011607 (print-id-cond c r))))
15021608
15031609 (defun print-rule-labels (rul)
1610 (declare (type axiom rul))
15041611 (let ((labels (axiom-labels rul)))
15051612 (unless *chaos-verbose*
15061613 ;; (format t "~%~{~s~^ ~}" labels)
15181625 (full-stop nil))
15191626 (declare (type axiom rul)
15201627 (type stream stream)
1521 (type (or null t) no-type no-label meta))
1628 (type (or null (not null)) no-type no-label meta full-stop))
15221629 (let ((type (axiom-type rul))
15231630 (cnd (not (term-is-similar? *BOOL-true* (axiom-condition rul))))
15241631 (.printed-vars-so-far. nil)
16131720 (princ " ."))))
16141721
16151722 (defun print-rule-id-inf (x)
1723 (declare (type list x))
16161724 (print-axiom-brief (nth 0 x)) (terpri)
16171725 (print-substitution (nth 1 x))
16181726 (when (cddr x)
16191727 (progn (print-chaos-object (nth 2 x) nil) (terpri))))
16201728
16211729 (defun print-rule (rul)
1730 (declare (type axiom rul))
16221731 (let ((type (axiom-type rul))
16231732 (cond (not (term-is-similar? *bool-true* (axiom-condition rul))))
16241733 (rul-rhs (axiom-rhs rul))
16281737 (if cond
16291738 (if (axiom-is-behavioural rul)
16301739 (princ "- conditional behavioural equation ")
1631 (princ "- conditional equation "))
1632 (if (axiom-is-behavioural rul)
1633 (princ "- behavioural equation ")
1634 (princ "- equation "))))
1740 (princ "- conditional equation "))
1741 (if (axiom-is-behavioural rul)
1742 (princ "- behavioural equation ")
1743 (princ "- equation "))))
16351744 (:rule
16361745 (if cond
16371746 (if (axiom-is-behavioural rul)
16381747 (princ "- conditional behavioural transition ")
1639 (princ "- conditional transition "))
1640 (if (axiom-is-behavioural rul)
1641 (princ "- behavioural transition ")
1642 (princ "- transition "))))
1748 (princ "- conditional transition "))
1749 (if (axiom-is-behavioural rul)
1750 (princ "- behavioural transition ")
1751 (princ "- transition "))))
16431752 (:pignose-axiom
16441753 (if (axiom-is-behavioural rul)
16451754 (princ "- behavioural FOPL axiom ")
16801789 (print-next)
16811790 (princ "* lhs is a variable."))
16821791 (t
1683 (let ((head (term-head lhs)))
1792 (let ((head (term-head lhs))
1793 (cntxt (get-context-module)))
16841794 (print-next)
16851795 (princ "top operator : ")
16861796 (when (method-arity head)
1687 (print-sort-list (method-arity head) *current-module*)
1797 (print-sort-list (method-arity head) cntxt)
16881798 (princ " "))
16891799 (princ "-> ")
1690 (print-sort-name (method-coarity head) *current-module*)))
1691 )
1692 ;;
1800 (print-sort-name (method-coarity head) cntxt))))
16931801 (when (axiom-id-condition rul)
16941802 (print-next)
16951803 (princ "id condition : ")
17421850
17431851 ;;; *TODO*
17441852 (defun print-rules-detail (mod)
1853 (declare (type module mod))
17451854 (let ((rules (module-rules mod)))
17461855 (dolist (r rules)
17471856 (print-chaos-object r) (terpri))))
17491858 ;;; axiom-declaration-string : axiom -> string
17501859 ;;;
17511860 (defun axiom-declaration-string (axiom &optional (mod (get-context-module)))
1861 (declare (type axiom axiom)
1862 (type module mod))
17521863 (with-output-to-string (stream)
17531864 (with-in-module (mod)
17541865 (let ((*term-print-depth* nil)
17701881 ;;;-----------------------------------------------------------------------------
17711882
17721883 (defun print-mapping (mppg &optional (stream *standard-output*))
1884 (declare (type modmorph mppg)
1885 (type stream stream))
17731886 (let ((*standard-output* stream)
17741887 (*print-indent* (1+ *print-indent*))
17751888 (*print-array* nil)
18171930 (print-mod-name (method-module head)
18181931 *standard-output*
18191932 t t)
1820 (princ ")")))
1821 )
1933 (princ ")"))))
18221934 (decf *print-indent* 2)
18231935 (print-next)
18241936 (princ "module mappings: ")
18341946 ;;;-----------------------------------------------------------------------------
18351947
18361948 (defun print-rule-ring (rr &optional (stream *standard-output*))
1949 (declare (type rule-ring rr)
1950 (type stream stream))
18371951 (princ "rule ring: " stream)
18381952 (do ((rule (initialize-rule-ring rr) (rule-ring-next rr)))
18391953 ;; avoid end-test so can trace it
18471961 ;;; SUBSTITUTION
18481962
18491963 (defun print-substitution (subst &optional (stream *standard-output*))
1964 (declare (type substitution subst)
1965 (type stream stream))
18501966 (let ((.file-col. .file-col.))
18511967 (if (or (substitution-is-empty subst)
18521968 (null (car subst)))
18711987 ;;; PARSE DICTIONARY
18721988
18731989 (defun show-parse-dict (dict)
1990 (declare (type parse-dictionary dict))
18741991 (format t "~%Parse Dictionary:")
18751992 (maphash #'(lambda (key val)
18761993 (format t "~% -- key = ~s" key)
18912008 ;;; SORT ORDER
18922009
18932010 (defun pp-sort-order (&optional (sort-order *current-sort-order*))
2011 (declare (type sort-order sort-order))
18942012 (maphash #'(lambda (sort sort-rel)
18952013 (format t "~%[Sort : ~A](~a)" (sort-print-name sort) sort)
18962014 (format t "~% Subsorts : ~{ ~A~}(~{ ~a~})"
19072025
19082026 (defun pp-sort-order-raw (module &optional
19092027 (sort-order (module-sort-order module)))
2028 (declare (type module module)
2029 (type sort-order sort-order))
19102030 (with-in-module (module)
19112031 (maphash #'(lambda (sort sort-rel)
19122032 (format t "~%[Sort : ~A](~a)" (sort-print-name sort) sort)
19242044
19252045 ;;; MODULE INSTANCE DB
19262046
1927 (defun print-instance-db (&optional (module *current-module*))
2047 (defun print-instance-db (&optional (module (get-context-module)))
2048 (declare (type module module))
19282049 (let ((db (module-instance-db module)))
19292050 (unless db
19302051 (format t "~%module ")
263263 (values list))
264264 (sort (copy-list s) ; (substitution-copy s)
265265 #'(lambda (x y) ; two substitution items (var . term)
266 (string< (the simple-string (string (variable-name (car x))))
267 (the simple-string (string (variable-name (car y))))))))
266 (string< (the simple-string (string (the symbol (variable-name (car x)))))
267 (the simple-string (string (the symbol (variable-name (car y)))))))))
268268
269269
270270 ;;; SUBSTITUTION-EQUAL : substitution1 substitution2 -> Bool
286286 (values list))
287287 (let ((res nil))
288288 (dolist (s sub)
289 (when (member (car s) vars)
289 (when (member (car s) vars :test #'variable=)
290290 (push s res)))
291291 res))
292292
484484 (defvar *variable-as-constant* nil)
485485
486486 (defun make-pconst-from-var (var)
487 (declare (optimize (speed 3) (safety 0)))
487 (declare (type term var)
488 (optimize (speed 3) (safety 0)))
488489 (let ((name (variable-name var))
489490 (print-name (variable-print-name var))
490491 (sort (variable-sort var))
491492 (unique-marker (gensym))
492493 (pc-name nil)
493494 (pc-pname nil))
495 (declare (type symbol name unique-marker pc-name pc-pname print-name)
496 (type sort* sort))
494497 (setq pc-name (intern (concatenate 'string "`" (string unique-marker) "-" (string name))))
495498 (if print-name
496499 (setq pc-pname (intern (concatenate 'string "`" (string print-name))))
266266 #+GCL
267267 (defentry addr-of (object) (object addr_of))
268268
269 (defvar .32bit. #xffffffff)
269 (defconstant .32bit. #xffffffff)
270270
271271 #-GCL
272272 (declaim (inline addr-of))
150150 (print-next)
151151 (print-axiom-brief (rule-pat-rule (rwl-state-rule-pat sub))))
152152 (incf arc-num))))
153
154 ;;; ***********
155 ;;; SEARCH TREE
156 ;;; ***********
157
158 ;;; Search tree
159 ;;; - bi-directional dag (see comlib/dag.lisp)
160 ;;; - datum contains an instance of rwl-state.
161 ;;;
162 (defstruct (rwl-sch-node (:include bdag)
163 (:conc-name "SCH-NODE-")
164 (:print-function pr-rwl-sch-node))
165 (done nil :type (or null t)) ; t iff this node is checked already
166 (is-solution nil :type (or null t)) ; t iff this node found as a solution
167 )
168
169 (defmacro create-sch-node (rwl-state)
170 `(make-rwl-sch-node :datum ,rwl-state :subnodes nil :parent nil :is-solution nil))
171
172 (defun pr-rwl-sch-node (node &optional (stream *standard-output*) &rest ignore)
173 (declare (ignore ignore))
174 (let ((*standard-output* stream))
175 (format t "SCH-NODE:~A" (dag-node-datum node))))
153176
154177 ;;; **************
155178 ;;; SEARCH CONTEXT
185208 )
186209
187210 (defun print-sch-context (ctxt &optional (stream *standard-output*) &rest ignore)
188 (declare (ignore ignore))
211 (declare (type rwl-sch-context ctxt)
212 (type stream stream)
213 (ignore ignore))
189214 (let ((*standard-output* stream)
190215 (mod (rwl-sch-context-module ctxt)))
191216 (with-in-module (mod)
222247 (format t "~% if: ")
223248 (term-print-with-sort (rwl-sch-context-if ctxt))))))
224249
225 ;;; ***********
226 ;;; SEARCH TREE
227 ;;; ***********
228
229 ;;; Search tree
230 ;;; - bi-directional dag (see comlib/dag.lisp)
231 ;;; - datum contains an instance of rwl-state.
232 ;;;
233 (defstruct (rwl-sch-node (:include bdag)
234 (:conc-name "SCH-NODE-")
235 (:print-function pr-rwl-sch-node))
236 (done nil :type (or null t)) ; t iff this node is checked already
237 (is-solution nil :type (or null t)) ; t iff this node found as a solution
238 )
239
240 (defmacro create-sch-node (rwl-state)
241 `(make-rwl-sch-node :datum ,rwl-state :subnodes nil :parent nil :is-solution nil))
242
243 (defun pr-rwl-sch-node (node &optional (stream *standard-output*) &rest ignore)
244 (declare (ignore ignore))
245 (let ((*standard-output* stream))
246 (format t "SCH-NODE:~A" (dag-node-datum node))))
247250
248251 ;;; ******************
249252 ;;; RWL-SCH-NODE utils