annotate lisp/mule/ccl.el @ 5473:ac37a5f7e5be

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