annotate src/mule-ccl.c @ 161:28f395d8dc7a r20-3b7

Import from CVS: tag r20-3b7
author cvs
date Mon, 13 Aug 2007 09:42:26 +0200
parents 538048ae2ab8
children 8eaf7971accc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 /* CCL -- Code Conversion Language Interpreter
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 #include <config.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25 #include "lisp.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27 #include "buffer.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28 #include "mule-coding.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 /* CCL operators */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 #define CCL_SetCS 0x00
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32 #define CCL_SetCL 0x01
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 #define CCL_SetR 0x02
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 #define CCL_SetA 0x03
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35 #define CCL_Jump 0x04
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 #define CCL_JumpCond 0x05
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 #define CCL_WriteJump 0x06
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 #define CCL_WriteReadJump 0x07
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 #define CCL_WriteCJump 0x08
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 #define CCL_WriteCReadJump 0x09
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 #define CCL_WriteSJump 0x0A
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 #define CCL_WriteSReadJump 0x0B
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 #define CCL_WriteAReadJump 0x0C
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 #define CCL_Branch 0x0D
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 #define CCL_Read1 0x0E
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46 #define CCL_Read2 0x0F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 #define CCL_ReadBranch 0x10
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 #define CCL_Write1 0x11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 #define CCL_Write2 0x12
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 #define CCL_WriteC 0x13
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 #define CCL_WriteS 0x14
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 #define CCL_WriteA 0x15
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53 #define CCL_End 0x16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 #define CCL_SetSelfCS 0x17
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 #define CCL_SetSelfCL 0x18
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 #define CCL_SetSelfR 0x19
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 #define CCL_SetExprCL 0x1A
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58 #define CCL_SetExprR 0x1B
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 #define CCL_JumpCondC 0x1C
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 #define CCL_JumpCondR 0x1D
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 #define CCL_ReadJumpCondC 0x1E
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 #define CCL_ReadJumpCondR 0x1F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64 #define CCL_PLUS 0x00
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 #define CCL_MINUS 0x01
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 #define CCL_MUL 0x02
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 #define CCL_DIV 0x03
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 #define CCL_MOD 0x04
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 #define CCL_AND 0x05
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70 #define CCL_OR 0x06
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 #define CCL_XOR 0x07
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 #define CCL_LSH 0x08
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73 #define CCL_RSH 0x09
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74 #define CCL_LSH8 0x0A
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 #define CCL_RSH8 0x0B
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 #define CCL_DIVMOD 0x0C
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 #define CCL_LS 0x10
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78 #define CCL_GT 0x11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 #define CCL_EQ 0x12
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 #define CCL_LE 0x13
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 #define CCL_GE 0x14
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 #define CCL_NE 0x15
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 /* Header of CCL compiled code */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 #define CCL_HEADER_EOF 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 #define CCL_HEADER_MAIN 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 #define CCL_STAT_SUCCESS 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 #define CCL_STAT_SUSPEND 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 #define CCL_STAT_INVALID_CMD 2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 #define CCL_SUCCESS \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 ccl->status = CCL_STAT_SUCCESS; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 goto ccl_finish
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 #define CCL_SUSPEND \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 ccl->ic = --ic; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 ccl->status = CCL_STAT_SUSPEND; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 goto ccl_finish
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 #define CCL_INVALID_CMD \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 ccl->status = CCL_STAT_INVALID_CMD; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 goto ccl_error_handler
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 #define CCL_WRITE_CHAR(ch) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 if (!src) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 CCL_INVALID_CMD; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 /* !!#### is this correct for both directions????? */ \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 Bufbyte __buf__[MAX_EMCHAR_LEN]; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 int __len__; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 __len__ = set_charptr_emchar (__buf__, ch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 Dynarr_add_many (dst, __buf__, __len__); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 #define CCL_WRITE_STRING(len) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121 if (!src) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 CCL_INVALID_CMD; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 for (j = 0; j < len; j++) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 Dynarr_add (dst, XINT (prog[ic + 1 + j])); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 #define CCL_READ_CHAR(r) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 if (!src) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 CCL_INVALID_CMD; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 else if (s < s_end) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139 r = *s++; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
140 else if (end_flag) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 ic = XINT (prog[CCL_HEADER_EOF]); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 continue; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147 CCL_SUSPEND; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152 /* Run a CCL program. The initial state and program are contained in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 CCL. SRC, if non-zero, specifies a source string (of size N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 to read bytes from, and DST, of non-zero, specifies a destination
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155 Dynarr to write bytes to. If END_FLAG is set, it means that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156 the end section of the CCL program should be run rather than
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157 the normal section.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 For CCL programs that do not involve code conversion (e.g.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 converting a single character into a font index), all parameters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 but the first will usually be 0. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 ccl_driver (struct ccl_program *ccl, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 unsigned_char_dynarr *dst, int n, int end_flag)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 int code, op, rrr, cc, i, j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 CONST unsigned char *s, *s_end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 int ic = ccl->ic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 int *reg = ccl->reg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 Lisp_Object *prog = ccl->prog;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 if (!ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 ic = CCL_HEADER_MAIN;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 if (src)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 s = src;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 s_end = s + n;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 code = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 op = code & 0x1F;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 rrr = (code >> 5) & 0x7;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 cc = code >> 8;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 switch (op)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 case CCL_SetCS:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 reg[rrr] = cc; continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 case CCL_SetCL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 reg[rrr] = XINT (prog[ic++]); continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 case CCL_SetR:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 reg[rrr] = reg[cc]; continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 case CCL_SetA:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 cc = reg[cc];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 i = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200 if (cc >= 0 && cc < i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 reg[rrr] = XINT (prog[ic + cc]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 ic += i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 case CCL_Jump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 ic = cc; continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 case CCL_JumpCond:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 if (!reg[rrr])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 case CCL_WriteJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 CCL_WRITE_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 case CCL_WriteReadJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 if (ccl->status != CCL_STAT_SUSPEND)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 CCL_WRITE_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 ccl->status = CCL_STAT_SUCCESS;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 case CCL_WriteCJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 CCL_WRITE_CHAR (XINT (prog[ic]));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 case CCL_WriteCReadJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 if (ccl->status != CCL_STAT_SUSPEND)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 CCL_WRITE_CHAR (XINT (prog[ic]));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 ccl->status = CCL_STAT_SUCCESS;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 case CCL_WriteSJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 i = XINT (prog[ic]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 CCL_WRITE_STRING (i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 case CCL_WriteSReadJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 if (ccl->status != CCL_STAT_SUSPEND)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 i = XINT (prog[ic]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 CCL_WRITE_STRING (i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 ccl->status = CCL_STAT_SUCCESS;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 case CCL_WriteAReadJump:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 if (ccl->status != CCL_STAT_SUSPEND)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 i = XINT (prog[ic]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 if (reg[rrr] >= 0 && reg[rrr] < i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 CCL_WRITE_CHAR (XINT (prog[ic + 1 + reg[rrr]]));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 ccl->status = CCL_STAT_SUCCESS;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 case CCL_ReadBranch:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 case CCL_Branch:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 ic = XINT (prog[ic + (((unsigned int) reg[rrr] < cc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 ? reg[rrr] : cc)]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 case CCL_Read1:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 case CCL_Read2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277 CCL_READ_CHAR (reg[cc]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 case CCL_Write1:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 CCL_WRITE_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282 case CCL_Write2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 CCL_WRITE_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 CCL_WRITE_CHAR (reg[cc]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 case CCL_WriteC:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 i = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 CCL_WRITE_CHAR (i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 case CCL_WriteS:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 cc = XINT (prog[ic]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 CCL_WRITE_STRING (cc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 ic += cc + 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 case CCL_WriteA:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 i = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 cc = reg[rrr];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 if (cc >= 0 && cc < i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 CCL_WRITE_CHAR (XINT (prog[ic + cc]));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 ic += i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302 case CCL_End:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 CCL_SUCCESS;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 case CCL_SetSelfCS:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 i = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 goto ccl_set_self;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 case CCL_SetSelfCL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 i = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 goto ccl_set_self;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 case CCL_SetSelfR:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 i = reg[cc];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315 ccl_set_self:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
316 switch (op)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 case CCL_PLUS: reg[rrr] += i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 case CCL_MINUS: reg[rrr] -= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 case CCL_MUL: reg[rrr] *= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321 case CCL_DIV: reg[rrr] /= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
322 case CCL_MOD: reg[rrr] %= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
323 case CCL_AND: reg[rrr] &= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
324 case CCL_OR: reg[rrr] |= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325 case CCL_XOR: reg[rrr] ^= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
326 case CCL_LSH: reg[rrr] <<= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
327 case CCL_RSH: reg[rrr] >>= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
328 case CCL_LSH8: reg[rrr] <<= 8; reg[rrr] |= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
329 case CCL_RSH8: reg[7] = reg[rrr] & 0xFF; reg[rrr] >>= 8; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
330 case CCL_DIVMOD: reg[7] = reg[rrr] % i; reg[rrr] /= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
331 case CCL_LS: reg[rrr] = reg[rrr] < i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
332 case CCL_GT: reg[rrr] = reg[rrr] > i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333 case CCL_EQ: reg[rrr] = reg[rrr] == i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334 case CCL_LE: reg[rrr] = reg[rrr] <= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
335 case CCL_GE: reg[rrr] = reg[rrr] >= i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
336 case CCL_NE: reg[rrr] = reg[rrr] != i; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
337 default: CCL_INVALID_CMD;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
338 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
339 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
340 case CCL_SetExprCL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
341 i = reg[cc];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
342 j = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
343 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
344 cc = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
345 goto ccl_set_expr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
346 case CCL_SetExprR:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347 i = reg[cc];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
348 j = reg[XINT (prog[ic++])];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
349 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350 cc = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351 goto ccl_set_expr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352 case CCL_ReadJumpCondC:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
354 case CCL_JumpCondC:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
355 i = reg[rrr];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 j = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357 rrr = 7;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359 goto ccl_set_expr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 case CCL_ReadJumpCondR:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 CCL_READ_CHAR (reg[rrr]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
362 case CCL_JumpCondR:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 i = reg[rrr];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 j = reg[XINT (prog[ic++])];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 rrr = 7;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366 op = XINT (prog[ic++]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367 ccl_set_expr:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368 switch (op)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370 case CCL_PLUS: reg[rrr] = i + j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371 case CCL_MINUS: reg[rrr] = i - j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372 case CCL_MUL: reg[rrr] = i * j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373 case CCL_DIV: reg[rrr] = i / j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374 case CCL_MOD: reg[rrr] = i % j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375 case CCL_AND: reg[rrr] = i & j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376 case CCL_OR: reg[rrr] = i | j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 case CCL_XOR: reg[rrr] = i ^ j;; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 case CCL_LSH: reg[rrr] = i << j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 case CCL_RSH: reg[rrr] = i >> j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380 case CCL_LSH8: reg[rrr] = (i << 8) | j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381 case CCL_RSH8: reg[rrr] = i >> 8; reg[7] = i & 0xFF; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382 case CCL_DIVMOD: reg[rrr] = i / j; reg[7] = i % j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
383 case CCL_LS: reg[rrr] = i < j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
384 case CCL_GT: reg[rrr] = i > j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
385 case CCL_EQ: reg[rrr] = i == j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 case CCL_LE: reg[rrr] = i <= j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387 case CCL_GE: reg[rrr] = i >= j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
388 case CCL_NE: reg[rrr] = i != j; break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
389 default: CCL_INVALID_CMD;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391 if (cc && !reg[rrr])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392 ic = cc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 CCL_INVALID_CMD;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 ccl_error_handler:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400 if (dst)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402 char buf[200];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403 switch (ccl->status)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
405 case CCL_STAT_INVALID_CMD:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
406 sprintf (buf, "CCL: Invalid command (%x).\n", op);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
407 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
408 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
409 sprintf (buf, "CCL: Unknown error type (%d).\n", ccl->status);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
410 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
411 Dynarr_add_many (dst, (unsigned char *) buf, strlen (buf));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
412 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 ccl_finish:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415 ccl->ic = ic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416 if (dst)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417 return Dynarr_length (dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422 /* Set up CCL to execute CCL program VAL, with initial register values
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423 coming from REGS (NUMREGS of them are specified) and initial
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424 instruction counter coming from INITIAL_IC (a value of 0 means
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425 start at the beginning of the program, wherever that is).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429 set_ccl_program (struct ccl_program *ccl, Lisp_Object val, int *regs,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 int numregs, int initial_ic)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434 ccl->saved_vector = val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435 ccl->prog = XVECTOR (val)->contents;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 ccl->size = XVECTOR (val)->size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437 if (initial_ic == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438 ccl->ic = CCL_HEADER_MAIN;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440 ccl->ic = initial_ic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441 for (i = 0; i < numregs; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442 ccl->reg[i] = regs[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 for (; i < 8; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
444 ccl->reg[i] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
445 ccl->end_flag = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446 ccl->status = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
449 #ifdef emacs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
450
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
451 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
452 set_ccl_program_from_lisp_values (struct ccl_program *ccl,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
453 Lisp_Object prog,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454 Lisp_Object status)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457 int intregs[8];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458 int ic;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460 CHECK_VECTOR (prog);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 CHECK_VECTOR (status);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 if (vector_length (XVECTOR (status)) != 9)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464 signal_simple_error ("Must specify values for the eight registers and IC",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 status);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 for (i = 0; i < 8; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468 Lisp_Object regval = XVECTOR (status)->contents[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 if (NILP (regval))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470 intregs[i] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473 CHECK_INT (regval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474 intregs[i] = XINT (regval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 Lisp_Object lic = XVECTOR (status)->contents[8];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480 if (NILP (lic))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 ic = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
483 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 CHECK_NATNUM (lic);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485 ic = XINT (lic);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
487 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
488
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
489 set_ccl_program (ccl, prog, intregs, 8, ic);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
490 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
492 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
493 set_lisp_status_from_ccl_program (Lisp_Object status,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494 struct ccl_program *ccl)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498 for (i = 0; i < 8; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 XVECTOR (status)->contents[i] = make_int (ccl->reg[i]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500 XVECTOR (status)->contents[8] = make_int (ccl->ic);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 DEFUN ("execute-ccl-program", Fexecute_ccl_program, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 Execute CCL-PROGRAM with registers initialized by STATUS.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 CCL-PROGRAM is a vector of compiled CCL code created by `ccl-compile'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507 STATUS must be a vector of nine values, specifying the initial value
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
508 for the R0, R1 .. R7 registers and for the instruction counter IC.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
509 A nil value for a register initializer causes the register to be set
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
510 to 0. A nil value for the IC initializer causes execution to start
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511 at the beginning of the program.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
512 When the program is done, STATUS is modified (by side-effect) to contain
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513 the ending values for the corresponding registers and IC.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515 (ccl_program, status))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517 struct ccl_program ccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 set_ccl_program_from_lisp_values (&ccl, ccl_program, status);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520 ccl_driver (&ccl, 0, 0, 0, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521 set_lisp_status_from_ccl_program (status, &ccl);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525 DEFUN ("execute-ccl-program-string", Fexecute_ccl_program_string, 3, 3, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526 Execute CCL-PROGRAM with initial STATUS on STRING.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 CCL-PROGRAM is a vector of compiled CCL code created by `ccl-compile'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528 STATUS must be a vector of nine values, specifying the initial value
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529 for the R0, R1 .. R7 registers and for the instruction counter IC.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530 A nil value for a register initializer causes the register to be set
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 to 0. A nil value for the IC initializer causes execution to start
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532 at the beginning of the program.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533 When the program is done, STATUS is modified (by side-effect) to contain
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534 the ending values for the corresponding registers and IC.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 Returns the resulting string.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 (ccl_program, status, str))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539 struct ccl_program ccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 Lisp_Object val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541 int len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542 unsigned_char_dynarr *outbuf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544 set_ccl_program_from_lisp_values (&ccl, ccl_program, status);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545 CHECK_STRING (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547 outbuf = Dynarr_new (unsigned char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548 len = ccl_driver (&ccl, XSTRING_DATA (str), outbuf, XSTRING_LENGTH (str), 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549 ccl_driver (&ccl, (unsigned char *) "", outbuf, 0, 1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550 set_lisp_status_from_ccl_program (status, &ccl);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552 val = make_string (Dynarr_atp (outbuf, 0), len);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 Dynarr_free (outbuf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554 return val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557 DEFUN ("ccl-reset-elapsed-time", Fccl_reset_elapsed_time, 0, 0, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558 Reset the internal value which holds the time elapsed by CCL interpreter.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
560 ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562 error ("Not yet implemented; use `current-process-time'");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
565
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 DEFUN ("ccl-elapsed-time", Fccl_elapsed_time, 0, 0, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567 Return the time elapsed by CCL interpreter as cons of user and system time.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568 This measures processor time, not real time. Both values are floating point
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569 numbers measured in seconds. If only one overall value can be determined,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570 the return value will be a cons of that value and 0.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574 error ("Not yet implemented; use `current-process-time'");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
576 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579 syms_of_mule_ccl (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581 DEFSUBR (Fexecute_ccl_program);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 DEFSUBR (Fexecute_ccl_program_string);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583 DEFSUBR (Fccl_reset_elapsed_time);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 DEFSUBR (Fccl_elapsed_time);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
586
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
587 #else /* not emacs */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
588 #ifdef standalone
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
589
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
590 #define INBUF_SIZE 1024
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
591 #define MAX_CCL_CODE_SIZE 4096
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
592
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
593 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
594 main (int argc, char **argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
595 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
596 FILE *progf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
597 char inbuf[INBUF_SIZE];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
598 unsigned_char_dynarr *outbuf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
599 struct ccl_program ccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
600 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
601 Lisp_Object ccl_prog = make_vector (MAX_CCL_CODE_SIZE);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
602
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
603 if (argc < 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
604 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
605 fprintf (stderr,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
606 "Usage: %s ccl_program_file_name <infile >outfile\n",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
607 argv[0]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
608 exit (1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
609 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
610
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
611 if ((progf = fopen (argv[1], "r")) == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
612 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
613 fprintf (stderr, "%s: Can't read file %s", argv[0], argv[1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
614 exit (1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
615 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
616
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
617 XVECTOR (ccl_prog)->size = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
618 while (fscanf (progf, "%x", &i) == 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
619 XVECTOR (ccl_prog)->contents[XVECTOR (ccl_prog)->size++] = make_int (i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
620 set_ccl_program (&ccl, ccl_prog, 0, 0, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
621
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
622 outbuf = Dynarr_new (unsigned char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
623
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
624 while ((i = fread (inbuf, 1, INBUF_SIZE, stdin)) == INBUF_SIZE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
625 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
626 i = ccl_driver (&ccl, inbuf, outbuf, INBUF_SIZE, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
627 fwrite (Dynarr_atp (outbuf, 0), 1, i, stdout);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
628 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
629 if (i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
630 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
631 i = ccl_driver (&ccl, inbuf, outbuf, i, 1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
632 fwrite (Dynarr_atp (outbuf, 0), 1, i, stdout);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
633 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
634
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
635 fclose (progf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
636 exit (0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
637 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
638 #endif /* standalone */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
639 #endif /* not emacs */