annotate lisp/mule/mule-ccl.el @ 418:e804706bfb8c r21-2-17

Import from CVS: tag r21-2-17
author cvs
date Mon, 13 Aug 2007 11:23:13 +0200
parents 697ef44129c6
children 95016f13131a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1 ;;; ccl.el --- CCL (Code Conversion Language) compiler
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
2
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
4 ;; Licensed to the Free Software Foundation.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
5
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
6 ;; Keywords: CCL, mule, multilingual, character set, coding-system
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
7
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
8 ;; This file is part of X Emacs.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
9
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
13 ;; any later version.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
14
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
19
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
24
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
25 ;; Synched up with: FSF 20.2
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
26
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
27 ;;; Commentary:
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
28
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
29 ;; CCL (Code Conversion Language) is a simple programming language to
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
30 ;; be used for various kind of code conversion. CCL program is
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
31 ;; compiled to CCL code (vector of integers) and executed by CCL
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
32 ;; interpreter of Emacs.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
33 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
34 ;; CCL is used for code conversion at process I/O and file I/O for
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
35 ;; non-standard coding-system. In addition, it is used for
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
36 ;; calculating a code point of X's font from a character code.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
37 ;; However, since CCL is designed as a powerful programming language,
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
38 ;; it can be used for more generic calculation. For instance,
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
39 ;; combination of three or more arithmetic operations can be
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
40 ;; calculated faster than Emacs Lisp.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
41 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
42 ;; Here's the syntax of CCL program in BNF notation.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
43 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
44 ;; CCL_PROGRAM :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
45 ;; (BUFFER_MAGNIFICATION
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
46 ;; CCL_MAIN_BLOCK
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
47 ;; [ CCL_EOF_BLOCK ])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
48 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
49 ;; BUFFER_MAGNIFICATION := integer
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
50 ;; CCL_MAIN_BLOCK := CCL_BLOCK
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
51 ;; CCL_EOF_BLOCK := CCL_BLOCK
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
52 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
53 ;; CCL_BLOCK :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
54 ;; STATEMENT | (STATEMENT [STATEMENT ...])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
55 ;; STATEMENT :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
56 ;; SET | IF | BRANCH | LOOP | REPEAT | BREAK | READ | WRITE | CALL
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
57 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
58 ;; SET :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
59 ;; (REG = EXPRESSION)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
60 ;; | (REG ASSIGNMENT_OPERATOR EXPRESSION)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
61 ;; | integer
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
62 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
63 ;; EXPRESSION := ARG | (EXPRESSION OPERATOR ARG)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
64 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
65 ;; IF := (if EXPRESSION CCL_BLOCK CCL_BLOCK)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
66 ;; BRANCH := (branch EXPRESSION CCL_BLOCK [CCL_BLOCK ...])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
67 ;; LOOP := (loop STATEMENT [STATEMENT ...])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
68 ;; BREAK := (break)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
69 ;; REPEAT :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
70 ;; (repeat)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
71 ;; | (write-repeat [REG | integer | string])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
72 ;; | (write-read-repeat REG [integer | ARRAY])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
73 ;; READ :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
74 ;; (read REG ...)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
75 ;; | (read-if (REG OPERATOR ARG) CCL_BLOCK CCL_BLOCK)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
76 ;; | (read-branch REG CCL_BLOCK [CCL_BLOCK ...])
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
77 ;; WRITE :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
78 ;; (write REG ...)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
79 ;; | (write EXPRESSION)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
80 ;; | (write integer) | (write string) | (write REG ARRAY)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
81 ;; | string
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
82 ;; CALL := (call ccl-program-name)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
83 ;; END := (end)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
84 ;;
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
85 ;; REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
86 ;; ARG := REG | integer
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
87 ;; OPERATOR :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
88 ;; + | - | * | / | % | & | '|' | ^ | << | >> | <8 | >8 | //
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
89 ;; | < | > | == | <= | >= | != | de-sjis | en-sjis
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
90 ;; ASSIGNMENT_OPERATOR :=
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
91 ;; += | -= | *= | /= | %= | &= | '|=' | ^= | <<= | >>=
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
92 ;; ARRAY := '[' interger ... ']'
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
93
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
94 ;;; Code:
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
95
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
96 (defconst ccl-command-table
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
97 [if branch loop break repeat write-repeat write-read-repeat
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
98 read read-if read-branch write call end]
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
99 "*Vector of CCL commands (symbols).")
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
100
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
101 ;; Put a property to each symbol of CCL commands for the compiler.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
102 (let (op (i 0) (len (length ccl-command-table)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
103 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
104 (setq op (aref ccl-command-table i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
105 (put op 'ccl-compile-function (intern (format "ccl-compile-%s" op)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
106 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
107
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
108 (defconst ccl-code-table
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
109 [set-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
110 set-short-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
111 set-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
112 set-array
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
113 jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
114 jump-cond
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
115 write-register-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
116 write-register-read-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
117 write-const-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
118 write-const-read-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
119 write-string-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
120 write-array-read-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
121 read-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
122 branch
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
123 read-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
124 write-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
125 read-branch
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
126 write-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
127 write-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
128 call
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
129 write-const-string
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
130 write-array
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
131 end
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
132 set-assign-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
133 set-assign-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
134 set-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
135 set-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
136 jump-cond-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
137 jump-cond-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
138 read-jump-cond-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
139 read-jump-cond-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
140 ]
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
141 "*Vector of CCL compiled codes (symbols).")
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
142
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
143 ;; Put a property to each symbol of CCL codes for the disassembler.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
144 (let (code (i 0) (len (length ccl-code-table)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
145 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
146 (setq code (aref ccl-code-table i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
147 (put code 'ccl-code i)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
148 (put code 'ccl-dump-function (intern (format "ccl-dump-%s" code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
149 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
150
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
151 (defconst ccl-jump-code-list
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
152 '(jump jump-cond write-register-jump write-register-read-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
153 write-const-jump write-const-read-jump write-string-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
154 write-array-read-jump read-jump))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
155
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
156 ;; Put a property `jump-flag' to each CCL code which execute jump in
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
157 ;; some way.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
158 (let ((l ccl-jump-code-list))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
159 (while l
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
160 (put (car l) 'jump-flag t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
161 (setq l (cdr l))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
162
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
163 (defconst ccl-register-table
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
164 [r0 r1 r2 r3 r4 r5 r6 r7]
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
165 "*Vector of CCL registers (symbols).")
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
166
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
167 ;; Put a property to indicate register number to each symbol of CCL.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
168 ;; registers.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
169 (let (reg (i 0) (len (length ccl-register-table)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
170 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
171 (setq reg (aref ccl-register-table i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
172 (put reg 'ccl-register-number i)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
173 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
174
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
175 (defconst ccl-arith-table
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
176 [+ - * / % & | ^ << >> <8 >8 // nil nil nil
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
177 < > == <= >= != de-sjis en-sjis]
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
178 "*Vector of CCL arithmetic/logical operators (symbols).")
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
179
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
180 ;; Put a property to each symbol of CCL operators for the compiler.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
181 (let (arith (i 0) (len (length ccl-arith-table)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
182 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
183 (setq arith (aref ccl-arith-table i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
184 (if arith (put arith 'ccl-arith-code i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
185 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
186
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
187 (defconst ccl-assign-arith-table
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
188 [+= -= *= /= %= &= |= ^= <<= >>= <8= >8= //=]
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
189 "*Vector of CCL assignment operators (symbols).")
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
190
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
191 ;; Put a property to each symbol of CCL assignment operators for the compiler.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
192 (let (arith (i 0) (len (length ccl-assign-arith-table)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
193 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
194 (setq arith (aref ccl-assign-arith-table i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
195 (put arith 'ccl-self-arith-code i)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
196 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
197
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
198 (defvar ccl-program-vector nil
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
199 "Working vector of CCL codes produced by CCL compiler.")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
200 (defvar ccl-current-ic 0
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
201 "The current index for `ccl-program-vector'.")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
202
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
203 ;; Embed integer DATA in `ccl-program-vector' at `ccl-current-ic' and
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
204 ;; increment it. If IC is specified, embed DATA at IC.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
205 (defun ccl-embed-data (data &optional ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
206 (let ((val (if (characterp data) (char-int data) data)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
207 (if ic
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
208 (aset ccl-program-vector ic val)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
209 (aset ccl-program-vector ccl-current-ic val)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
210 (setq ccl-current-ic (1+ ccl-current-ic)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
211
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
212 ;; Embed string STR of length LEN in `ccl-program-vector' at
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
213 ;; `ccl-current-ic'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
214 (defun ccl-embed-string (len str)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
215 (let ((i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
216 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
217 (ccl-embed-data (logior (ash (aref str i) 16)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
218 (if (< (1+ i) len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
219 (ash (aref str (1+ i)) 8)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
220 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
221 (if (< (+ i 2) len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
222 (aref str (+ i 2))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
223 0)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
224 (setq i (+ i 3)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
225
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
226 ;; Embed a relative jump address to `ccl-current-ic' in
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
227 ;; `ccl-program-vector' at IC without altering the other bit field.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
228 (defun ccl-embed-current-address (ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
229 (let ((relative (- ccl-current-ic (1+ ic))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
230 (aset ccl-program-vector ic
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
231 (logior (aref ccl-program-vector ic) (ash relative 8)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
232
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
233 ;; Embed CCL code for the operation OP and arguments REG and DATA in
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
234 ;; `ccl-program-vector' at `ccl-current-ic' in the following format.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
235 ;; |----------------- integer (28-bit) ------------------|
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
236 ;; |------------ 20-bit ------------|- 3-bit --|- 5-bit -|
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
237 ;; |------------- DATA -------------|-- REG ---|-- OP ---|
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
238 ;; If REG2 is specified, embed a code in the following format.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
239 ;; |------- 17-bit ------|- 3-bit --|- 3-bit --|- 5-bit -|
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
240 ;; |-------- DATA -------|-- REG2 --|-- REG ---|-- OP ---|
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
241
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
242 ;; If REG is a CCL register symbol (e.g. r0, r1...), the register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
243 ;; number is embedded. If OP is one of unconditional jumps, DATA is
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
244 ;; changed to an relative jump address.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
245
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
246 (defun ccl-embed-code (op reg data &optional reg2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
247 (if (and (> data 0) (get op 'jump-flag))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
248 ;; DATA is an absolute jump address. Make it relative to the
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
249 ;; next of jump code.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
250 (setq data (- data (1+ ccl-current-ic))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
251 (let ((code (logior (get op 'ccl-code)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
252 (ash
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
253 (if (symbolp reg) (get reg 'ccl-register-number) reg) 5)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
254 (if reg2
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
255 (logior (ash (get reg2 'ccl-register-number) 8)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
256 (ash data 11))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
257 (ash data 8)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
258 (aset ccl-program-vector ccl-current-ic code)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
259 (setq ccl-current-ic (1+ ccl-current-ic))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
260
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
261 ;; Just advance `ccl-current-ic' by INC.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
262 (defun ccl-increment-ic (inc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
263 (setq ccl-current-ic (+ ccl-current-ic inc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
264
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
265 ;;;###autoload
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
266 (defun ccl-program-p (obj)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
267 "T if OBJECT is a valid CCL compiled code."
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
268 (and (vectorp obj)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
269 (let ((i 0) (len (length obj)) (flag t))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
270 (if (> len 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
271 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
272 (while (and flag (< i len))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
273 (setq flag (integerp (aref obj i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
274 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
275 flag)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
276
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
277 ;; If non-nil, index of the start of the current loop.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
278 (defvar ccl-loop-head nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
279 ;; If non-nil, list of absolute addresses of the breaking points of
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
280 ;; the current loop.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
281 (defvar ccl-breaks nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
282
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
283 ;;;###autoload
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
284 (defun ccl-compile (ccl-program)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
285 "Return a compiled code of CCL-PROGRAM as a vector of integer."
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
286 (if (or (null (consp ccl-program))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
287 (null (integer-or-char-p (car ccl-program)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
288 (null (listp (car (cdr ccl-program)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
289 (error "CCL: Invalid CCL program: %s" ccl-program))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
290 (if (null (vectorp ccl-program-vector))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
291 (setq ccl-program-vector (make-vector 8192 0)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
292 (setq ccl-loop-head nil ccl-breaks nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
293 (setq ccl-current-ic 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
294
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
295 ;; The first element is the buffer magnification.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
296 (ccl-embed-data (car ccl-program))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
297
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
298 ;; The second element is the address of the start CCL code for
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
299 ;; processing end of input buffer (we call it eof-processor). We
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
300 ;; set it later.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
301 (ccl-increment-ic 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
302
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
303 ;; Compile the main body of the CCL program.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
304 (ccl-compile-1 (car (cdr ccl-program)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
305
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
306 ;; Embed the address of eof-processor.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
307 (ccl-embed-data ccl-current-ic 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
308
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
309 ;; Then compile eof-processor.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
310 (if (nth 2 ccl-program)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
311 (ccl-compile-1 (nth 2 ccl-program)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
312
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
313 ;; At last, embed termination code.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
314 (ccl-embed-code 'end 0 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
315
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
316 (let ((vec (make-vector ccl-current-ic 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
317 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
318 (while (< i ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
319 (aset vec i (aref ccl-program-vector i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
320 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
321 vec))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
322
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
323 ;; Signal syntax error.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
324 (defun ccl-syntax-error (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
325 (error "CCL: Syntax error: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
326
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
327 ;; Check if ARG is a valid CCL register.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
328 (defun ccl-check-register (arg cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
329 (if (get arg 'ccl-register-number)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
330 arg
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
331 (error "CCL: Invalid register %s in %s." arg cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
332
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
333 ;; Check if ARG is a valid CCL command.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
334 (defun ccl-check-compile-function (arg cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
335 (or (get arg 'ccl-compile-function)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
336 (error "CCL: Invalid command: %s" cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
337
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
338 ;; In the following code, most ccl-compile-XXXX functions return t if
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
339 ;; they end with unconditional jump, else return nil.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
340
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
341 ;; Compile CCL-BLOCK (see the syntax above).
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
342 (defun ccl-compile-1 (ccl-block)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
343 (let (unconditional-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
344 cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
345 (if (or (integer-or-char-p ccl-block)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
346 (stringp ccl-block)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
347 (and ccl-block (symbolp (car ccl-block))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
348 ;; This block consists of single statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
349 (setq ccl-block (list ccl-block)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
350
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
351 ;; Now CCL-BLOCK is a list of statements. Compile them one by
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
352 ;; one.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
353 (while ccl-block
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
354 (setq cmd (car ccl-block))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
355 (setq unconditional-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
356 (cond ((integer-or-char-p cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
357 ;; SET statement for the register 0.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
358 (ccl-compile-set (list 'r0 '= cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
359
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
360 ((stringp cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
361 ;; WRITE statement of string argument.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
362 (ccl-compile-write-string cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
363
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
364 ((listp cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
365 ;; The other statements.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
366 (cond ((eq (nth 1 cmd) '=)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
367 ;; SET statement of the form `(REG = EXPRESSION)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
368 (ccl-compile-set cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
369
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
370 ((and (symbolp (nth 1 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
371 (get (nth 1 cmd) 'ccl-self-arith-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
372 ;; SET statement with an assignment operation.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
373 (ccl-compile-self-set cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
374
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
375 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
376 (funcall (ccl-check-compile-function (car cmd) cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
377 cmd))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
378
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
379 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
380 (ccl-syntax-error cmd))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
381 (setq ccl-block (cdr ccl-block)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
382 unconditional-jump))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
383
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
384 (defconst ccl-max-short-const (ash 1 19))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
385 (defconst ccl-min-short-const (ash -1 19))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
386
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
387 ;; Compile SET statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
388 (defun ccl-compile-set (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
389 (let ((rrr (ccl-check-register (car cmd) cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
390 (right (nth 2 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
391 (cond ((listp right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
392 ;; CMD has the form `(RRR = (XXX OP YYY))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
393 (ccl-compile-expression rrr right))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
394
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
395 ((integer-or-char-p right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
396 ;; CMD has the form `(RRR = integer)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
397 (if (and (<= right ccl-max-short-const)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
398 (>= right ccl-min-short-const))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
399 (ccl-embed-code 'set-short-const rrr right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
400 (ccl-embed-code 'set-const rrr 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
401 (ccl-embed-data right)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
402
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
403 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
404 ;; CMD has the form `(RRR = rrr [ array ])'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
405 (ccl-check-register right cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
406 (let ((ary (nth 3 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
407 (if (vectorp ary)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
408 (let ((i 0) (len (length ary)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
409 (ccl-embed-code 'set-array rrr len right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
410 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
411 (ccl-embed-data (aref ary i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
412 (setq i (1+ i))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
413 (ccl-embed-code 'set-register rrr 0 right))))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
414 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
415
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
416 ;; Compile SET statement with ASSIGNMENT_OPERATOR.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
417 (defun ccl-compile-self-set (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
418 (let ((rrr (ccl-check-register (car cmd) cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
419 (right (nth 2 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
420 (if (listp right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
421 ;; CMD has the form `(RRR ASSIGN_OP (XXX OP YYY))', compile
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
422 ;; the right hand part as `(r7 = (XXX OP YYY))' (note: the
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
423 ;; register 7 can be used for storing temporary value).
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
424 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
425 (ccl-compile-expression 'r7 right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
426 (setq right 'r7)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
427 ;; Now CMD has the form `(RRR ASSIGN_OP ARG)'. Compile it as
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
428 ;; `(RRR = (RRR OP ARG))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
429 (ccl-compile-expression
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
430 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
431 (list rrr (intern (substring (symbol-name (nth 1 cmd)) 0 -1)) right)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
432 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
433
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
434 ;; Compile SET statement of the form `(RRR = EXPR)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
435 (defun ccl-compile-expression (rrr expr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
436 (let ((left (car expr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
437 (op (get (nth 1 expr) 'ccl-arith-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
438 (right (nth 2 expr)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
439 (if (listp left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
440 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
441 ;; EXPR has the form `((EXPR2 OP2 ARG) OP RIGHT)'. Compile
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
442 ;; the first term as `(r7 = (EXPR2 OP2 ARG)).'
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
443 (ccl-compile-expression 'r7 left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
444 (setq left 'r7)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
445
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
446 ;; Now EXPR has the form (LEFT OP RIGHT).
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
447 (if (eq rrr left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
448 ;; Compile this SET statement as `(RRR OP= RIGHT)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
449 (if (integer-or-char-p right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
450 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
451 (ccl-embed-code 'set-assign-expr-const rrr (ash op 3) 'r0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
452 (ccl-embed-data right))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
453 (ccl-check-register right expr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
454 (ccl-embed-code 'set-assign-expr-register rrr (ash op 3) right))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
455
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
456 ;; Compile this SET statement as `(RRR = (LEFT OP RIGHT))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
457 (if (integer-or-char-p right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
458 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
459 (ccl-embed-code 'set-expr-const rrr (ash op 3) left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
460 (ccl-embed-data right))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
461 (ccl-check-register right expr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
462 (ccl-embed-code 'set-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
463 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
464 (logior (ash op 3) (get right 'ccl-register-number))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
465 left)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
466
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
467 ;; Compile WRITE statement with string argument.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
468 (defun ccl-compile-write-string (str)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
469 (let ((len (length str)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
470 (ccl-embed-code 'write-const-string 1 len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
471 (ccl-embed-string len str))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
472 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
473
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
474 ;; Compile IF statement of the form `(if CONDITION TRUE-PART FALSE-PART)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
475 ;; If READ-FLAG is non-nil, this statement has the form
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
476 ;; `(read-if (REG OPERATOR ARG) TRUE-PART FALSE-PART)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
477 (defun ccl-compile-if (cmd &optional read-flag)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
478 (if (and (/= (length cmd) 3) (/= (length cmd) 4))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
479 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
480 (let ((condition (nth 1 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
481 (true-cmds (nth 2 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
482 (false-cmds (nth 3 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
483 jump-cond-address
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
484 false-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
485 (if (and (listp condition)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
486 (listp (car condition)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
487 ;; If CONDITION is a nested expression, the inner expression
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
488 ;; should be compiled at first as SET statement, i.e.:
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
489 ;; `(if ((X OP2 Y) OP Z) ...)' is compiled into two statements:
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
490 ;; `(r7 = (X OP2 Y)) (if (r7 OP Z) ...)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
491 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
492 (ccl-compile-expression 'r7 (car condition))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
493 (setq condition (cons 'r7 (cdr condition)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
494 (setq cmd (cons (car cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
495 (cons condition (cdr (cdr cmd)))))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
496
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
497 (setq jump-cond-address ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
498 ;; Compile CONDITION.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
499 (if (symbolp condition)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
500 ;; CONDITION is a register.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
501 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
502 (ccl-check-register condition cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
503 (ccl-embed-code 'jump-cond condition 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
504 ;; CONDITION is a simple expression of the form (RRR OP ARG).
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
505 (let ((rrr (car condition))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
506 (op (get (nth 1 condition) 'ccl-arith-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
507 (arg (nth 2 condition)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
508 (ccl-check-register rrr cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
509 (if (integer-or-char-p arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
510 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
511 (ccl-embed-code (if read-flag 'read-jump-cond-expr-const
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
512 'jump-cond-expr-const)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
513 rrr 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
514 (ccl-embed-data op)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
515 (ccl-embed-data arg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
516 (ccl-check-register arg cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
517 (ccl-embed-code (if read-flag 'read-jump-cond-expr-register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
518 'jump-cond-expr-register)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
519 rrr 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
520 (ccl-embed-data op)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
521 (ccl-embed-data (get arg 'ccl-register-number)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
522
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
523 ;; Compile TRUE-PART.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
524 (let ((unconditional-jump (ccl-compile-1 true-cmds)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
525 (if (null false-cmds)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
526 ;; This is the place to jump to if condition is false.
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
527 (ccl-embed-current-address jump-cond-address)
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
528 (let (end-true-part-address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
529 (if (not unconditional-jump)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
530 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
531 ;; If TRUE-PART does not end with unconditional jump, we
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
532 ;; have to jump to the end of FALSE-PART from here.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
533 (setq end-true-part-address ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
534 (ccl-embed-code 'jump 0 0)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
535 ;; This is the place to jump to if CONDITION is false.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
536 (ccl-embed-current-address jump-cond-address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
537 ;; Compile FALSE-PART.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
538 (setq unconditional-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
539 (and (ccl-compile-1 false-cmds) unconditional-jump))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
540 (if end-true-part-address
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
541 ;; This is the place to jump to after the end of TRUE-PART.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
542 (ccl-embed-current-address end-true-part-address))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
543 unconditional-jump)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
544
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
545 ;; Compile BRANCH statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
546 (defun ccl-compile-branch (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
547 (if (< (length cmd) 3)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
548 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
549 (ccl-compile-branch-blocks 'branch
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
550 (ccl-compile-branch-expression (nth 1 cmd) cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
551 (cdr (cdr cmd))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
552
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
553 ;; Compile READ statement of the form `(read-branch EXPR BLOCK0 BLOCK1 ...)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
554 (defun ccl-compile-read-branch (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
555 (if (< (length cmd) 3)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
556 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
557 (ccl-compile-branch-blocks 'read-branch
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
558 (ccl-compile-branch-expression (nth 1 cmd) cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
559 (cdr (cdr cmd))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
560
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
561 ;; Compile EXPRESSION part of BRANCH statement and return register
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
562 ;; which holds a value of the expression.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
563 (defun ccl-compile-branch-expression (expr cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
564 (if (listp expr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
565 ;; EXPR has the form `(EXPR2 OP ARG)'. Compile it as SET
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
566 ;; statement of the form `(r7 = (EXPR2 OP ARG))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
567 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
568 (ccl-compile-expression 'r7 expr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
569 'r7)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
570 (ccl-check-register expr cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
571
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
572 ;; Compile BLOCKs of BRANCH statement. CODE is 'branch or 'read-branch.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
573 ;; REG is a register which holds a value of EXPRESSION part. BLOCKs
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
574 ;; is a list of CCL-BLOCKs.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
575 (defun ccl-compile-branch-blocks (code rrr blocks)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
576 (let ((branches (length blocks))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
577 branch-idx
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
578 jump-table-head-address
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
579 empty-block-indexes
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
580 block-tail-addresses
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
581 block-unconditional-jump)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
582 (ccl-embed-code code rrr branches)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
583 (setq jump-table-head-address ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
584 ;; The size of jump table is the number of blocks plus 1 (for the
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
585 ;; case RRR is out of range).
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
586 (ccl-increment-ic (1+ branches))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
587 (setq empty-block-indexes (list branches))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
588 ;; Compile each block.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
589 (setq branch-idx 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
590 (while blocks
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
591 (if (null (car blocks))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
592 ;; This block is empty.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
593 (setq empty-block-indexes (cons branch-idx empty-block-indexes)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
594 block-unconditional-jump t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
595 ;; This block is not empty.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
596 (ccl-embed-data (- ccl-current-ic jump-table-head-address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
597 (+ jump-table-head-address branch-idx))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
598 (setq block-unconditional-jump (ccl-compile-1 (car blocks)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
599 (if (not block-unconditional-jump)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
600 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
601 ;; Jump address of the end of branches are embedded later.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
602 ;; For the moment, just remember where to embed them.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
603 (setq block-tail-addresses
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
604 (cons ccl-current-ic block-tail-addresses))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
605 (ccl-embed-code 'jump 0 0))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
606 (setq branch-idx (1+ branch-idx))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
607 (setq blocks (cdr blocks)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
608 (if (not block-unconditional-jump)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
609 ;; We don't need jump code at the end of the last block.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
610 (setq block-tail-addresses (cdr block-tail-addresses)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
611 ccl-current-ic (1- ccl-current-ic)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
612 ;; Embed jump address at the tailing jump commands of blocks.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
613 (while block-tail-addresses
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
614 (ccl-embed-current-address (car block-tail-addresses))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
615 (setq block-tail-addresses (cdr block-tail-addresses)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
616 ;; For empty blocks, make entries in the jump table point directly here.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
617 (while empty-block-indexes
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
618 (ccl-embed-data (- ccl-current-ic jump-table-head-address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
619 (+ jump-table-head-address (car empty-block-indexes)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
620 (setq empty-block-indexes (cdr empty-block-indexes))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
621 ;; Branch command ends by unconditional jump if RRR is out of range.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
622 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
623
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
624 ;; Compile LOOP statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
625 (defun ccl-compile-loop (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
626 (if (< (length cmd) 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
627 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
628 (let* ((ccl-loop-head ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
629 (ccl-breaks nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
630 unconditional-jump)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
631 (setq cmd (cdr cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
632 (if cmd
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
633 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
634 (setq unconditional-jump t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
635 (while cmd
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
636 (setq unconditional-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
637 (and (ccl-compile-1 (car cmd)) unconditional-jump))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
638 (setq cmd (cdr cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
639 (if (not ccl-breaks)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
640 unconditional-jump
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
641 ;; Embed jump address for break statements encountered in
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
642 ;; this loop.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
643 (while ccl-breaks
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
644 (ccl-embed-current-address (car ccl-breaks))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
645 (setq ccl-breaks (cdr ccl-breaks))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
646 nil))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
647
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
648 ;; Compile BREAK statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
649 (defun ccl-compile-break (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
650 (if (/= (length cmd) 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
651 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
652 (if (null ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
653 (error "CCL: No outer loop: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
654 (setq ccl-breaks (cons ccl-current-ic ccl-breaks))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
655 (ccl-embed-code 'jump 0 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
656 t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
657
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
658 ;; Compile REPEAT statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
659 (defun ccl-compile-repeat (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
660 (if (/= (length cmd) 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
661 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
662 (if (null ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
663 (error "CCL: No outer loop: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
664 (ccl-embed-code 'jump 0 ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
665 t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
666
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
667 ;; Compile WRITE-REPEAT statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
668 (defun ccl-compile-write-repeat (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
669 (if (/= (length cmd) 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
670 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
671 (if (null ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
672 (error "CCL: No outer loop: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
673 (let ((arg (nth 1 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
674 (cond ((integer-or-char-p arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
675 (ccl-embed-code 'write-const-jump 0 ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
676 (ccl-embed-data arg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
677 ((stringp arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
678 (let ((len (length arg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
679 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
680 (ccl-embed-code 'write-string-jump 0 ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
681 (ccl-embed-data len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
682 (ccl-embed-string len arg)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
683 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
684 (ccl-check-register arg cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
685 (ccl-embed-code 'write-register-jump arg ccl-loop-head))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
686 t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
687
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
688 ;; Compile WRITE-READ-REPEAT statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
689 (defun ccl-compile-write-read-repeat (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
690 (if (or (< (length cmd) 2) (> (length cmd) 3))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
691 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
692 (if (null ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
693 (error "CCL: No outer loop: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
694 (let ((rrr (ccl-check-register (nth 1 cmd) cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
695 (arg (nth 2 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
696 (cond ((null arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
697 (ccl-embed-code 'write-register-read-jump rrr ccl-loop-head))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
698 ((integer-or-char-p arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
699 (ccl-embed-code 'write-const-read-jump rrr arg ccl-loop-head))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
700 ((vectorp arg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
701 (let ((len (length arg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
702 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
703 (ccl-embed-code 'write-array-read-jump rrr ccl-loop-head)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
704 (ccl-embed-data len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
705 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
706 (ccl-embed-data (aref arg i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
707 (setq i (1+ i)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
708 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
709 (error "CCL: Invalid argument %s: %s" arg cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
710 (ccl-embed-code 'read-jump rrr ccl-loop-head))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
711 t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
712
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
713 ;; Compile READ statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
714 (defun ccl-compile-read (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
715 (if (< (length cmd) 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
716 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
717 (let* ((args (cdr cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
718 (i (1- (length args))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
719 (while args
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
720 (let ((rrr (ccl-check-register (car args) cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
721 (ccl-embed-code 'read-register rrr i)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
722 (setq args (cdr args) i (1- i)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
723 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
724
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
725 ;; Compile READ-IF statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
726 (defun ccl-compile-read-if (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
727 (ccl-compile-if cmd 'read))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
728
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
729 ;; Compile WRITE statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
730 (defun ccl-compile-write (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
731 (if (< (length cmd) 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
732 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
733 (let ((rrr (nth 1 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
734 (cond ((integer-or-char-p rrr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
735 (ccl-embed-code 'write-const-string 0 rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
736 ((stringp rrr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
737 (ccl-compile-write-string rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
738 ((and (symbolp rrr) (vectorp (nth 2 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
739 (ccl-check-register rrr cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
740 ;; CMD has the form `(write REG ARRAY)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
741 (let* ((arg (nth 2 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
742 (len (length arg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
743 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
744 (ccl-embed-code 'write-array rrr len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
745 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
746 (if (not (integer-or-char-p (aref arg i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
747 (error "CCL: Invalid argument %s: %s" arg cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
748 (ccl-embed-data (aref arg i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
749 (setq i (1+ i)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
750
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
751 ((symbolp rrr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
752 ;; CMD has the form `(write REG ...)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
753 (let* ((args (cdr cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
754 (i (1- (length args))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
755 (while args
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
756 (setq rrr (ccl-check-register (car args) cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
757 (ccl-embed-code 'write-register rrr i)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
758 (setq args (cdr args) i (1- i)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
759
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
760 ((listp rrr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
761 ;; CMD has the form `(write (LEFT OP RIGHT))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
762 (let ((left (car rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
763 (op (get (nth 1 rrr) 'ccl-arith-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
764 (right (nth 2 rrr)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
765 (if (listp left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
766 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
767 ;; RRR has the form `((EXPR OP2 ARG) OP RIGHT)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
768 ;; Compile the first term as `(r7 = (EXPR OP2 ARG))'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
769 (ccl-compile-expression 'r7 left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
770 (setq left 'r7)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
771 ;; Now RRR has the form `(ARG OP RIGHT)'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
772 (if (integer-or-char-p right)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
773 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
774 (ccl-embed-code 'write-expr-const 0 (ash op 3) left)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
775 (ccl-embed-data right))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
776 (ccl-check-register right rrr)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
777 (ccl-embed-code 'write-expr-register 0
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
778 (logior (ash op 3)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
779 (get right 'ccl-register-number))))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
780
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
781 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
782 (error "CCL: Invalid argument: %s" cmd))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
783 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
784
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
785 ;; Compile CALL statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
786 (defun ccl-compile-call (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
787 (if (/= (length cmd) 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
788 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
789 (if (not (symbolp (nth 1 cmd)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
790 (error "CCL: Subroutine should be a symbol: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
791 (let* ((name (nth 1 cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
792 (idx (get name 'ccl-program-idx)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
793 (if (not idx)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
794 (error "CCL: Unknown subroutine name: %s" name))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
795 (ccl-embed-code 'call 0 idx))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
796 nil)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
797
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
798 ;; Compile END statement.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
799 (defun ccl-compile-end (cmd)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
800 (if (/= (length cmd) 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
801 (error "CCL: Invalid number of arguments: %s" cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
802 (ccl-embed-code 'end 0 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
803 t)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
804
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
805 ;;; CCL dump staffs
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
806
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
807 ;; To avoid byte-compiler warning.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
808 (defvar ccl-code)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
809
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
810 ;;;###autoload
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
811 (defun ccl-dump (ccl-code)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
812 "Disassemble compiled CCL-CODE."
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
813 (let ((len (length ccl-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
814 (buffer-mag (aref ccl-code 0)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
815 (cond ((= buffer-mag 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
816 (insert "Don't output anything.\n"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
817 ((= buffer-mag 1)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
818 (insert "Out-buffer must be as large as in-buffer.\n"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
819 (t
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
820 (insert
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
821 (format "Out-buffer must be %d times bigger than in-buffer.\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
822 buffer-mag))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
823 (insert "Main-body:\n")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
824 (setq ccl-current-ic 2)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
825 (if (> (aref ccl-code 1) 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
826 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
827 (while (< ccl-current-ic (aref ccl-code 1))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
828 (ccl-dump-1))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
829 (insert "At EOF:\n")))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
830 (while (< ccl-current-ic len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
831 (ccl-dump-1))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
832 ))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
833
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
834 ;; Return a CCL code in `ccl-code' at `ccl-current-ic'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
835 (defun ccl-get-next-code ()
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
836 (prog1
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
837 (aref ccl-code ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
838 (setq ccl-current-ic (1+ ccl-current-ic))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
839
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
840 (defun ccl-dump-1 ()
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
841 (let* ((code (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
842 (cmd (aref ccl-code-table (logand code 31)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
843 (rrr (ash (logand code 255) -5))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
844 (cc (ash code -8)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
845 (insert (format "%5d:[%s] " (1- ccl-current-ic) cmd))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
846 (funcall (get cmd 'ccl-dump-function) rrr cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
847
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
848 (defun ccl-dump-set-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
849 (insert (format "r%d = r%d\n" rrr cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
850
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
851 (defun ccl-dump-set-short-const (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
852 (insert (format "r%d = %d\n" rrr cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
853
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
854 (defun ccl-dump-set-const (rrr ignore)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
855 (insert (format "r%d = %d\n" rrr (ccl-get-next-code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
856
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
857 (defun ccl-dump-set-array (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
858 (let ((rrr2 (logand cc 7))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
859 (len (ash cc -3))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
860 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
861 (insert (format "r%d = array[r%d] of length %d\n\t"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
862 rrr rrr2 len))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
863 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
864 (insert (format "%d " (ccl-get-next-code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
865 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
866 (insert "\n")))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
867
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
868 (defun ccl-dump-jump (ignore cc &optional address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
869 (insert (format "jump to %d(" (+ (or address ccl-current-ic) cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
870 (if (>= cc 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
871 (insert "+"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
872 (insert (format "%d)\n" (1+ cc))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
873
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
874 (defun ccl-dump-jump-cond (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
875 (insert (format "if (r%d == 0), " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
876 (ccl-dump-jump nil cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
877
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
878 (defun ccl-dump-write-register-jump (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
879 (insert (format "write r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
880 (ccl-dump-jump nil cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
881
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
882 (defun ccl-dump-write-register-read-jump (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
883 (insert (format "write r%d, read r%d, " rrr rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
884 (ccl-dump-jump nil cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
885 (ccl-get-next-code) ; Skip dummy READ-JUMP
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
886 )
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
887
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
888 (defun ccl-extract-arith-op (cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
889 (aref ccl-arith-table (ash cc -6)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
890
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
891 (defun ccl-dump-write-expr-const (ignore cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
892 (insert (format "write (r%d %s %d)\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
893 (logand cc 7)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
894 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
895 (ccl-get-next-code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
896
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
897 (defun ccl-dump-write-expr-register (ignore cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
898 (insert (format "write (r%d %s r%d)\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
899 (logand cc 7)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
900 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
901 (logand (ash cc -3) 7))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
902
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
903 (defun ccl-dump-insert-char (cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
904 (cond ((= cc ?\t) (insert " \"^I\""))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
905 ((= cc ?\n) (insert " \"^J\""))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
906 (t (insert (format " \"%c\"" cc)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
907
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
908 (defun ccl-dump-write-const-jump (ignore cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
909 (let ((address ccl-current-ic))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
910 (insert "write char")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
911 (ccl-dump-insert-char (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
912 (insert ", ")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
913 (ccl-dump-jump nil cc address)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
914
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
915 (defun ccl-dump-write-const-read-jump (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
916 (let ((address ccl-current-ic))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
917 (insert "write char")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
918 (ccl-dump-insert-char (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
919 (insert (format ", read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
920 (ccl-dump-jump cc address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
921 (ccl-get-next-code) ; Skip dummy READ-JUMP
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
922 ))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
923
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
924 (defun ccl-dump-write-string-jump (ignore cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
925 (let ((address ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
926 (len (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
927 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
928 (insert "write \"")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
929 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
930 (let ((code (ccl-get-next-code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
931 (insert (ash code -16))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
932 (if (< (1+ i) len) (insert (logand (ash code -8) 255)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
933 (if (< (+ i 2) len) (insert (logand code 255))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
934 (setq i (+ i 3)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
935 (insert "\", ")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
936 (ccl-dump-jump nil cc address)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
937
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
938 (defun ccl-dump-write-array-read-jump (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
939 (let ((address ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
940 (len (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
941 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
942 (insert (format "write array[r%d] of length %d,\n\t" rrr len))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
943 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
944 (ccl-dump-insert-char (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
945 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
946 (insert (format "\n\tthen read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
947 (ccl-dump-jump nil cc address)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
948 (ccl-get-next-code) ; Skip dummy READ-JUMP.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
949 ))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
950
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
951 (defun ccl-dump-read-jump (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
952 (insert (format "read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
953 (ccl-dump-jump nil cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
954
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
955 (defun ccl-dump-branch (rrr len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
956 (let ((jump-table-head ccl-current-ic)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
957 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
958 (insert (format "jump to array[r%d] of length %d\n\t" rrr len))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
959 (while (<= i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
960 (insert (format "%d " (+ jump-table-head (ccl-get-next-code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
961 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
962 (insert "\n")))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
963
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
964 (defun ccl-dump-read-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
965 (insert (format "read r%d (%d remaining)\n" rrr cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
966
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
967 (defun ccl-dump-read-branch (rrr len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
968 (insert (format "read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
969 (ccl-dump-branch rrr len))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
970
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
971 (defun ccl-dump-write-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
972 (insert (format "write r%d (%d remaining)\n" rrr cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
973
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
974 (defun ccl-dump-call (ignore cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
975 (insert (format "call subroutine #%d\n" cc)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
976
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
977 (defun ccl-dump-write-const-string (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
978 (if (= rrr 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
979 (progn
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
980 (insert "write char")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
981 (ccl-dump-insert-char cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
982 (newline))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
983 (let ((len cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
984 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
985 (insert "write \"")
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
986 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
987 (let ((code (ccl-get-next-code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
988 (insert (format "%c" (lsh code -16)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
989 (if (< (1+ i) len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
990 (insert (format "%c" (logand (lsh code -8) 255))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
991 (if (< (+ i 2) len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
992 (insert (format "%c" (logand code 255))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
993 (setq i (+ i 3))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
994 (insert "\"\n"))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
995
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
996 (defun ccl-dump-write-array (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
997 (let ((i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
998 (insert (format "write array[r%d] of length %d\n\t" rrr cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
999 (while (< i cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1000 (ccl-dump-insert-char (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1001 (setq i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1002 (insert "\n")))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1003
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1004 (defun ccl-dump-end (&rest ignore)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1005 (insert "end\n"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1006
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1007 (defun ccl-dump-set-assign-expr-const (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1008 (insert (format "r%d %s= %d\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1009 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1010 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1011 (ccl-get-next-code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1012
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1013 (defun ccl-dump-set-assign-expr-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1014 (insert (format "r%d %s= r%d\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1015 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1016 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1017 (logand cc 7))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1018
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1019 (defun ccl-dump-set-expr-const (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1020 (insert (format "r%d = r%d %s %d\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1021 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1022 (logand cc 7)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1023 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1024 (ccl-get-next-code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1025
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1026 (defun ccl-dump-set-expr-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1027 (insert (format "r%d = r%d %s r%d\n"
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1028 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1029 (logand cc 7)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1030 (ccl-extract-arith-op cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1031 (logand (ash cc -3) 7))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1032
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1033 (defun ccl-dump-jump-cond-expr-const (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1034 (let ((address ccl-current-ic))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1035 (insert (format "if !(r%d %s %d), "
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1036 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1037 (aref ccl-arith-table (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1038 (ccl-get-next-code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1039 (ccl-dump-jump nil cc address)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1040
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1041 (defun ccl-dump-jump-cond-expr-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1042 (let ((address ccl-current-ic))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1043 (insert (format "if !(r%d %s r%d), "
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1044 rrr
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1045 (aref ccl-arith-table (ccl-get-next-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1046 (ccl-get-next-code)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1047 (ccl-dump-jump nil cc address)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1048
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1049 (defun ccl-dump-read-jump-cond-expr-const (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1050 (insert (format "read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1051 (ccl-dump-jump-cond-expr-const rrr cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1052
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1053 (defun ccl-dump-read-jump-cond-expr-register (rrr cc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1054 (insert (format "read r%d, " rrr))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1055 (ccl-dump-jump-cond-expr-register rrr cc))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1056
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1057 (defun ccl-dump-binary (ccl-code)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1058 (let ((len (length ccl-code))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1059 (i 2))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1060 (while (< i len)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1061 (let ((code (aref ccl-code i))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1062 (j 27))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1063 (while (>= j 0)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1064 (insert (if (= (logand code (ash 1 j)) 0) ?0 ?1))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1065 (setq j (1- j)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1066 (setq code (logand code 31))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1067 (if (< code (length ccl-code-table))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1068 (insert (format ":%s" (aref ccl-code-table code))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1069 (insert "\n"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1070 (setq i (1+ i)))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1071
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1072 ;; CCL emulation staffs
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1073
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1074 ;; Not yet implemented.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1075
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1076 ;;;###autoload
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
1077 (defmacro declare-ccl-program (name)
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1078 "Declare NAME as a name of CCL program.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1079
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1080 To compile a CCL program which calls another CCL program not yet
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
1081 defined, it must be declared as a CCL program in advance."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
1082 `(put ',name 'ccl-program-idx (register-ccl-program ',name nil)))
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1083
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1084 ;;;###autoload
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1085 (defmacro define-ccl-program (name ccl-program &optional doc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1086 "Set NAME the compiled code of CCL-PROGRAM.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1087 CCL-PROGRAM is `eval'ed before being handed to the CCL compiler `ccl-compile'.
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1088 The compiled code is a vector of integers."
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1089 `(let ((prog ,(ccl-compile (eval ccl-program))))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1090 (defconst ,name prog ,doc)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1091 (put ',name 'ccl-program-idx (register-ccl-program ',name prog))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1092 nil))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1093
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1094 ;;;###autoload
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1095 (defun ccl-execute-with-args (ccl-prog &rest args)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1096 "Execute CCL-PROGRAM with registers initialized by the remaining args.
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
1097 The return value is a vector of resulting CCL registeres."
333
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1098 (let ((reg (make-vector 8 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1099 (i 0))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1100 (while (and args (< i 8))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1101 (if (not (integerp (car args)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1102 (error "Arguments should be integer"))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1103 (aset reg i (car args))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1104 (setq args (cdr args) i (1+ i)))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1105 (ccl-execute ccl-prog reg)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1106 reg))
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1107
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1108 (provide 'ccl)
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1109
4f79e16b1112 Import from CVS: tag r21-0-64
cvs
parents:
diff changeset
1110 ;; ccl.el ends here