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