annotate lisp/mule/ccl.el @ 5591:c40d3f96af55 g++-warning-removal-2008-10-28

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