Mercurial > emacs
annotate lisp/international/ccl.el @ 32338:5bd182bded06
Mention that `u' might or might not restore point.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Mon, 09 Oct 2000 16:26:43 +0000 |
parents | dcfcae58d8d6 |
children | 496f65930f98 |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17297
diff
changeset
|
1 ;;; ccl.el --- CCL (Code Conversion Language) compiler |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
17315
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 5 |
6 ;; Keywords: CCL, mule, multilingual, character set, coding-system | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
17052 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; CCL (Code Conversion Language) is a simple programming language to | |
28 ;; be used for various kind of code conversion. CCL program is | |
29 ;; compiled to CCL code (vector of integers) and executed by CCL | |
30 ;; interpreter of Emacs. | |
31 ;; | |
32 ;; CCL is used for code conversion at process I/O and file I/O for | |
33 ;; non-standard coding-system. In addition, it is used for | |
34 ;; calculating a code point of X's font from a character code. | |
35 ;; However, since CCL is designed as a powerful programming language, | |
36 ;; it can be used for more generic calculation. For instance, | |
37 ;; combination of three or more arithmetic operations can be | |
38 ;; calculated faster than Emacs Lisp. | |
39 ;; | |
30845
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
40 ;; Syntax and semantics of CCL program is described in the |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
41 ;; documentation of `define-ccl-program'. |
17052 | 42 |
43 ;;; Code: | |
44 | |
21645 | 45 (defgroup ccl nil |
46 "CCL (Code Conversion Language) compiler." | |
47 :prefix "ccl-" | |
48 :group 'i18n) | |
49 | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
50 (defconst ccl-command-table |
17052 | 51 [if branch loop break repeat write-repeat write-read-repeat |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
52 read read-if read-branch write call end |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
53 read-multibyte-character write-multibyte-character |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
54 translate-character |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
55 iterate-multiple-map map-multiple map-single] |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
56 "Vector of CCL commands (symbols).") |
17052 | 57 |
58 ;; Put a property to each symbol of CCL commands for the compiler. | |
59 (let (op (i 0) (len (length ccl-command-table))) | |
60 (while (< i len) | |
61 (setq op (aref ccl-command-table i)) | |
62 (put op 'ccl-compile-function (intern (format "ccl-compile-%s" op))) | |
63 (setq i (1+ i)))) | |
64 | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
65 (defconst ccl-code-table |
17052 | 66 [set-register |
67 set-short-const | |
68 set-const | |
69 set-array | |
70 jump | |
71 jump-cond | |
72 write-register-jump | |
73 write-register-read-jump | |
74 write-const-jump | |
75 write-const-read-jump | |
76 write-string-jump | |
77 write-array-read-jump | |
78 read-jump | |
79 branch | |
80 read-register | |
81 write-expr-const | |
82 read-branch | |
83 write-register | |
84 write-expr-register | |
85 call | |
86 write-const-string | |
87 write-array | |
88 end | |
89 set-assign-expr-const | |
90 set-assign-expr-register | |
91 set-expr-const | |
92 set-expr-register | |
93 jump-cond-expr-const | |
94 jump-cond-expr-register | |
95 read-jump-cond-expr-const | |
96 read-jump-cond-expr-register | |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
97 ex-cmd |
17052 | 98 ] |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
99 "Vector of CCL compiled codes (symbols).") |
17052 | 100 |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
101 (defconst ccl-extended-code-table |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
102 [read-multibyte-character |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
103 write-multibyte-character |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
104 translate-character |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
105 translate-character-const-tbl |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
106 nil nil nil nil nil nil nil nil nil nil nil nil ; 0x04-0x0f |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
107 iterate-multiple-map |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
108 map-multiple |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
109 map-single |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
110 ] |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
111 "Vector of CCL extended compiled codes (symbols).") |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
112 |
17052 | 113 ;; Put a property to each symbol of CCL codes for the disassembler. |
114 (let (code (i 0) (len (length ccl-code-table))) | |
115 (while (< i len) | |
116 (setq code (aref ccl-code-table i)) | |
117 (put code 'ccl-code i) | |
118 (put code 'ccl-dump-function (intern (format "ccl-dump-%s" code))) | |
119 (setq i (1+ i)))) | |
120 | |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
121 (let (code (i 0) (len (length ccl-extended-code-table))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
122 (while (< i len) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
123 (setq code (aref ccl-extended-code-table i)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
124 (if code |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
125 (progn |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
126 (put code 'ccl-ex-code i) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
127 (put code 'ccl-dump-function (intern (format "ccl-dump-%s" code))))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
128 (setq i (1+ i)))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
129 |
17052 | 130 (defconst ccl-jump-code-list |
131 '(jump jump-cond write-register-jump write-register-read-jump | |
132 write-const-jump write-const-read-jump write-string-jump | |
133 write-array-read-jump read-jump)) | |
134 | |
135 ;; Put a property `jump-flag' to each CCL code which execute jump in | |
136 ;; some way. | |
137 (let ((l ccl-jump-code-list)) | |
138 (while l | |
139 (put (car l) 'jump-flag t) | |
140 (setq l (cdr l)))) | |
141 | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
142 (defconst ccl-register-table |
17052 | 143 [r0 r1 r2 r3 r4 r5 r6 r7] |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
144 "Vector of CCL registers (symbols).") |
17052 | 145 |
146 ;; Put a property to indicate register number to each symbol of CCL. | |
147 ;; registers. | |
148 (let (reg (i 0) (len (length ccl-register-table))) | |
149 (while (< i len) | |
150 (setq reg (aref ccl-register-table i)) | |
151 (put reg 'ccl-register-number i) | |
152 (setq i (1+ i)))) | |
153 | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
154 (defconst ccl-arith-table |
17052 | 155 [+ - * / % & | ^ << >> <8 >8 // nil nil nil |
156 < > == <= >= != de-sjis en-sjis] | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
157 "Vector of CCL arithmetic/logical operators (symbols).") |
17052 | 158 |
159 ;; Put a property to each symbol of CCL operators for the compiler. | |
160 (let (arith (i 0) (len (length ccl-arith-table))) | |
161 (while (< i len) | |
162 (setq arith (aref ccl-arith-table i)) | |
163 (if arith (put arith 'ccl-arith-code i)) | |
164 (setq i (1+ i)))) | |
165 | |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
166 (defconst ccl-assign-arith-table |
17052 | 167 [+= -= *= /= %= &= |= ^= <<= >>= <8= >8= //=] |
21977
fe7ef7cd642a
Cancel the previous change for
Kenichi Handa <handa@m17n.org>
parents:
21669
diff
changeset
|
168 "Vector of CCL assignment operators (symbols).") |
17052 | 169 |
170 ;; Put a property to each symbol of CCL assignment operators for the compiler. | |
171 (let (arith (i 0) (len (length ccl-assign-arith-table))) | |
172 (while (< i len) | |
173 (setq arith (aref ccl-assign-arith-table i)) | |
174 (put arith 'ccl-self-arith-code i) | |
175 (setq i (1+ i)))) | |
176 | |
177 (defvar ccl-program-vector nil | |
178 "Working vector of CCL codes produced by CCL compiler.") | |
179 (defvar ccl-current-ic 0 | |
180 "The current index for `ccl-program-vector'.") | |
181 | |
182 ;; Embed integer DATA in `ccl-program-vector' at `ccl-current-ic' and | |
183 ;; increment it. If IC is specified, embed DATA at IC. | |
184 (defun ccl-embed-data (data &optional ic) | |
185 (if ic | |
186 (aset ccl-program-vector ic data) | |
30705
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
187 (let ((len (length ccl-program-vector))) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
188 (if (>= ccl-current-ic len) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
189 (let ((new (make-vector (* len 2) nil))) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
190 (while (> len 0) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
191 (setq len (1- len)) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
192 (aset new len (aref ccl-program-vector len))) |
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
193 (setq ccl-program-vector new)))) |
17052 | 194 (aset ccl-program-vector ccl-current-ic data) |
195 (setq ccl-current-ic (1+ ccl-current-ic)))) | |
196 | |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
197 ;; Embed pair of SYMBOL and PROP where (get SYMBOL PROP) should give |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
198 ;; proper index number for SYMBOL. PROP should be |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
199 ;; `translation-table-id', `code-conversion-map-id', or |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
200 ;; `ccl-program-idx'. |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
201 (defun ccl-embed-symbol (symbol prop) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
202 (ccl-embed-data (cons symbol prop))) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
203 |
17052 | 204 ;; Embed string STR of length LEN in `ccl-program-vector' at |
205 ;; `ccl-current-ic'. | |
206 (defun ccl-embed-string (len str) | |
207 (let ((i 0)) | |
208 (while (< i len) | |
209 (ccl-embed-data (logior (ash (aref str i) 16) | |
210 (if (< (1+ i) len) | |
211 (ash (aref str (1+ i)) 8) | |
212 0) | |
213 (if (< (+ i 2) len) | |
214 (aref str (+ i 2)) | |
215 0))) | |
216 (setq i (+ i 3))))) | |
217 | |
218 ;; Embed a relative jump address to `ccl-current-ic' in | |
219 ;; `ccl-program-vector' at IC without altering the other bit field. | |
220 (defun ccl-embed-current-address (ic) | |
221 (let ((relative (- ccl-current-ic (1+ ic)))) | |
222 (aset ccl-program-vector ic | |
223 (logior (aref ccl-program-vector ic) (ash relative 8))))) | |
224 | |
225 ;; Embed CCL code for the operation OP and arguments REG and DATA in | |
226 ;; `ccl-program-vector' at `ccl-current-ic' in the following format. | |
227 ;; |----------------- integer (28-bit) ------------------| | |
228 ;; |------------ 20-bit ------------|- 3-bit --|- 5-bit -| | |
229 ;; |------------- DATA -------------|-- REG ---|-- OP ---| | |
230 ;; If REG2 is specified, embed a code in the following format. | |
231 ;; |------- 17-bit ------|- 3-bit --|- 3-bit --|- 5-bit -| | |
232 ;; |-------- DATA -------|-- REG2 --|-- REG ---|-- OP ---| | |
233 | |
234 ;; If REG is a CCL register symbol (e.g. r0, r1...), the register | |
235 ;; number is embedded. If OP is one of unconditional jumps, DATA is | |
17297 | 236 ;; changed to an relative jump address. |
17052 | 237 |
238 (defun ccl-embed-code (op reg data &optional reg2) | |
239 (if (and (> data 0) (get op 'jump-flag)) | |
240 ;; DATA is an absolute jump address. Make it relative to the | |
241 ;; next of jump code. | |
242 (setq data (- data (1+ ccl-current-ic)))) | |
243 (let ((code (logior (get op 'ccl-code) | |
244 (ash | |
245 (if (symbolp reg) (get reg 'ccl-register-number) reg) 5) | |
246 (if reg2 | |
247 (logior (ash (get reg2 'ccl-register-number) 8) | |
248 (ash data 11)) | |
249 (ash data 8))))) | |
30705
b37405134317
(ccl-embed-data): Make ccl-program-vector
Kenichi Handa <handa@m17n.org>
parents:
29429
diff
changeset
|
250 (ccl-embed-data code))) |
17052 | 251 |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
252 ;; extended ccl command format |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
253 ;; |- 14-bit -|- 3-bit --|- 3-bit --|- 3-bit --|- 5-bit -| |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
254 ;; |- EX-OP --|-- REG3 --|-- REG2 --|-- REG ---|-- OP ---| |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
255 (defun ccl-embed-extended-command (ex-op reg reg2 reg3) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
256 (let ((data (logior (ash (get ex-op 'ccl-ex-code) 3) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
257 (if (symbolp reg3) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
258 (get reg3 'ccl-register-number) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
259 0)))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
260 (ccl-embed-code 'ex-cmd reg data reg2))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
261 |
17052 | 262 ;; Just advance `ccl-current-ic' by INC. |
263 (defun ccl-increment-ic (inc) | |
264 (setq ccl-current-ic (+ ccl-current-ic inc))) | |
265 | |
266 ;; If non-nil, index of the start of the current loop. | |
267 (defvar ccl-loop-head nil) | |
268 ;; If non-nil, list of absolute addresses of the breaking points of | |
269 ;; the current loop. | |
270 (defvar ccl-breaks nil) | |
271 | |
272 ;;;###autoload | |
273 (defun ccl-compile (ccl-program) | |
23196 | 274 "Return a compiled code of CCL-PROGRAM as a vector of integer." |
17052 | 275 (if (or (null (consp ccl-program)) |
276 (null (integerp (car ccl-program))) | |
277 (null (listp (car (cdr ccl-program))))) | |
278 (error "CCL: Invalid CCL program: %s" ccl-program)) | |
279 (if (null (vectorp ccl-program-vector)) | |
280 (setq ccl-program-vector (make-vector 8192 0))) | |
281 (setq ccl-loop-head nil ccl-breaks nil) | |
282 (setq ccl-current-ic 0) | |
283 | |
284 ;; The first element is the buffer magnification. | |
285 (ccl-embed-data (car ccl-program)) | |
286 | |
287 ;; The second element is the address of the start CCL code for | |
288 ;; processing end of input buffer (we call it eof-processor). We | |
289 ;; set it later. | |
290 (ccl-increment-ic 1) | |
291 | |
292 ;; Compile the main body of the CCL program. | |
293 (ccl-compile-1 (car (cdr ccl-program))) | |
294 | |
295 ;; Embed the address of eof-processor. | |
296 (ccl-embed-data ccl-current-ic 1) | |
297 | |
298 ;; Then compile eof-processor. | |
299 (if (nth 2 ccl-program) | |
300 (ccl-compile-1 (nth 2 ccl-program))) | |
301 | |
302 ;; At last, embed termination code. | |
303 (ccl-embed-code 'end 0 0) | |
304 | |
305 (let ((vec (make-vector ccl-current-ic 0)) | |
306 (i 0)) | |
307 (while (< i ccl-current-ic) | |
308 (aset vec i (aref ccl-program-vector i)) | |
309 (setq i (1+ i))) | |
310 vec)) | |
311 | |
312 ;; Signal syntax error. | |
313 (defun ccl-syntax-error (cmd) | |
314 (error "CCL: Syntax error: %s" cmd)) | |
315 | |
316 ;; Check if ARG is a valid CCL register. | |
317 (defun ccl-check-register (arg cmd) | |
318 (if (get arg 'ccl-register-number) | |
319 arg | |
320 (error "CCL: Invalid register %s in %s." arg cmd))) | |
321 | |
322 ;; Check if ARG is a valid CCL command. | |
323 (defun ccl-check-compile-function (arg cmd) | |
324 (or (get arg 'ccl-compile-function) | |
325 (error "CCL: Invalid command: %s" cmd))) | |
326 | |
327 ;; In the following code, most ccl-compile-XXXX functions return t if | |
328 ;; they end with unconditional jump, else return nil. | |
329 | |
330 ;; Compile CCL-BLOCK (see the syntax above). | |
331 (defun ccl-compile-1 (ccl-block) | |
332 (let (unconditional-jump | |
333 cmd) | |
334 (if (or (integerp ccl-block) | |
335 (stringp ccl-block) | |
336 (and ccl-block (symbolp (car ccl-block)))) | |
337 ;; This block consists of single statement. | |
338 (setq ccl-block (list ccl-block))) | |
339 | |
340 ;; Now CCL-BLOCK is a list of statements. Compile them one by | |
341 ;; one. | |
342 (while ccl-block | |
343 (setq cmd (car ccl-block)) | |
344 (setq unconditional-jump | |
345 (cond ((integerp cmd) | |
346 ;; SET statement for the register 0. | |
347 (ccl-compile-set (list 'r0 '= cmd))) | |
348 | |
349 ((stringp cmd) | |
350 ;; WRITE statement of string argument. | |
351 (ccl-compile-write-string cmd)) | |
352 | |
353 ((listp cmd) | |
354 ;; The other statements. | |
355 (cond ((eq (nth 1 cmd) '=) | |
356 ;; SET statement of the form `(REG = EXPRESSION)'. | |
357 (ccl-compile-set cmd)) | |
358 | |
359 ((and (symbolp (nth 1 cmd)) | |
360 (get (nth 1 cmd) 'ccl-self-arith-code)) | |
361 ;; SET statement with an assignment operation. | |
362 (ccl-compile-self-set cmd)) | |
363 | |
364 (t | |
365 (funcall (ccl-check-compile-function (car cmd) cmd) | |
366 cmd)))) | |
367 | |
368 (t | |
369 (ccl-syntax-error cmd)))) | |
370 (setq ccl-block (cdr ccl-block))) | |
371 unconditional-jump)) | |
372 | |
373 (defconst ccl-max-short-const (ash 1 19)) | |
374 (defconst ccl-min-short-const (ash -1 19)) | |
375 | |
376 ;; Compile SET statement. | |
377 (defun ccl-compile-set (cmd) | |
378 (let ((rrr (ccl-check-register (car cmd) cmd)) | |
379 (right (nth 2 cmd))) | |
380 (cond ((listp right) | |
381 ;; CMD has the form `(RRR = (XXX OP YYY))'. | |
382 (ccl-compile-expression rrr right)) | |
383 | |
384 ((integerp right) | |
385 ;; CMD has the form `(RRR = integer)'. | |
386 (if (and (<= right ccl-max-short-const) | |
387 (>= right ccl-min-short-const)) | |
388 (ccl-embed-code 'set-short-const rrr right) | |
389 (ccl-embed-code 'set-const rrr 0) | |
390 (ccl-embed-data right))) | |
391 | |
392 (t | |
393 ;; CMD has the form `(RRR = rrr [ array ])'. | |
394 (ccl-check-register right cmd) | |
395 (let ((ary (nth 3 cmd))) | |
396 (if (vectorp ary) | |
397 (let ((i 0) (len (length ary))) | |
398 (ccl-embed-code 'set-array rrr len right) | |
399 (while (< i len) | |
400 (ccl-embed-data (aref ary i)) | |
401 (setq i (1+ i)))) | |
402 (ccl-embed-code 'set-register rrr 0 right)))))) | |
403 nil) | |
404 | |
405 ;; Compile SET statement with ASSIGNMENT_OPERATOR. | |
406 (defun ccl-compile-self-set (cmd) | |
407 (let ((rrr (ccl-check-register (car cmd) cmd)) | |
408 (right (nth 2 cmd))) | |
409 (if (listp right) | |
410 ;; CMD has the form `(RRR ASSIGN_OP (XXX OP YYY))', compile | |
411 ;; the right hand part as `(r7 = (XXX OP YYY))' (note: the | |
412 ;; register 7 can be used for storing temporary value). | |
413 (progn | |
414 (ccl-compile-expression 'r7 right) | |
415 (setq right 'r7))) | |
416 ;; Now CMD has the form `(RRR ASSIGN_OP ARG)'. Compile it as | |
417 ;; `(RRR = (RRR OP ARG))'. | |
418 (ccl-compile-expression | |
419 rrr | |
420 (list rrr (intern (substring (symbol-name (nth 1 cmd)) 0 -1)) right))) | |
421 nil) | |
422 | |
423 ;; Compile SET statement of the form `(RRR = EXPR)'. | |
424 (defun ccl-compile-expression (rrr expr) | |
425 (let ((left (car expr)) | |
426 (op (get (nth 1 expr) 'ccl-arith-code)) | |
427 (right (nth 2 expr))) | |
428 (if (listp left) | |
429 (progn | |
430 ;; EXPR has the form `((EXPR2 OP2 ARG) OP RIGHT)'. Compile | |
431 ;; the first term as `(r7 = (EXPR2 OP2 ARG)).' | |
432 (ccl-compile-expression 'r7 left) | |
433 (setq left 'r7))) | |
434 | |
435 ;; Now EXPR has the form (LEFT OP RIGHT). | |
28152
1b7866e465bd
(ccl-compile-expression): Don't generate
Kenichi Handa <handa@m17n.org>
parents:
25064
diff
changeset
|
436 (if (and (eq rrr left) |
1b7866e465bd
(ccl-compile-expression): Don't generate
Kenichi Handa <handa@m17n.org>
parents:
25064
diff
changeset
|
437 (< op (length ccl-assign-arith-table))) |
17052 | 438 ;; Compile this SET statement as `(RRR OP= RIGHT)'. |
439 (if (integerp right) | |
440 (progn | |
441 (ccl-embed-code 'set-assign-expr-const rrr (ash op 3) 'r0) | |
442 (ccl-embed-data right)) | |
443 (ccl-check-register right expr) | |
444 (ccl-embed-code 'set-assign-expr-register rrr (ash op 3) right)) | |
445 | |
446 ;; Compile this SET statement as `(RRR = (LEFT OP RIGHT))'. | |
447 (if (integerp right) | |
448 (progn | |
449 (ccl-embed-code 'set-expr-const rrr (ash op 3) left) | |
450 (ccl-embed-data right)) | |
451 (ccl-check-register right expr) | |
452 (ccl-embed-code 'set-expr-register | |
453 rrr | |
454 (logior (ash op 3) (get right 'ccl-register-number)) | |
455 left))))) | |
456 | |
457 ;; Compile WRITE statement with string argument. | |
458 (defun ccl-compile-write-string (str) | |
29030
837bc0327945
(ccl-compile-write-string): Make STR unibyte.
Kenichi Handa <handa@m17n.org>
parents:
28152
diff
changeset
|
459 (setq str (string-as-unibyte str)) |
17052 | 460 (let ((len (length str))) |
461 (ccl-embed-code 'write-const-string 1 len) | |
462 (ccl-embed-string len str)) | |
463 nil) | |
464 | |
465 ;; Compile IF statement of the form `(if CONDITION TRUE-PART FALSE-PART)'. | |
466 ;; If READ-FLAG is non-nil, this statement has the form | |
467 ;; `(read-if (REG OPERATOR ARG) TRUE-PART FALSE-PART)'. | |
468 (defun ccl-compile-if (cmd &optional read-flag) | |
469 (if (and (/= (length cmd) 3) (/= (length cmd) 4)) | |
470 (error "CCL: Invalid number of arguments: %s" cmd)) | |
471 (let ((condition (nth 1 cmd)) | |
472 (true-cmds (nth 2 cmd)) | |
473 (false-cmds (nth 3 cmd)) | |
474 jump-cond-address | |
475 false-ic) | |
476 (if (and (listp condition) | |
477 (listp (car condition))) | |
478 ;; If CONDITION is a nested expression, the inner expression | |
479 ;; should be compiled at first as SET statement, i.e.: | |
480 ;; `(if ((X OP2 Y) OP Z) ...)' is compiled into two statements: | |
481 ;; `(r7 = (X OP2 Y)) (if (r7 OP Z) ...)'. | |
482 (progn | |
483 (ccl-compile-expression 'r7 (car condition)) | |
484 (setq condition (cons 'r7 (cdr condition))) | |
485 (setq cmd (cons (car cmd) | |
486 (cons condition (cdr (cdr cmd))))))) | |
487 | |
488 (setq jump-cond-address ccl-current-ic) | |
489 ;; Compile CONDITION. | |
490 (if (symbolp condition) | |
491 ;; CONDITION is a register. | |
492 (progn | |
493 (ccl-check-register condition cmd) | |
494 (ccl-embed-code 'jump-cond condition 0)) | |
495 ;; CONDITION is a simple expression of the form (RRR OP ARG). | |
496 (let ((rrr (car condition)) | |
497 (op (get (nth 1 condition) 'ccl-arith-code)) | |
498 (arg (nth 2 condition))) | |
499 (ccl-check-register rrr cmd) | |
500 (if (integerp arg) | |
501 (progn | |
502 (ccl-embed-code (if read-flag 'read-jump-cond-expr-const | |
503 'jump-cond-expr-const) | |
504 rrr 0) | |
505 (ccl-embed-data op) | |
506 (ccl-embed-data arg)) | |
507 (ccl-check-register arg cmd) | |
508 (ccl-embed-code (if read-flag 'read-jump-cond-expr-register | |
509 'jump-cond-expr-register) | |
510 rrr 0) | |
511 (ccl-embed-data op) | |
512 (ccl-embed-data (get arg 'ccl-register-number))))) | |
513 | |
514 ;; Compile TRUE-PART. | |
515 (let ((unconditional-jump (ccl-compile-1 true-cmds))) | |
516 (if (null false-cmds) | |
517 ;; This is the place to jump to if condition is false. | |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
518 (progn |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
519 (ccl-embed-current-address jump-cond-address) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
520 (setq unconditional-jump nil)) |
17052 | 521 (let (end-true-part-address) |
522 (if (not unconditional-jump) | |
523 (progn | |
524 ;; If TRUE-PART does not end with unconditional jump, we | |
525 ;; have to jump to the end of FALSE-PART from here. | |
526 (setq end-true-part-address ccl-current-ic) | |
527 (ccl-embed-code 'jump 0 0))) | |
528 ;; This is the place to jump to if CONDITION is false. | |
529 (ccl-embed-current-address jump-cond-address) | |
530 ;; Compile FALSE-PART. | |
531 (setq unconditional-jump | |
532 (and (ccl-compile-1 false-cmds) unconditional-jump)) | |
533 (if end-true-part-address | |
534 ;; This is the place to jump to after the end of TRUE-PART. | |
535 (ccl-embed-current-address end-true-part-address)))) | |
536 unconditional-jump))) | |
537 | |
538 ;; Compile BRANCH statement. | |
539 (defun ccl-compile-branch (cmd) | |
540 (if (< (length cmd) 3) | |
541 (error "CCL: Invalid number of arguments: %s" cmd)) | |
542 (ccl-compile-branch-blocks 'branch | |
543 (ccl-compile-branch-expression (nth 1 cmd) cmd) | |
544 (cdr (cdr cmd)))) | |
545 | |
546 ;; Compile READ statement of the form `(read-branch EXPR BLOCK0 BLOCK1 ...)'. | |
547 (defun ccl-compile-read-branch (cmd) | |
548 (if (< (length cmd) 3) | |
549 (error "CCL: Invalid number of arguments: %s" cmd)) | |
550 (ccl-compile-branch-blocks 'read-branch | |
551 (ccl-compile-branch-expression (nth 1 cmd) cmd) | |
552 (cdr (cdr cmd)))) | |
553 | |
554 ;; Compile EXPRESSION part of BRANCH statement and return register | |
555 ;; which holds a value of the expression. | |
556 (defun ccl-compile-branch-expression (expr cmd) | |
557 (if (listp expr) | |
558 ;; EXPR has the form `(EXPR2 OP ARG)'. Compile it as SET | |
559 ;; statement of the form `(r7 = (EXPR2 OP ARG))'. | |
560 (progn | |
561 (ccl-compile-expression 'r7 expr) | |
562 'r7) | |
563 (ccl-check-register expr cmd))) | |
564 | |
565 ;; Compile BLOCKs of BRANCH statement. CODE is 'branch or 'read-branch. | |
566 ;; REG is a register which holds a value of EXPRESSION part. BLOCKs | |
567 ;; is a list of CCL-BLOCKs. | |
568 (defun ccl-compile-branch-blocks (code rrr blocks) | |
569 (let ((branches (length blocks)) | |
570 branch-idx | |
571 jump-table-head-address | |
572 empty-block-indexes | |
573 block-tail-addresses | |
574 block-unconditional-jump) | |
575 (ccl-embed-code code rrr branches) | |
576 (setq jump-table-head-address ccl-current-ic) | |
577 ;; The size of jump table is the number of blocks plus 1 (for the | |
578 ;; case RRR is out of range). | |
579 (ccl-increment-ic (1+ branches)) | |
580 (setq empty-block-indexes (list branches)) | |
581 ;; Compile each block. | |
582 (setq branch-idx 0) | |
583 (while blocks | |
584 (if (null (car blocks)) | |
585 ;; This block is empty. | |
586 (setq empty-block-indexes (cons branch-idx empty-block-indexes) | |
587 block-unconditional-jump t) | |
588 ;; This block is not empty. | |
589 (ccl-embed-data (- ccl-current-ic jump-table-head-address) | |
590 (+ jump-table-head-address branch-idx)) | |
591 (setq block-unconditional-jump (ccl-compile-1 (car blocks))) | |
592 (if (not block-unconditional-jump) | |
593 (progn | |
594 ;; Jump address of the end of branches are embedded later. | |
595 ;; For the moment, just remember where to embed them. | |
596 (setq block-tail-addresses | |
597 (cons ccl-current-ic block-tail-addresses)) | |
598 (ccl-embed-code 'jump 0 0)))) | |
599 (setq branch-idx (1+ branch-idx)) | |
600 (setq blocks (cdr blocks))) | |
601 (if (not block-unconditional-jump) | |
602 ;; We don't need jump code at the end of the last block. | |
603 (setq block-tail-addresses (cdr block-tail-addresses) | |
604 ccl-current-ic (1- ccl-current-ic))) | |
605 ;; Embed jump address at the tailing jump commands of blocks. | |
606 (while block-tail-addresses | |
607 (ccl-embed-current-address (car block-tail-addresses)) | |
608 (setq block-tail-addresses (cdr block-tail-addresses))) | |
609 ;; For empty blocks, make entries in the jump table point directly here. | |
610 (while empty-block-indexes | |
611 (ccl-embed-data (- ccl-current-ic jump-table-head-address) | |
612 (+ jump-table-head-address (car empty-block-indexes))) | |
613 (setq empty-block-indexes (cdr empty-block-indexes)))) | |
614 ;; Branch command ends by unconditional jump if RRR is out of range. | |
615 nil) | |
616 | |
617 ;; Compile LOOP statement. | |
618 (defun ccl-compile-loop (cmd) | |
619 (if (< (length cmd) 2) | |
620 (error "CCL: Invalid number of arguments: %s" cmd)) | |
621 (let* ((ccl-loop-head ccl-current-ic) | |
622 (ccl-breaks nil) | |
623 unconditional-jump) | |
624 (setq cmd (cdr cmd)) | |
625 (if cmd | |
626 (progn | |
627 (setq unconditional-jump t) | |
628 (while cmd | |
629 (setq unconditional-jump | |
630 (and (ccl-compile-1 (car cmd)) unconditional-jump)) | |
631 (setq cmd (cdr cmd))) | |
632 (if (not ccl-breaks) | |
633 unconditional-jump | |
634 ;; Embed jump address for break statements encountered in | |
635 ;; this loop. | |
636 (while ccl-breaks | |
637 (ccl-embed-current-address (car ccl-breaks)) | |
638 (setq ccl-breaks (cdr ccl-breaks)))) | |
639 nil)))) | |
640 | |
641 ;; Compile BREAK statement. | |
642 (defun ccl-compile-break (cmd) | |
643 (if (/= (length cmd) 1) | |
644 (error "CCL: Invalid number of arguments: %s" cmd)) | |
645 (if (null ccl-loop-head) | |
646 (error "CCL: No outer loop: %s" cmd)) | |
647 (setq ccl-breaks (cons ccl-current-ic ccl-breaks)) | |
648 (ccl-embed-code 'jump 0 0) | |
649 t) | |
650 | |
651 ;; Compile REPEAT statement. | |
652 (defun ccl-compile-repeat (cmd) | |
653 (if (/= (length cmd) 1) | |
654 (error "CCL: Invalid number of arguments: %s" cmd)) | |
655 (if (null ccl-loop-head) | |
656 (error "CCL: No outer loop: %s" cmd)) | |
657 (ccl-embed-code 'jump 0 ccl-loop-head) | |
658 t) | |
659 | |
660 ;; Compile WRITE-REPEAT statement. | |
661 (defun ccl-compile-write-repeat (cmd) | |
662 (if (/= (length cmd) 2) | |
663 (error "CCL: Invalid number of arguments: %s" cmd)) | |
664 (if (null ccl-loop-head) | |
665 (error "CCL: No outer loop: %s" cmd)) | |
666 (let ((arg (nth 1 cmd))) | |
667 (cond ((integerp arg) | |
668 (ccl-embed-code 'write-const-jump 0 ccl-loop-head) | |
669 (ccl-embed-data arg)) | |
670 ((stringp arg) | |
29030
837bc0327945
(ccl-compile-write-string): Make STR unibyte.
Kenichi Handa <handa@m17n.org>
parents:
28152
diff
changeset
|
671 (setq arg (string-as-unibyte arg)) |
17052 | 672 (let ((len (length arg)) |
673 (i 0)) | |
674 (ccl-embed-code 'write-string-jump 0 ccl-loop-head) | |
675 (ccl-embed-data len) | |
676 (ccl-embed-string len arg))) | |
677 (t | |
678 (ccl-check-register arg cmd) | |
679 (ccl-embed-code 'write-register-jump arg ccl-loop-head)))) | |
680 t) | |
681 | |
682 ;; Compile WRITE-READ-REPEAT statement. | |
683 (defun ccl-compile-write-read-repeat (cmd) | |
684 (if (or (< (length cmd) 2) (> (length cmd) 3)) | |
685 (error "CCL: Invalid number of arguments: %s" cmd)) | |
686 (if (null ccl-loop-head) | |
687 (error "CCL: No outer loop: %s" cmd)) | |
688 (let ((rrr (ccl-check-register (nth 1 cmd) cmd)) | |
689 (arg (nth 2 cmd))) | |
690 (cond ((null arg) | |
691 (ccl-embed-code 'write-register-read-jump rrr ccl-loop-head)) | |
692 ((integerp arg) | |
693 (ccl-embed-code 'write-const-read-jump rrr arg ccl-loop-head)) | |
694 ((vectorp arg) | |
695 (let ((len (length arg)) | |
696 (i 0)) | |
697 (ccl-embed-code 'write-array-read-jump rrr ccl-loop-head) | |
698 (ccl-embed-data len) | |
699 (while (< i len) | |
700 (ccl-embed-data (aref arg i)) | |
701 (setq i (1+ i))))) | |
702 (t | |
703 (error "CCL: Invalid argument %s: %s" arg cmd))) | |
704 (ccl-embed-code 'read-jump rrr ccl-loop-head)) | |
705 t) | |
706 | |
707 ;; Compile READ statement. | |
708 (defun ccl-compile-read (cmd) | |
709 (if (< (length cmd) 2) | |
710 (error "CCL: Invalid number of arguments: %s" cmd)) | |
711 (let* ((args (cdr cmd)) | |
712 (i (1- (length args)))) | |
713 (while args | |
714 (let ((rrr (ccl-check-register (car args) cmd))) | |
715 (ccl-embed-code 'read-register rrr i) | |
716 (setq args (cdr args) i (1- i))))) | |
717 nil) | |
718 | |
719 ;; Compile READ-IF statement. | |
720 (defun ccl-compile-read-if (cmd) | |
721 (ccl-compile-if cmd 'read)) | |
722 | |
723 ;; Compile WRITE statement. | |
724 (defun ccl-compile-write (cmd) | |
725 (if (< (length cmd) 2) | |
726 (error "CCL: Invalid number of arguments: %s" cmd)) | |
727 (let ((rrr (nth 1 cmd))) | |
728 (cond ((integerp rrr) | |
729 (ccl-embed-code 'write-const-string 0 rrr)) | |
730 ((stringp rrr) | |
731 (ccl-compile-write-string rrr)) | |
732 ((and (symbolp rrr) (vectorp (nth 2 cmd))) | |
733 (ccl-check-register rrr cmd) | |
734 ;; CMD has the form `(write REG ARRAY)'. | |
735 (let* ((arg (nth 2 cmd)) | |
736 (len (length arg)) | |
737 (i 0)) | |
738 (ccl-embed-code 'write-array rrr len) | |
739 (while (< i len) | |
740 (if (not (integerp (aref arg i))) | |
741 (error "CCL: Invalid argument %s: %s" arg cmd)) | |
742 (ccl-embed-data (aref arg i)) | |
743 (setq i (1+ i))))) | |
744 | |
745 ((symbolp rrr) | |
746 ;; CMD has the form `(write REG ...)'. | |
747 (let* ((args (cdr cmd)) | |
748 (i (1- (length args)))) | |
749 (while args | |
750 (setq rrr (ccl-check-register (car args) cmd)) | |
751 (ccl-embed-code 'write-register rrr i) | |
752 (setq args (cdr args) i (1- i))))) | |
753 | |
754 ((listp rrr) | |
755 ;; CMD has the form `(write (LEFT OP RIGHT))'. | |
756 (let ((left (car rrr)) | |
757 (op (get (nth 1 rrr) 'ccl-arith-code)) | |
758 (right (nth 2 rrr))) | |
759 (if (listp left) | |
760 (progn | |
761 ;; RRR has the form `((EXPR OP2 ARG) OP RIGHT)'. | |
762 ;; Compile the first term as `(r7 = (EXPR OP2 ARG))'. | |
763 (ccl-compile-expression 'r7 left) | |
764 (setq left 'r7))) | |
765 ;; Now RRR has the form `(ARG OP RIGHT)'. | |
766 (if (integerp right) | |
767 (progn | |
768 (ccl-embed-code 'write-expr-const 0 (ash op 3) left) | |
769 (ccl-embed-data right)) | |
770 (ccl-check-register right rrr) | |
771 (ccl-embed-code 'write-expr-register 0 | |
772 (logior (ash op 3) | |
773 (get right 'ccl-register-number)))))) | |
774 | |
775 (t | |
776 (error "CCL: Invalid argument: %s" cmd)))) | |
777 nil) | |
778 | |
779 ;; Compile CALL statement. | |
780 (defun ccl-compile-call (cmd) | |
781 (if (/= (length cmd) 2) | |
782 (error "CCL: Invalid number of arguments: %s" cmd)) | |
783 (if (not (symbolp (nth 1 cmd))) | |
784 (error "CCL: Subroutine should be a symbol: %s" cmd)) | |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
785 (ccl-embed-code 'call 1 0) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
786 (ccl-embed-symbol (nth 1 cmd) 'ccl-program-idx) |
17052 | 787 nil) |
788 | |
789 ;; Compile END statement. | |
790 (defun ccl-compile-end (cmd) | |
791 (if (/= (length cmd) 1) | |
792 (error "CCL: Invalid number of arguments: %s" cmd)) | |
793 (ccl-embed-code 'end 0 0) | |
794 t) | |
795 | |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
796 ;; Compile read-multibyte-character |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
797 (defun ccl-compile-read-multibyte-character (cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
798 (if (/= (length cmd) 3) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
799 (error "CCL: Invalid number of arguments: %s" cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
800 (let ((RRR (nth 1 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
801 (rrr (nth 2 cmd))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
802 (ccl-check-register rrr cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
803 (ccl-check-register RRR cmd) |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
804 (ccl-embed-extended-command 'read-multibyte-character rrr RRR 0)) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
805 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
806 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
807 ;; Compile write-multibyte-character |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
808 (defun ccl-compile-write-multibyte-character (cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
809 (if (/= (length cmd) 3) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
810 (error "CCL: Invalid number of arguments: %s" cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
811 (let ((RRR (nth 1 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
812 (rrr (nth 2 cmd))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
813 (ccl-check-register rrr cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
814 (ccl-check-register RRR cmd) |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
815 (ccl-embed-extended-command 'write-multibyte-character rrr RRR 0)) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
816 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
817 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
818 ;; Compile translate-character |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
819 (defun ccl-compile-translate-character (cmd) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
820 (if (/= (length cmd) 4) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
821 (error "CCL: Invalid number of arguments: %s" cmd)) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
822 (let ((Rrr (nth 1 cmd)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
823 (RRR (nth 2 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
824 (rrr (nth 3 cmd))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
825 (ccl-check-register rrr cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
826 (ccl-check-register RRR cmd) |
24152
202b1402425b
(ccl-compile-translate-character): Handle
Kenichi Handa <handa@m17n.org>
parents:
23771
diff
changeset
|
827 (cond ((and (symbolp Rrr) (not (get Rrr 'ccl-register-number))) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
828 (ccl-embed-extended-command 'translate-character-const-tbl |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
829 rrr RRR 0) |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
830 (ccl-embed-symbol Rrr 'translation-table-id)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
831 (t |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
832 (ccl-check-register Rrr cmd) |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
833 (ccl-embed-extended-command 'translate-character rrr RRR Rrr)))) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
834 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
835 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
836 (defun ccl-compile-iterate-multiple-map (cmd) |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
837 (ccl-compile-multiple-map-function 'iterate-multiple-map cmd) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
838 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
839 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
840 (defun ccl-compile-map-multiple (cmd) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
841 (if (/= (length cmd) 4) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
842 (error "CCL: Invalid number of arguments: %s" cmd)) |
29429
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
843 (let (func arg) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
844 (setq func |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
845 (lambda (arg mp) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
846 (let ((len 0) result add) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
847 (while arg |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
848 (if (consp (car arg)) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
849 (setq add (funcall func (car arg) t) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
850 result (append result add) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
851 add (+ (- (car add)) 1)) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
852 (setq result |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
853 (append result |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
854 (list (car arg))) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
855 add 1)) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
856 (setq arg (cdr arg) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
857 len (+ len add))) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
858 (if mp |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
859 (cons (- len) result) |
1fa36ef2bb6c
(ccl-compile-translate-character): Don't check if Rrr has property
Kenichi Handa <handa@m17n.org>
parents:
29044
diff
changeset
|
860 result)))) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
861 (setq arg (append (list (nth 0 cmd) (nth 1 cmd) (nth 2 cmd)) |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
862 (funcall func (nth 3 cmd) nil))) |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
863 (ccl-compile-multiple-map-function 'map-multiple arg)) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
864 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
865 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
866 (defun ccl-compile-map-single (cmd) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
867 (if (/= (length cmd) 4) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
868 (error "CCL: Invalid number of arguments: %s" cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
869 (let ((RRR (nth 1 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
870 (rrr (nth 2 cmd)) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
871 (map (nth 3 cmd)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
872 id) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
873 (ccl-check-register rrr cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
874 (ccl-check-register RRR cmd) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
875 (ccl-embed-extended-command 'map-single rrr RRR 0) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
876 (cond ((symbolp map) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
877 (if (get map 'code-conversion-map) |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
878 (ccl-embed-symbol map 'code-conversion-map-id) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
879 (error "CCL: Invalid map: %s" map))) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
880 (t |
23432
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
881 (error "CCL: Invalid type of arguments: %s" cmd)))) |
5f51adf0b6ec
(ccl-compile-if): If there's no false-cmds,
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
882 nil) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
883 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
884 (defun ccl-compile-multiple-map-function (command cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
885 (if (< (length cmd) 4) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
886 (error "CCL: Invalid number of arguments: %s" cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
887 (let ((RRR (nth 1 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
888 (rrr (nth 2 cmd)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
889 (args (nthcdr 3 cmd)) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
890 map) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
891 (ccl-check-register rrr cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
892 (ccl-check-register RRR cmd) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
893 (ccl-embed-extended-command command rrr RRR 0) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
894 (ccl-embed-data (length args)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
895 (while args |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
896 (setq map (car args)) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
897 (cond ((symbolp map) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
898 (if (get map 'code-conversion-map) |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
899 (ccl-embed-symbol map 'code-conversion-map-id) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
900 (error "CCL: Invalid map: %s" map))) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
901 ((numberp map) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
902 (ccl-embed-data map)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
903 (t |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
904 (error "CCL: Invalid type of arguments: %s" cmd))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
905 (setq args (cdr args))))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
906 |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
907 |
17052 | 908 ;;; CCL dump staffs |
909 | |
910 ;; To avoid byte-compiler warning. | |
911 (defvar ccl-code) | |
912 | |
913 ;;;###autoload | |
914 (defun ccl-dump (ccl-code) | |
915 "Disassemble compiled CCL-CODE." | |
916 (let ((len (length ccl-code)) | |
917 (buffer-mag (aref ccl-code 0))) | |
918 (cond ((= buffer-mag 0) | |
919 (insert "Don't output anything.\n")) | |
920 ((= buffer-mag 1) | |
921 (insert "Out-buffer must be as large as in-buffer.\n")) | |
922 (t | |
923 (insert | |
924 (format "Out-buffer must be %d times bigger than in-buffer.\n" | |
925 buffer-mag)))) | |
926 (insert "Main-body:\n") | |
927 (setq ccl-current-ic 2) | |
928 (if (> (aref ccl-code 1) 0) | |
929 (progn | |
930 (while (< ccl-current-ic (aref ccl-code 1)) | |
931 (ccl-dump-1)) | |
932 (insert "At EOF:\n"))) | |
933 (while (< ccl-current-ic len) | |
934 (ccl-dump-1)) | |
935 )) | |
936 | |
937 ;; Return a CCL code in `ccl-code' at `ccl-current-ic'. | |
938 (defun ccl-get-next-code () | |
939 (prog1 | |
940 (aref ccl-code ccl-current-ic) | |
941 (setq ccl-current-ic (1+ ccl-current-ic)))) | |
942 | |
943 (defun ccl-dump-1 () | |
944 (let* ((code (ccl-get-next-code)) | |
945 (cmd (aref ccl-code-table (logand code 31))) | |
946 (rrr (ash (logand code 255) -5)) | |
947 (cc (ash code -8))) | |
948 (insert (format "%5d:[%s] " (1- ccl-current-ic) cmd)) | |
949 (funcall (get cmd 'ccl-dump-function) rrr cc))) | |
950 | |
951 (defun ccl-dump-set-register (rrr cc) | |
952 (insert (format "r%d = r%d\n" rrr cc))) | |
953 | |
954 (defun ccl-dump-set-short-const (rrr cc) | |
955 (insert (format "r%d = %d\n" rrr cc))) | |
956 | |
957 (defun ccl-dump-set-const (rrr ignore) | |
958 (insert (format "r%d = %d\n" rrr (ccl-get-next-code)))) | |
959 | |
960 (defun ccl-dump-set-array (rrr cc) | |
961 (let ((rrr2 (logand cc 7)) | |
962 (len (ash cc -3)) | |
963 (i 0)) | |
964 (insert (format "r%d = array[r%d] of length %d\n\t" | |
965 rrr rrr2 len)) | |
966 (while (< i len) | |
967 (insert (format "%d " (ccl-get-next-code))) | |
968 (setq i (1+ i))) | |
969 (insert "\n"))) | |
970 | |
971 (defun ccl-dump-jump (ignore cc &optional address) | |
972 (insert (format "jump to %d(" (+ (or address ccl-current-ic) cc))) | |
973 (if (>= cc 0) | |
974 (insert "+")) | |
975 (insert (format "%d)\n" (1+ cc)))) | |
976 | |
977 (defun ccl-dump-jump-cond (rrr cc) | |
978 (insert (format "if (r%d == 0), " rrr)) | |
979 (ccl-dump-jump nil cc)) | |
980 | |
981 (defun ccl-dump-write-register-jump (rrr cc) | |
982 (insert (format "write r%d, " rrr)) | |
983 (ccl-dump-jump nil cc)) | |
984 | |
985 (defun ccl-dump-write-register-read-jump (rrr cc) | |
986 (insert (format "write r%d, read r%d, " rrr rrr)) | |
987 (ccl-dump-jump nil cc) | |
988 (ccl-get-next-code) ; Skip dummy READ-JUMP | |
989 ) | |
990 | |
991 (defun ccl-extract-arith-op (cc) | |
992 (aref ccl-arith-table (ash cc -6))) | |
993 | |
994 (defun ccl-dump-write-expr-const (ignore cc) | |
995 (insert (format "write (r%d %s %d)\n" | |
996 (logand cc 7) | |
997 (ccl-extract-arith-op cc) | |
998 (ccl-get-next-code)))) | |
999 | |
1000 (defun ccl-dump-write-expr-register (ignore cc) | |
1001 (insert (format "write (r%d %s r%d)\n" | |
1002 (logand cc 7) | |
1003 (ccl-extract-arith-op cc) | |
1004 (logand (ash cc -3) 7)))) | |
1005 | |
1006 (defun ccl-dump-insert-char (cc) | |
1007 (cond ((= cc ?\t) (insert " \"^I\"")) | |
1008 ((= cc ?\n) (insert " \"^J\"")) | |
1009 (t (insert (format " \"%c\"" cc))))) | |
1010 | |
1011 (defun ccl-dump-write-const-jump (ignore cc) | |
1012 (let ((address ccl-current-ic)) | |
1013 (insert "write char") | |
1014 (ccl-dump-insert-char (ccl-get-next-code)) | |
1015 (insert ", ") | |
1016 (ccl-dump-jump nil cc address))) | |
1017 | |
1018 (defun ccl-dump-write-const-read-jump (rrr cc) | |
1019 (let ((address ccl-current-ic)) | |
1020 (insert "write char") | |
1021 (ccl-dump-insert-char (ccl-get-next-code)) | |
1022 (insert (format ", read r%d, " rrr)) | |
1023 (ccl-dump-jump cc address) | |
1024 (ccl-get-next-code) ; Skip dummy READ-JUMP | |
1025 )) | |
1026 | |
1027 (defun ccl-dump-write-string-jump (ignore cc) | |
1028 (let ((address ccl-current-ic) | |
1029 (len (ccl-get-next-code)) | |
1030 (i 0)) | |
1031 (insert "write \"") | |
1032 (while (< i len) | |
1033 (let ((code (ccl-get-next-code))) | |
1034 (insert (ash code -16)) | |
1035 (if (< (1+ i) len) (insert (logand (ash code -8) 255))) | |
1036 (if (< (+ i 2) len) (insert (logand code 255)))) | |
1037 (setq i (+ i 3))) | |
1038 (insert "\", ") | |
1039 (ccl-dump-jump nil cc address))) | |
1040 | |
1041 (defun ccl-dump-write-array-read-jump (rrr cc) | |
1042 (let ((address ccl-current-ic) | |
1043 (len (ccl-get-next-code)) | |
1044 (i 0)) | |
1045 (insert (format "write array[r%d] of length %d,\n\t" rrr len)) | |
1046 (while (< i len) | |
1047 (ccl-dump-insert-char (ccl-get-next-code)) | |
1048 (setq i (1+ i))) | |
1049 (insert (format "\n\tthen read r%d, " rrr)) | |
1050 (ccl-dump-jump nil cc address) | |
1051 (ccl-get-next-code) ; Skip dummy READ-JUMP. | |
1052 )) | |
1053 | |
1054 (defun ccl-dump-read-jump (rrr cc) | |
1055 (insert (format "read r%d, " rrr)) | |
1056 (ccl-dump-jump nil cc)) | |
1057 | |
1058 (defun ccl-dump-branch (rrr len) | |
1059 (let ((jump-table-head ccl-current-ic) | |
1060 (i 0)) | |
1061 (insert (format "jump to array[r%d] of length %d\n\t" rrr len)) | |
1062 (while (<= i len) | |
1063 (insert (format "%d " (+ jump-table-head (ccl-get-next-code)))) | |
1064 (setq i (1+ i))) | |
1065 (insert "\n"))) | |
1066 | |
1067 (defun ccl-dump-read-register (rrr cc) | |
1068 (insert (format "read r%d (%d remaining)\n" rrr cc))) | |
1069 | |
1070 (defun ccl-dump-read-branch (rrr len) | |
1071 (insert (format "read r%d, " rrr)) | |
1072 (ccl-dump-branch rrr len)) | |
1073 | |
1074 (defun ccl-dump-write-register (rrr cc) | |
1075 (insert (format "write r%d (%d remaining)\n" rrr cc))) | |
1076 | |
1077 (defun ccl-dump-call (ignore cc) | |
1078 (insert (format "call subroutine #%d\n" cc))) | |
1079 | |
1080 (defun ccl-dump-write-const-string (rrr cc) | |
1081 (if (= rrr 0) | |
1082 (progn | |
1083 (insert "write char") | |
1084 (ccl-dump-insert-char cc) | |
1085 (newline)) | |
1086 (let ((len cc) | |
1087 (i 0)) | |
1088 (insert "write \"") | |
1089 (while (< i len) | |
1090 (let ((code (ccl-get-next-code))) | |
1091 (insert (format "%c" (lsh code -16))) | |
1092 (if (< (1+ i) len) | |
1093 (insert (format "%c" (logand (lsh code -8) 255)))) | |
1094 (if (< (+ i 2) len) | |
1095 (insert (format "%c" (logand code 255)))) | |
1096 (setq i (+ i 3)))) | |
1097 (insert "\"\n")))) | |
1098 | |
1099 (defun ccl-dump-write-array (rrr cc) | |
1100 (let ((i 0)) | |
1101 (insert (format "write array[r%d] of length %d\n\t" rrr cc)) | |
1102 (while (< i cc) | |
1103 (ccl-dump-insert-char (ccl-get-next-code)) | |
1104 (setq i (1+ i))) | |
1105 (insert "\n"))) | |
1106 | |
1107 (defun ccl-dump-end (&rest ignore) | |
1108 (insert "end\n")) | |
1109 | |
1110 (defun ccl-dump-set-assign-expr-const (rrr cc) | |
1111 (insert (format "r%d %s= %d\n" | |
1112 rrr | |
1113 (ccl-extract-arith-op cc) | |
1114 (ccl-get-next-code)))) | |
1115 | |
1116 (defun ccl-dump-set-assign-expr-register (rrr cc) | |
1117 (insert (format "r%d %s= r%d\n" | |
1118 rrr | |
1119 (ccl-extract-arith-op cc) | |
1120 (logand cc 7)))) | |
1121 | |
1122 (defun ccl-dump-set-expr-const (rrr cc) | |
1123 (insert (format "r%d = r%d %s %d\n" | |
1124 rrr | |
1125 (logand cc 7) | |
1126 (ccl-extract-arith-op cc) | |
1127 (ccl-get-next-code)))) | |
1128 | |
1129 (defun ccl-dump-set-expr-register (rrr cc) | |
1130 (insert (format "r%d = r%d %s r%d\n" | |
1131 rrr | |
1132 (logand cc 7) | |
1133 (ccl-extract-arith-op cc) | |
1134 (logand (ash cc -3) 7)))) | |
1135 | |
1136 (defun ccl-dump-jump-cond-expr-const (rrr cc) | |
1137 (let ((address ccl-current-ic)) | |
1138 (insert (format "if !(r%d %s %d), " | |
1139 rrr | |
1140 (aref ccl-arith-table (ccl-get-next-code)) | |
1141 (ccl-get-next-code))) | |
1142 (ccl-dump-jump nil cc address))) | |
1143 | |
1144 (defun ccl-dump-jump-cond-expr-register (rrr cc) | |
1145 (let ((address ccl-current-ic)) | |
1146 (insert (format "if !(r%d %s r%d), " | |
1147 rrr | |
1148 (aref ccl-arith-table (ccl-get-next-code)) | |
1149 (ccl-get-next-code))) | |
1150 (ccl-dump-jump nil cc address))) | |
1151 | |
1152 (defun ccl-dump-read-jump-cond-expr-const (rrr cc) | |
1153 (insert (format "read r%d, " rrr)) | |
1154 (ccl-dump-jump-cond-expr-const rrr cc)) | |
1155 | |
1156 (defun ccl-dump-read-jump-cond-expr-register (rrr cc) | |
1157 (insert (format "read r%d, " rrr)) | |
1158 (ccl-dump-jump-cond-expr-register rrr cc)) | |
1159 | |
1160 (defun ccl-dump-binary (ccl-code) | |
1161 (let ((len (length ccl-code)) | |
1162 (i 2)) | |
1163 (while (< i len) | |
1164 (let ((code (aref ccl-code i)) | |
1165 (j 27)) | |
1166 (while (>= j 0) | |
1167 (insert (if (= (logand code (ash 1 j)) 0) ?0 ?1)) | |
1168 (setq j (1- j))) | |
1169 (setq code (logand code 31)) | |
1170 (if (< code (length ccl-code-table)) | |
1171 (insert (format ":%s" (aref ccl-code-table code)))) | |
1172 (insert "\n")) | |
1173 (setq i (1+ i))))) | |
1174 | |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1175 (defun ccl-dump-ex-cmd (rrr cc) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1176 (let* ((RRR (logand cc ?\x7)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1177 (Rrr (logand (ash cc -3) ?\x7)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1178 (ex-op (aref ccl-extended-code-table (logand (ash cc -6) ?\x3fff)))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1179 (insert (format "<%s> " ex-op)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1180 (funcall (get ex-op 'ccl-dump-function) rrr RRR Rrr))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1181 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1182 (defun ccl-dump-read-multibyte-character (rrr RRR Rrr) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1183 (insert (format "read-multibyte-character r%d r%d\n" RRR rrr))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1184 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1185 (defun ccl-dump-write-multibyte-character (rrr RRR Rrr) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1186 (insert (format "write-multibyte-character r%d r%d\n" RRR rrr))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1187 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1188 (defun ccl-dump-translate-character (rrr RRR Rrr) |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22127
diff
changeset
|
1189 (insert (format "translation table(r%d) r%d r%d\n" Rrr RRR rrr))) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1190 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1191 (defun ccl-dump-translate-character-const-tbl (rrr RRR Rrr) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1192 (let ((tbl (ccl-get-next-code))) |
23771
0ed776e14a50
(ccl-dump-translate-character-const-tbl):
Kenichi Handa <handa@m17n.org>
parents:
23432
diff
changeset
|
1193 (insert (format "translation table(%S) r%d r%d\n" tbl RRR rrr)))) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1194 |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1195 (defun ccl-dump-iterate-multiple-map (rrr RRR Rrr) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1196 (let ((notbl (ccl-get-next-code)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1197 (i 0) id) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1198 (insert (format "iterate-multiple-map r%d r%d\n" RRR rrr)) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1199 (insert (format "\tnumber of maps is %d .\n\t [" notbl)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1200 (while (< i notbl) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1201 (setq id (ccl-get-next-code)) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1202 (insert (format "%S" id)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1203 (setq i (1+ i))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1204 (insert "]\n"))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1205 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1206 (defun ccl-dump-map-multiple (rrr RRR Rrr) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1207 (let ((notbl (ccl-get-next-code)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1208 (i 0) id) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1209 (insert (format "map-multiple r%d r%d\n" RRR rrr)) |
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1210 (insert (format "\tnumber of maps and separators is %d\n\t [" notbl)) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1211 (while (< i notbl) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1212 (setq id (ccl-get-next-code)) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1213 (if (= id -1) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1214 (insert "]\n\t [") |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1215 (insert (format "%S " id))) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1216 (setq i (1+ i))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1217 (insert "]\n"))) |
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1218 |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1219 (defun ccl-dump-map-single (rrr RRR Rrr) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1220 (let ((id (ccl-get-next-code))) |
22127
dc00ef92855c
Change term translate-XXX-map to map-XXX
Kenichi Handa <handa@m17n.org>
parents:
21977
diff
changeset
|
1221 (insert (format "map-single r%d r%d map(%S)\n" RRR rrr id)))) |
20735
d97c44710cac
Comment about CCL syntax modified.
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
1222 |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1223 |
17052 | 1224 ;; CCL emulation staffs |
1225 | |
1226 ;; Not yet implemented. | |
1227 | |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1228 ;; Auto-loaded functions. |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1229 |
17052 | 1230 ;;;###autoload |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1231 (defmacro declare-ccl-program (name &optional vector) |
17052 | 1232 "Declare NAME as a name of CCL program. |
1233 | |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1234 This macro exists for backward compatibility. In the old version of |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1235 Emacs, to compile a CCL program which calls another CCL program not |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1236 yet defined, it must be declared as a CCL program in advance. But, |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1237 now CCL program names are resolved not at compile time but before |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1238 execution. |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1239 |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1240 Optional arg VECTOR is a compiled CCL code of the CCL program." |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1241 `(put ',name 'ccl-program-idx (register-ccl-program ',name ,vector))) |
17052 | 1242 |
1243 ;;;###autoload | |
1244 (defmacro define-ccl-program (name ccl-program &optional doc) | |
1245 "Set NAME the compiled code of CCL-PROGRAM. | |
30845
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1246 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1247 CCL-PROGRAM is has this form: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1248 (BUFFER_MAGNIFICATION |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1249 CCL_MAIN_CODE |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1250 [ CCL_EOF_CODE ]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1251 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1252 BUFFER_MAGNIFICATION is an integer value specifying the approximate |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1253 output buffer magnification size compared with the bytes of input data |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1254 text. If the value is zero, the CCL program can't execute `read' and |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1255 `write' commands. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1256 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1257 CCL_MAIN_CODE and CCL_EOF_CODE are CCL program codes. CCL_MAIN_CODE |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1258 executed at first. If there's no more input data when `read' command |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1259 is executed in CCL_MAIN_CODE, CCL_EOF_CODE is executed. If |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1260 CCL_MAIN_CODE is terminated, CCL_EOF_CODE is not executed. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1261 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1262 Here's the syntax of CCL program code in BNF notation. The lines |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1263 starting by two semicolons (and optional leading spaces) describe the |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1264 semantics. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1265 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1266 CCL_MAIN_CODE := CCL_BLOCK |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1267 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1268 CCL_EOF_CODE := CCL_BLOCK |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1269 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1270 CCL_BLOCK := STATEMENT | (STATEMENT [STATEMENT ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1271 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1272 STATEMENT := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1273 SET | IF | BRANCH | LOOP | REPEAT | BREAK | READ | WRITE | CALL |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1274 | TRANSLATE | END |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1275 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1276 SET := (REG = EXPRESSION) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1277 | (REG ASSIGNMENT_OPERATOR EXPRESSION) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1278 ;; The following form is the same as (r0 = integer). |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1279 | integer |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1280 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1281 EXPRESSION := ARG | (EXPRESSION OPERATOR ARG) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1282 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1283 ;; Evaluate EXPRESSION. If the result is nonzeor, execute |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1284 ;; CCL_BLOCK_0. Otherwise, execute CCL_BLOCK_1. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1285 IF := (if EXPRESSION CCL_BLOCK_0 CCL_BLOCK_1) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1286 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1287 ;; Evaluate EXPRESSION. Provided that the result is N, execute |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1288 ;; CCL_BLOCK_N. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1289 BRANCH := (branch EXPRESSION CCL_BLOCK_0 [CCL_BLOCK_1 ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1290 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1291 ;; Execute STATEMENTs until (break) or (end) is executed. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1292 LOOP := (loop STATEMENT [STATEMENT ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1293 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1294 ;; Terminate the most inner loop. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1295 BREAK := (break) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1296 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1297 REPEAT := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1298 ;; Jump to the head of the most inner loop. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1299 (repeat) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1300 ;; Same as: ((write [REG | integer | string]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1301 ;; (repeat)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1302 | (write-repeat [REG | integer | string]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1303 ;; Same as: ((write REG [ARRAY]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1304 ;; (read REG) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1305 ;; (repeat)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1306 | (write-read-repeat REG [ARRAY]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1307 ;; Same as: ((write integer) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1308 ;; (read REG) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1309 ;; (repeat)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1310 | (write-read-repeat REG integer) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1311 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1312 READ := ;; Set REG_0 to a byte read from the input text, set REG_1 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1313 ;; to the next byte read, and so on. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1314 (read REG_0 [REG_1 ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1315 ;; Same as: ((read REG) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1316 ;; (if (REG OPERATOR ARG) CCL_BLOCK_0 CCL_BLOCK_1)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1317 | (read-if (REG OPERATOR ARG) CCL_BLOCK_0 CCL_BLOCK_1) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1318 ;; Same as: ((read REG) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1319 ;; (branch REG CCL_BLOCK_0 [CCL_BLOCK_1 ...])) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1320 | (read-branch REG CCL_BLOCK_0 [CCL_BLOCK_1 ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1321 ;; Read a character from the input text while parsing |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1322 ;; multibyte representation, set REG_0 to the charset ID of |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1323 ;; the character, set REG_1 to the code point of the |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1324 ;; character. If the dimension of charset is two, set REG_1 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1325 ;; to ((CODE0 << 8) | CODE1), where CODE0 is the first code |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1326 ;; point and CODE1 is the second code point. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1327 | (read-multibyte-character REG_0 REG_1) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1328 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1329 WRITE := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1330 ;; Write REG_0, REG_1, ... to the output buffer. If REG_N is |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1331 ;; a multibyte character, write the corresponding multibyte |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1332 ;; representation. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1333 (write REG_0 [REG_1 ...]) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1334 ;; Same as: ((r7 = EXPRESSION) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1335 ;; (write r7)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1336 | (write EXPRESSION) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1337 ;; Write the value of `integer' to the output buffer. If it |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1338 ;; is a multibyte character, write the corresponding multibyte |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1339 ;; representation. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1340 | (write integer) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1341 ;; Write the byte sequence of `string' as is to the output |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1342 ;; buffer. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1343 | (write string) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1344 ;; Same as: (write string) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1345 | string |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1346 ;; Provided that the value of REG is N, write Nth element of |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1347 ;; ARRAY to the output buffer. If it is a multibyte |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1348 ;; character, write the corresponding multibyte |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1349 ;; representation. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1350 | (write REG ARRAY) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1351 ;; Write a multibyte representation of a character whose |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1352 ;; charset ID is REG_0 and code point is REG_1. If the |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1353 ;; dimension of the charset is two, REG_1 should be ((CODE0 << |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1354 ;; 8) | CODE1), where CODE0 is the first code point and CODE1 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1355 ;; is the second code point of the character. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1356 | (write-multibyte-character REG_0 REG_1) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1357 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1358 ;; Call CCL program whose name is ccl-program-name. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1359 CALL := (call ccl-program-name) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1360 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1361 ;; Terminate the CCL program. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1362 END := (end) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1363 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1364 ;; CCL registers that can contain any integer value. As r7 is also |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1365 ;; used by CCL interpreter, its value is changed unexpectedly. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1366 REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1367 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1368 ARG := REG | integer |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1369 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1370 OPERATOR := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1371 ;; Normal arithmethic operators (same meaning as C code). |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1372 + | - | * | / | % |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1373 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1374 ;; Bitwize operators (same meaning as C code) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1375 | & | `|' | ^ |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1376 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1377 ;; Shifting operators (same meaning as C code) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1378 | << | >> |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1379 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1380 ;; (REG = ARG_0 <8 ARG_1) means: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1381 ;; (REG = ((ARG_0 << 8) | ARG_1)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1382 | <8 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1383 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1384 ;; (REG = ARG_0 >8 ARG_1) means: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1385 ;; ((REG = (ARG_0 >> 8)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1386 ;; (r7 = (ARG_0 & 255))) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1387 | >8 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1388 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1389 ;; (REG = ARG_0 // ARG_1) means: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1390 ;; ((REG = (ARG_0 / ARG_1)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1391 ;; (r7 = (ARG_0 % ARG_1))) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1392 | // |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1393 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1394 ;; Normal comparing operators (same meaning as C code) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1395 | < | > | == | <= | >= | != |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1396 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1397 ;; If ARG_0 and ARG_1 are higher and lower byte of Shift-JIS |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1398 ;; code, and CHAR is the corresponding JISX0208 character, |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1399 ;; (REG = ARG_0 de-sjis ARG_1) means: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1400 ;; ((REG = CODE0) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1401 ;; (r7 = CODE1)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1402 ;; where CODE0 is the first code point of CHAR, CODE1 is the |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1403 ;; second code point of CHAR. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1404 | de-sjis |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1405 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1406 ;; If ARG_0 and ARG_1 are the first and second code point of |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1407 ;; JISX0208 character CHAR, and SJIS is the correponding |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1408 ;; Shift-JIS code, |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1409 ;; (REG = ARG_0 en-sjis ARG_1) means: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1410 ;; ((REG = HIGH) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1411 ;; (r7 = LOW)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1412 ;; where HIGH is the higher byte of SJIS, LOW is the lower |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1413 ;; byte of SJIS. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1414 | en-sjis |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1415 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1416 ASSIGNMENT_OPERATOR := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1417 ;; Same meaning as C code |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1418 += | -= | *= | /= | %= | &= | `|=' | ^= | <<= | >>= |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1419 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1420 ;; (REG <8= ARG) is the same as: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1421 ;; ((REG <<= 8) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1422 ;; (REG |= ARG)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1423 | <8= |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1424 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1425 ;; (REG >8= ARG) is the same as: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1426 ;; ((r7 = (REG & 255)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1427 ;; (REG >>= 8)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1428 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1429 ;; (REG //= ARG) is the same as: |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1430 ;; ((r7 = (REG % ARG)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1431 ;; (REG /= ARG)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1432 | //= |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1433 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1434 ARRAY := `[' integer ... `]' |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1435 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1436 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1437 TRANSLATE := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1438 (translate-character REG(table) REG(charset) REG(codepoint)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1439 | (translate-character SYMBOL REG(charset) REG(codepoint)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1440 MAP := |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1441 (iterate-multiple-map REG REG MAP-IDs) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1442 | (map-multiple REG REG (MAP-SET)) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1443 | (map-single REG REG MAP-ID) |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1444 MAP-IDs := MAP-ID ... |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1445 MAP-SET := MAP-IDs | (MAP-IDs) MAP-SET |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1446 MAP-ID := integer |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1447 " |
17052 | 1448 `(let ((prog ,(ccl-compile (eval ccl-program)))) |
1449 (defconst ,name prog ,doc) | |
1450 (put ',name 'ccl-program-idx (register-ccl-program ',name prog)) | |
1451 nil)) | |
1452 | |
1453 ;;;###autoload | |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1454 (defmacro check-ccl-program (ccl-program &optional name) |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1455 "Check validity of CCL-PROGRAM. |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1456 If CCL-PROGRAM is a symbol denoting a CCL program, return |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1457 CCL-PROGRAM, else return nil. |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1458 If CCL-PROGRAM is a vector and optional arg NAME (symbol) is supplied, |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1459 register CCL-PROGRAM by name NAME, and return NAME." |
25064
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1460 `(if (ccl-program-p ,ccl-program) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1461 (if (vectorp ,ccl-program) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1462 (progn |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1463 (register-ccl-program ,name ,ccl-program) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1464 ,name) |
206f04753cc1
(ccl-embed-symbol): New function.
Kenichi Handa <handa@m17n.org>
parents:
24152
diff
changeset
|
1465 ,ccl-program))) |
21661
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1466 |
f763b61886ce
(ccl-compile-unify-character): Inhibit
Kenichi Handa <handa@m17n.org>
parents:
21645
diff
changeset
|
1467 ;;;###autoload |
17052 | 1468 (defun ccl-execute-with-args (ccl-prog &rest args) |
1469 "Execute CCL-PROGRAM with registers initialized by the remaining args. | |
30845
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1470 The return value is a vector of resulting CCL registers. |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1471 |
dcfcae58d8d6
(declare-ccl-program): Docstring modified.
Kenichi Handa <handa@m17n.org>
parents:
30705
diff
changeset
|
1472 See the documentation of `define-ccl-program' for the detail of CCL program." |
17052 | 1473 (let ((reg (make-vector 8 0)) |
1474 (i 0)) | |
1475 (while (and args (< i 8)) | |
1476 (if (not (integerp (car args))) | |
1477 (error "Arguments should be integer")) | |
1478 (aset reg i (car args)) | |
1479 (setq args (cdr args) i (1+ i))) | |
1480 (ccl-execute ccl-prog reg) | |
1481 reg)) | |
1482 | |
1483 (provide 'ccl) | |
1484 | |
1485 ;; ccl.el ends here |