annotate lisp/mule/mule-ccl.el @ 3924:06ead1d71a8d

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