annotate lisp/mule/mule-ccl.el @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents 131b0175ea99
children 78f53ef88e17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 ;;; mule-ccl.el --- Code Conversion Language functions.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 ;; any later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 ;; General Public License for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20 ;; Boston, MA 02111-1307, USA.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 ;;; 93.5.26 created for Mule Ver.0.9.8 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 ;;;; #### This stuff doesn't work yet.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 (defconst ccl-operator-table
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27 '[if branch loop break repeat write-repeat write-read-repeat
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28 read read-if read-branch write end])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 (let (op (i 0) (len (length ccl-operator-table)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32 (setq op (aref ccl-operator-table i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 (put op 'ccl-compile-function (intern (format "ccl-compile-%s" op)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 (defconst ccl-machine-code-table
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 '[set-cs set-cl set-r set-a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 jump jump-cond write-jump write-read-jump write-c-jump
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 write-c-read-jump write-s-jump write-s-read-jump write-a-read-jump
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 branch
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 read1 read2 read-branch write1 write2 write-c write-s write-a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 end
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 set-self-cs set-self-cl set-self-r set-expr-cl set-expr-r
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 jump-cond-c jump-cond-r read-jump-cond-c read-jump-cond-r
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 ])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 (let (code (i 0) (len (length ccl-machine-code-table)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 (setq code (aref ccl-machine-code-table i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 (put code 'ccl-code i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 (put code 'ccl-dump-function (intern (format "ccl-dump-%s" code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 (defconst ccl-register-table '[r0 r1 r2 r3 r4 r5 r6 r7])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 (let (reg (i 0) (len (length ccl-register-table)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58 (setq reg (aref ccl-register-table i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 (put reg 'ccl-register-number i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 (defconst ccl-arith-table
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63 '[+ - * / % & | ^ << >> <8 >8 // nil nil nil < > == <= >= !=])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 (let (arith (i 0) (len (length ccl-arith-table)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 (setq arith (aref ccl-arith-table i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 (if arith (put arith 'ccl-arith-code i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 (defconst ccl-self-arith-table
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 '[+= -= *= /= %= &= |= ^= <<= >>= <8= >8= //=])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74 (let (arith (i 0) (len (length ccl-self-arith-table)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 (setq arith (aref ccl-self-arith-table i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 (put arith 'ccl-self-arith-code i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 ;; this holds the compiled CCL program as it is being compiled.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 (defvar ccl-program-vector nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83 ;; this holds the index into ccl-program-vector where the next
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 ;; instruction is to be stored.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 (defvar ccl-current-ic 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87 ;; add a constant to the compiled CCL program, either at IC (if specified)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 ;; or at the current instruction counter (and bumping that value)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 (defun ccl-embed-const (const &optional ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 (if ic
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91 (aset ccl-program-vector ic const)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 (aset ccl-program-vector ccl-current-ic const)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 (setq ccl-current-ic (1+ ccl-current-ic))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 (defun ccl-embed-code (op reg const &optional ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 (let ((machine-code (logior (get op 'ccl-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 (if (symbolp reg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 (ash (get reg 'ccl-register-number) 5)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 (ash const 8))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 (if ic
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102 (aset ccl-program-vector ic machine-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 (aset ccl-program-vector ccl-current-ic machine-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 (setq ccl-current-ic (1+ ccl-current-ic)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 ;; advance the instruction counter by INC without doing anything else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 (defun ccl-embed-nop (&optional inc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 (setq ccl-current-ic (+ ccl-current-ic (or inc 1))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 (defun ccl-program-p (obj)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 "T if OBJECT is a valid CCL compiled code."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 (and (vectorp obj)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 (let ((i 0) (len (length obj)) (flag t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 (if (> len 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 (while (and flag (< i len))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 (setq flag (integerp (aref obj i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120 flag)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 (defvar ccl-loop-head nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 (defvar ccl-breaks nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 (defun ccl-compile (ccl-program)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 "Compile a CCL source program and return the compiled equivalent.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 The return value will be a vector of integers."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 (if (or (null (consp ccl-program))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 (null (listp (car ccl-program))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131 (error "CCL: Invalid source program: %s" ccl-program))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 (if (null (vectorp ccl-program-vector))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 (setq ccl-program-vector (make-vector 8192 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 ;; perhaps not necessary but guarantees some sort of determinism
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135 (fillarray ccl-program-vector 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 (setq ccl-loop-head nil ccl-breaks nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 (setq ccl-current-ic 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 ;; leave space for offset to EOL program
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139 (ccl-embed-nop)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
140 (ccl-compile-1 (car ccl-program))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 ;; store offset to EOL program in first word of compiled prog
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 (ccl-embed-const ccl-current-ic 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 (if (car (cdr ccl-program))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 (ccl-compile-1 (car (cdr ccl-program))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 (ccl-embed-code 'end 0 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146 (let ((vec (make-vector ccl-current-ic 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147 (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 (while (< i ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149 (aset vec i (aref ccl-program-vector i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151 vec))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 (defun ccl-check-constant (arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 (if (>= arg 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155 arg
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156 (error "CCL: Negative constant %s not allowed: %s" arg cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158 (defun ccl-check-register (arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 (if (get arg 'ccl-register-number)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 arg
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 (error "CCL: Invalid register %s: %s" arg cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 (defun ccl-check-reg-const (arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 (if (integer-or-char-p arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 (ccl-check-constant arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 (ccl-check-register arg cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 (defun ccl-check-compile-function (arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 (or (get arg 'ccl-compile-function)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 (error "CCL: Invalid command: %s" cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 ;; compile a block of CCL code (see CCL_BLOCK above).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 (defun ccl-compile-1 (cmd-list)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 (let (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175 ;; a CCL_BLOCK is either STATEMENT or (STATEMENT [STATEMENT ...])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 ;; convert the former into the latter.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 (if (or (not (listp cmd-list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 (and cmd-list (symbolp (car cmd-list))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 (setq cmd-list (list cmd-list)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 (while cmd-list
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181 (setq cmd (car cmd-list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 ;; an int-or-char is equivalent to (r0 = int-or-char)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 ;; a string is equivalent to (write string)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 ;; convert the above two into their equivalent forms.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 ;; everything else is a list.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 (cond ((integer-or-char-p cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 (ccl-compile-set (list 'r0 '= cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 ((stringp cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 (ccl-compile-write-string (list 'write cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 ((listp cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 (if (eq (nth 1 cmd) '=)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 (ccl-compile-set cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 (if (and (symbolp (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 (get (nth 1 cmd) 'ccl-self-arith-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 (ccl-compile-self-set cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 (funcall (ccl-check-compile-function (car cmd) cmd) cmd))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 (error "CCL: Invalid command: %s" cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 (setq cmd-list (cdr cmd-list)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 (defun ccl-compile-set (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 (let ((rrr (ccl-check-register (car cmd) cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 (right (nth 2 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 (cond ((listp right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 ;; cmd == (RRR = (XXX OP YYY))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 (ccl-compile-expression rrr right))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 ((integer-or-char-p right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 (ccl-check-constant right cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 (if (< right 524288) ; (< right 2^19)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 (ccl-embed-code 'set-cs rrr right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 (ccl-embed-code 'set-cl rrr 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 (ccl-embed-const right)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 (ccl-check-register right cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 (let ((ary (nth 3 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 (if (vectorp ary)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 (let ((i 0) (len (length ary)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 (ccl-embed-code 'set-a rrr (get right 'ccl-register-number))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 (ccl-embed-const len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 (ccl-check-constant (aref ary i) cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 (ccl-embed-const (aref ary i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 (ccl-embed-code 'set-r rrr right)))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 (defun ccl-compile-self-set (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 (let ((rrr (ccl-check-register (car cmd) cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 (right (nth 2 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 (if (listp right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230 ;; cmd == (RRR SELF-OP= (XXX OP YYY))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 (ccl-compile-expression 'r7 right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 (setq right 'r7)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 (ccl-compile-expression
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 rrr
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 (list rrr (intern (substring (symbol-name (nth 1 cmd)) 0 -1)) right))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 (defun ccl-compile-expression (rrr expr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 (let ((left (car expr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 (right (nth 2 expr)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 (if (listp left)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 (ccl-compile-expression 'r7 left)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 (setq left 'r7)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 (if (eq rrr left)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 (if (integer-or-char-p right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 (if (< right 32768)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 (ccl-embed-code 'set-self-cs rrr right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 (ccl-embed-code 'set-self-cl rrr 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 (ccl-embed-const right))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 (ccl-check-register right expr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 (ccl-embed-code 'set-self-r rrr (get right 'ccl-register-number)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 (if (integer-or-char-p right)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 (ccl-embed-code 'set-expr-cl rrr (get left 'ccl-register-number))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 (ccl-embed-const right))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 (ccl-check-register right expr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 (ccl-embed-code 'set-expr-r rrr (get left 'ccl-register-number))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 (ccl-embed-const (get right 'ccl-register-number))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 (ccl-embed-const (get (nth 1 expr) 'ccl-arith-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 (defun ccl-compile-write-string (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 (if (/= (length cmd) 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 (let* ((str (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 (len (length str))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267 (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 (ccl-embed-code 'write-s 0 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 (ccl-embed-const len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271 (ccl-embed-const (aref str i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 (setq i (1+ i)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274 (defun ccl-compile-if (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 (if (and (/= (length cmd) 3) (/= (length cmd) 4))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277 (let ((condition (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 (true-cmds (nth 2 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 (false-cmds (nth 3 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 ic0 ic1 ic2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 (if (listp condition)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282 ;; cmd == (if (XXX OP YYY) ...)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 (if (listp (car condition))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 ;; cmd == (if ((xxx op yyy) OP YYY) ...)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 (ccl-compile-expression 'r7 (car condition))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 (setq condition (cons 'r7 (cdr condition)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 (setq cmd (cons (car cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 (cons condition
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 (cdr (cdr cmd))))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 (setq ic0 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 (ccl-embed-nop (if (listp condition) 3 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 (ccl-compile-1 true-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 (if (null false-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 (setq ic1 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 (setq ic2 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 (ccl-embed-const 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 (setq ic1 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 (ccl-compile-1 false-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 (ccl-embed-code 'jump 0 ccl-current-ic ic2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 (if (symbolp condition)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302 (ccl-embed-code 'jump-cond condition ic1 ic0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 (let ((arg (nth 2 condition)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 (if (integer-or-char-p arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 (ccl-embed-code 'jump-cond-c (car condition) ic1 ic0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 (ccl-embed-const arg (1+ ic0)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 (ccl-check-register arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 (ccl-embed-code 'jump-cond-r (car condition) ic1 ic0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 (ccl-embed-const (get arg 'ccl-register-number) (1+ ic0)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 (ccl-embed-const (get (nth 1 condition) 'ccl-arith-code) (+ ic0 2))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 (defun ccl-compile-branch (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 (if (< (length cmd) 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
316 (if (listp (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 (ccl-compile-expression 'r7 (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 (setq cmd (cons (car cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 (cons 'r7 (cdr (cdr cmd)))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321 (ccl-compile-branch-1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
322
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
323 (defun ccl-compile-read-branch (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
324 (ccl-compile-branch-1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
326 (defun ccl-compile-branch-1 (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
327 (if (< (length cmd) 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
328 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
329 (let ((rrr (ccl-check-register (car (cdr cmd)) cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
330 (branches (cdr (cdr cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
331 i ic0 ic1 ic2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
332 branch-tails)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333 (ccl-embed-code (car cmd) rrr (- (length cmd) 2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334 (setq ic0 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
335 (ccl-embed-nop (1- (length cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
336 (setq i 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
337 (while branches
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
338 (ccl-embed-const ccl-current-ic (+ ic0 i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
339 (ccl-compile-1 (car branches))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
340 (setq branch-tails (cons ccl-current-ic branch-tails))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
341 (ccl-embed-nop)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
342 (setq i (1+ i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
343 (setq branches (cdr branches)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
344 ;; We don't need `jump' from the last branch.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
345 (setq branch-tails (cdr branch-tails))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
346 (setq ccl-current-ic (1- ccl-current-ic))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347 (while branch-tails
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
348 (ccl-embed-code 'jump 0 ccl-current-ic (car branch-tails))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
349 (setq branch-tails (cdr branch-tails)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350 ;; This is the case `rrr' is out of range.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351 (ccl-embed-const ccl-current-ic (+ ic0 i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352 ))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
354 (defun ccl-compile-loop (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
355 (if (< (length cmd) 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357 (let ((ccl-loop-head ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 (ccl-breaks nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359 (setq cmd (cdr cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 (while cmd
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 (ccl-compile-1 (car cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
362 (setq cmd (cdr cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 (while ccl-breaks
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 (ccl-embed-code 'jump 0 ccl-current-ic (car ccl-breaks))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 (setq ccl-breaks (cdr ccl-breaks)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367 (defun ccl-compile-break (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368 (if (/= (length cmd) 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370 (if (null ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371 (error "CCL: No outer loop: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372 (setq ccl-breaks (cons ccl-current-ic ccl-breaks))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373 (ccl-embed-nop))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375 (defun ccl-compile-repeat (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376 (if (/= (length cmd) 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 (if (null ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 (error "CCL: No outer loop: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380 (ccl-embed-code 'jump 0 ccl-loop-head))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382 (defun ccl-compile-write-repeat (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
383 (if (/= (length cmd) 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
384 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
385 (if (null ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 (error "CCL: No outer loop: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387 (let ((arg (nth 1 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
388 (cond ((integer-or-char-p arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
389 (ccl-embed-code 'write-c-jump 0 ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390 (ccl-embed-const arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391 ((stringp arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392 (ccl-embed-code 'write-s-jump 0 ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393 (let ((i 0) (len (length arg)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394 (ccl-embed-const (length arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 (ccl-embed-const (aref arg i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 (setq i (1+ i)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 (ccl-check-register arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400 (ccl-embed-code 'write-jump arg ccl-loop-head)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402 (defun ccl-compile-write-read-repeat (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403 (if (or (< (length cmd) 2) (> (length cmd) 3))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
405 (if (null ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
406 (error "CCL: No outer loop: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
407 (let ((rrr (ccl-check-register (nth 1 cmd) cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
408 (arg (nth 2 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
409 (cond ((null arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
410 (ccl-embed-code 'write-read-jump rrr ccl-loop-head))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
411 ((integer-or-char-p arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
412 (ccl-embed-code 'write-c-read-jump rrr ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413 (ccl-embed-const arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 ((or (stringp arg) (vectorp arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415 (ccl-embed-code (if (stringp arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416 'write-s-read-jump
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417 'write-a-read-jump)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418 rrr ccl-loop-head)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419 (let ((i 0) (len (length arg)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420 (ccl-embed-const (length arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422 (ccl-embed-const (aref arg i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423 (setq i (1+ i)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424 (t (error "CCL: Invalide argument %s: %s" arg cmd)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426 (defun ccl-compile-read (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427 (let ((rrr (ccl-check-register (nth 1 cmd) cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428 (cond ((= (length cmd) 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429 (ccl-embed-code 'read1 rrr 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 ((= (length cmd) 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431 (ccl-embed-code 'read2 rrr (get (nth 2 cmd) 'ccl-register-number)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 (t (error "CCL: Invalid number of arguments: %s" cmd)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434 (defun ccl-compile-read-if (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435 (if (and (/= (length cmd) 3) (/= (length cmd) 4))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437 (let* ((expr (nth 1 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438 (rrr (ccl-check-register (car expr) cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439 (true-cmds (nth 2 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440 (false-cmds (nth 3 cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441 ic0 ic1 ic2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442 (setq ic0 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 (ccl-embed-nop 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
444 (ccl-compile-1 true-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
445 (if (null false-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446 (setq ic1 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 (setq ic2 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448 (ccl-embed-const 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
449 (setq ic1 ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
450 (ccl-compile-1 false-cmds)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
451 (ccl-embed-code 'jump 0 ccl-current-ic ic2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
452 (let ((arg (nth 2 expr)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
453 (ccl-embed-code (if (integer-or-char-p arg) 'read-jump-cond-c
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454 'read-jump-cond-r)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455 rrr ic1 ic0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 (ccl-embed-const (if (integer-or-char-p arg) arg
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457 (get arg 'ccl-register-number))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458 (1+ ic0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459 (ccl-embed-const (get (nth 1 expr) 'ccl-arith-code) (+ ic0 2)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 (defun ccl-compile-write (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462 (if (and (/= (length cmd) 2) (/= (length cmd) 3))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464 (let ((rrr (nth 1 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 (cond ((integer-or-char-p rrr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 (ccl-embed-code 'write-c 0 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467 (ccl-embed-const rrr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468 ((stringp rrr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 (ccl-compile-write-string (list 'write rrr)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471 (ccl-check-register rrr cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 (let ((arg (nth 2 cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473 (if arg
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474 (cond ((symbolp arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 (ccl-check-register arg cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476 (ccl-embed-code 'write2 rrr
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477 (get arg 'ccl-register-number)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478 ((vectorp arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 (let ((i 0) (len (length arg)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480 (ccl-embed-code 'write-a rrr 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 (ccl-embed-const len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
483 (ccl-embed-const (aref arg i))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 (setq i (1+ i)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485 (t (error "CCL: Invalid argument %s: %s" arg cmd)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486 (ccl-embed-code 'write1 rrr 0)))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
487
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
488 (defun ccl-compile-end (cmd)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
489 (if (/= (length cmd) 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
490 (error "CCL: Invalid number of arguments: %s" cmd))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491 (ccl-embed-code 'end 0 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
492
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
493 ;;; CCL dump staffs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494 (defvar ccl-program-vector-dump nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497 (defun ccl-dump (ccl-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498 "Disassemble compiled CCL-CODE."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500 (set-buffer (get-buffer-create "*CCL-Dump*"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 (erase-buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502 (setq ccl-program-vector-dump ccl-code)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503 (let ((len (length ccl-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 (insert "Main:\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 (setq ccl-current-ic 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 (if (> (aref ccl-code 0) 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
508 (while (< ccl-current-ic (aref ccl-code 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
509 (ccl-dump-1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
510 (insert "At EOF:\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511 (while (< ccl-current-ic len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
512 (ccl-dump-1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513 ))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514 (display-buffer (get-buffer "*CCL-Dump*")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 (defun ccl-get-next-code ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517 (prog1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518 (aref ccl-program-vector-dump ccl-current-ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 (setq ccl-current-ic (1+ ccl-current-ic))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521 (defun ccl-dump-1 ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 (let* ((opcode (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 (code (logand opcode 31))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524 (cmd (aref ccl-machine-code-table code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525 (rrr (logand (ash opcode -5) 7))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526 (cc (ash opcode -8)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 (insert (format "%4d: " (1- ccl-current-ic)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528 (funcall (get cmd 'ccl-dump-function) rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530 (defun ccl-dump-set-cs (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 (insert (format "r%d = %s\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533 (defun ccl-dump-set-cl (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534 (setq cc (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 (insert (format "r%d = %s\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 (defun ccl-dump-set-r (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 (insert (format "r%d = r%d\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 (defun ccl-dump-set-a (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541 (let ((range (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542 (insert (format "r%d = array[r%d] of length %d\n\t"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543 rrr cc range))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544 (let ((i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545 (while (< i range)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546 (insert (format "%d " (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547 (setq i (1+ i))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548 (insert "\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550 (defun ccl-dump-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551 (insert (format "jump to %d\n" cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 (defun ccl-dump-jump-cond (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554 (insert (format "if !(r%d), jump to %d\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556 (defun ccl-dump-write-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557 (insert (format "write r%d, jump to %d\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559 (defun ccl-dump-write-read-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
560 (insert (format "write r%d, read r%d, jump to %d\n" rrr rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562 (defun ccl-dump-write-c-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563 (let ((const (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 (insert (format "write %s, jump to %d\n" const cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
565
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 (defun ccl-dump-write-c-read-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567 (let ((const (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568 (insert (format "write %s, read r%d, jump to %d\n" const rrr cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570 (defun ccl-dump-write-s-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571 (let ((len (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 (insert "write \"")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574 (insert (format "%c" (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
576 (insert (format "\", jump to %d\n" cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578 (defun ccl-dump-write-s-read-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579 (let ((len (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580 (insert "write \"")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 (insert (format "%c" (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 (insert (format "\", read r%d, jump to %d\n" rrr cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
586 (defun ccl-dump-write-a-read-jump (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
587 (let ((len (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
588 (insert (format "write array[r%d] of length %d, read r%d, jump to %d\n\t"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
589 rrr len rrr cc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
590 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
591 (insert (format "%d " (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
592 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
593 (insert "\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
594
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
595 (defun ccl-dump-branch (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
596 (let ((i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
597 (insert (format "jump to array[r%d] of length %d)\n\t" rrr cc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
598 (while (<= i cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
599 (insert (format "%d " (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
600 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
601 (insert "\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
602
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
603 (defun ccl-dump-read1 (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
604 (insert (format "read r%d\n" rrr)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
605
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
606 (defun ccl-dump-read2 (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
607 (insert (format "read r%d and r%d\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
608
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
609 (defun ccl-dump-read-branch (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
610 (insert (format "read r%d, " rrr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
611 (ccl-dump-branch rrr cc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
612
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
613 (defun ccl-dump-write1 (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
614 (insert (format "write r%d\n" rrr)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
615
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
616 (defun ccl-dump-write2 (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
617 (insert (format "write r%d and r%d\n" rrr cc)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
618
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
619 (defun ccl-dump-write-c (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
620 (insert (format "write %s\n" (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
621
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
622 (defun ccl-dump-write-s (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
623 (let ((len (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
624 (insert "write \"")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
625 (while (< i len)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
626 (insert (format "%c" (ccl-get-next-code)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
627 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
628 (insert "\"\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
629
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
630 (defun ccl-dump-write-a (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
631 (let ((len (ccl-get-next-code)) (i 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
632 (insert (format "write array[r%d] of length %d\n\t" rrr len))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
633 (while (< i 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
634 (insert "%d " (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
635 (setq i (1+ i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
636 (insert "\n")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
637
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
638 (defun ccl-dump-end (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
639 (insert "end\n"))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
640
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
641 (defun ccl-dump-set-self-cs (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
642 (let ((arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
643 (insert (format "r%d %s= %s\n" rrr arith cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
644
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
645 (defun ccl-dump-set-self-cl (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
646 (setq cc (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
647 (let ((arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
648 (insert (format "r%d %s= %s\n" rrr arith cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
649
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
650 (defun ccl-dump-set-self-r (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
651 (let ((arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
652 (insert (format "r%d %s= r%d\n" rrr arith cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
653
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
654 (defun ccl-dump-set-expr-cl (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
655 (let ((const (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
656 (arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
657 (insert (format "r%d = r%d %s %s\n" rrr cc arith const))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
658
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
659 (defun ccl-dump-set-expr-r (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
660 (let ((reg (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
661 (arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
662 (insert (format "r%d = r%d %s r%d\n" rrr cc arith reg))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
663
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
664 (defun ccl-dump-jump-cond-c (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
665 (let ((const (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
666 (arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
667 (insert (format "if !(r%d %s %s), jump to %d\n" rrr arith const cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
668
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
669 (defun ccl-dump-jump-cond-r (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
670 (let ((reg (ccl-get-next-code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
671 (arith (aref ccl-arith-table (ccl-get-next-code))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
672 (insert (format "if !(r%d %s r%d), jump to %d\n" rrr arith reg cc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
673
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
674 (defun ccl-dump-read-jump-cond-c (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
675 (insert (format "read r%d, " rrr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
676 (ccl-dump-jump-cond-c rrr cc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
677
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
678 (defun ccl-dump-read-jump-cond-r (rrr cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
679 (insert (format "read r%d, " rrr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
680 (ccl-dump-jump-cond-r rrr cc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
681
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
682 ;; CCL emulation staffs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
683
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
684 ;; Not yet implemented.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
685
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
686 ;; For byte-compiler
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
687
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
688 ;;;###autoload
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
689 (defmacro define-ccl-program (name ccl-program &optional doc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
690 "Does (defconst NAME (ccl-compile (eval CCL-PROGRAM)) DOC).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
691 Byte-compiler expand this macro while compiling."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
692 (` (defconst (, name) (, (ccl-compile (eval ccl-program))) (, doc))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
693
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
694 (put 'define-ccl-program 'byte-hunk-handler 'macroexpand)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
695
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
696 (provide 'ccl)