annotate lisp/international/ccl.el @ 95398:f7271aace10a

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