Debian Codegraph @

thstuff/case.lisp

raw
1 ;;;-*- Mode:LISP; Package:CHAOS; Base:10; Syntax:Common-lisp -*-
2 ;;;
3 ;;; Copyright (c) 2000-2015, Toshimi Sawada. All rights reserved.
4 ;;;
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
7 ;;; are met:
8 ;;;
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
11 ;;;
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
16 ;;;
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ;;;
29 (in-package :chaos)
30 #|==============================================================================
31 System: CHAOS
32 Module: thstuff
33 File: base.lisp
34 ==============================================================================|#
35
36 (defparameter .case-module-true. (%module-decl* "true-dummy" :object :user nil))
37 (defparameter .case-module-false. (%module-decl* "false-dummy" :object :user nil))
38 (defparameter .case-true-axiom. (%axiom-decl* :equation '(":case_true") :LHS '("true") nil nil))
39 (defparameter .case-false-axiom. (%axiom-decl* :equation '(":case_false") :LHS '("false") nil nil))
40
41 (defun perform-case-reduction (ast)
42 (let ((bool-term (%scase-bool-term ast))
43 (module (%scase-module ast))
44 (name (%scase-name ast))
45 (body (parse-module-elements (%scase-body ast)))
46 (goal-term (%scase-goal-term ast)))
47 ;; prepare modules
48 (setf (%module-decl-name .case-module-true.) (concatenate 'string name "-#T"))
49 (setf (%module-decl-name .case-module-false.) (concatenate 'string name "-#F"))
50 ;; (push (%import* :including (parse-modexp module)) body)
51 (push (%import* :including module) body)
52 (setf (%axiom-decl-lhs .case-true-axiom.) bool-term)
53 (setf (%module-decl-elements .case-module-true.) (append body (list .case-true-axiom.)))
54 (setf (%axiom-decl-lhs .case-false-axiom.) bool-term)
55 (setf (%module-decl-elements .case-module-false.) (append body (list .case-false-axiom.)))
56 ;;
57 (let ((org-mod (eval-modexp module))
58 (true-mod (eval-ast .case-module-true.))
59 (false-mod (eval-ast .case-module-false.)))
60 (when (modexp-is-error org-mod)
61 (with-output-chaos-error ('no-such-module)
62 (format t "No such module or invalid module expression ~s" module)))
63
64 ;; CASE TRUE
65 (with-in-module (true-mod)
66 (compile-module *current-module*)
67 ;;
68 (with-output-simple-msg ()
69 (format t "===================~%")
70 (format t ">>* CASE: true *<<~%")
71 (format t "==================="))
72 (perform-reduction* goal-term true-mod :red))
73
74 ;; CASE FALSE
75 (with-in-module (false-mod)
76 (compile-module *current-module*)
77 ;;
78 (with-output-simple-msg ()
79 (format t "===================~%")
80 (format t ">>* CASE: false *<<~%")
81 (format t "==================="))
82 (perform-reduction* goal-term false-mod :red)))))
83
84
85
86 ;;; EOF
87