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