Source

mule-ucs / lisp / mucs-ccl.el

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
;;; -*- byte-compile-dynamic: t -*-
;;; mucs-ccl.el --- Mule-UCS CCL manager.(MUCS-CCL)

;; Copyright (C) 1997-2000 Miyashita Hisashi

;; Keywords: mule, multilingual, 
;;           character set, coding-system, CCL

;; This file is part of Mule-UCS

;; Mule-UCS is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; Mule-UCS is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;; Comment:

(require 'mucs-type)
(require 'trans-util)
(require 'ccl)

;;; To cease noisy compiler warnings.
(eval-when-compile
  (if (not (boundp 'mucs-version))
      (require 'mucs)))

;;; ------ Some notes on MUCS-CCL. ------
;;; MUCS-CCL stands for MUle-uCS CCL generation library.
;;; This module provides the following services.
;;;
;;; 1 ... more abstracted description. (that has upper compatibility.)
;;; 2 ... supply basic CCL libraries.
;;; 3 ... manages the state to produce CCL codes.
;;;           This state is called `mucs-ccl-production-state'.
;;; 4 ... register the mucs-ccl-production-state
;;;                at the location marked by users.
;;; 5 ... produce the table structures that are used by ExCCL.
;;;

;;;
;;; MUCS-CCL internal coding system.
;;;

(defvar mucs-ccl-temporal-coding-system-ccl-symbol nil)

(defsubst mucs-ccl-define-temporal-coding-system (conv)
  (if (eq mucs-ccl-temporal-coding-system-ccl-symbol
	  conv)
      nil
    (register-ccl-program
     'mucs-ccl-tmp-ccl-prog
     (mucs-conversion-get conv 'mucs-compiled-code))
    (if (not (coding-system-p
	      'mucs-ccl-temporary))
	(make-coding-system
	 'mucs-ccl-temporary
	 4 ?*
	 "Temporary coding-system privately used by MUCS-CCL"
	 '(mucs-ccl-tmp-ccl-prog . mucs-ccl-tmp-ccl-prog)))))

;;; CCL facility checker.

(defvar mucs-ccl-facility-alist
  '((valid-map-multiple
     mucs-ccl-check-map-multiple-function
     "CCL_MapMultiple facility is invalid."
     none)))

(defun mucs-ccl-check-map-multiple-function ()
  (let ((vec (make-vector 8 0)))
    (register-code-conversion-map
     'mucs-ccl-test-map-1
     [10 10])
    (register-code-conversion-map
     'mucs-ccl-test-map-2
     [0 1])
    (ccl-execute
     (ccl-compile
      '(0 ((map-multiple
	    r1 r0 (((mucs-ccl-test-map-1)) mucs-ccl-test-map-2)))))
     vec)
    (if (= (aref vec 0) 1)
	(progn
;	  (message "!!! This CCL interpreter have the valid MapMultiple instruction.
;!!! We enable all features on MUCS-CCL.")
	  t)
      (message "!!! Sorry.  This CCL interpreter have faults on MapMultiple instruction.
!!! Some features on MUCS-CCL are disabled.")
      nil)))

(defun mucs-ccl-inspect-facility (required-facility)
  (let ((slot (assq required-facility mucs-ccl-facility-alist))
	result)
    (if (null slot)
	(error "Unknown facility:%S" required-facility))
    (setq result (nth 3 slot))
    (if (eq result 'none)
	(progn
	  (setq result (funcall (nth 1 slot)))
	  (setcar (nthcdr 3 slot) result)))
    result))

(defun mucs-ccl-get-facility-error-message (facility)
  (nth 2 (assq facility mucs-ccl-facility-alist)))

(defsubst mucs-ccl-facility-error (required-facility
				   &optional additional-message)
  (if (not (mucs-ccl-inspect-facility required-facility))
      (error (concat
	      "  !!! "
	      (mucs-ccl-get-facility-error-message
	       required-facility)
	      "\n"
	      additional-message
	      "\n"
	      "If you would like to use this facility, please apply the patch for CCL to
your Emacs, and MUST recompile ALL PACKAGES of Mule-UCS!
For detail, please refer README file of Mule-UCS"))))

;;;
;;; some simple ccl codes.
;;;

(defvar mucs-ccl-read-ex-1-octet
  `((read r0)))

(defvar mucs-ccl-read-ex-be-2-octet
  `((read r0 r4)
    (r0 = (r0 <8 r4))))

(defvar mucs-ccl-read-ex-le-2-octet
  `((read r0 r4)
    (r0 = (r4 <8 r0))))

(defvar mucs-ccl-write-ex-1-octet
  `((write r0)))

(defvar mucs-ccl-write-ex-be-2-octet
  `((write (r0 >> 8))
    (write (r0 & 255)))) ; #xFF

(defvar mucs-ccl-write-ex-le-2-octet
  `((write (r0 & 255)) ; #xFF
    (write (r0 >> 8))))

;;;
;;; generic type definition
;;;

(mucs-define-type
 'char-1
 (function char-1-elisp-representation)
 (function char-1-ccl-representation))

(defun mucs-ccl-write-char-1 ()
  '((r1 = (r0 >> 16))
    (r0 = (r0 & 65535)) ; #xFFFF
    (if (r0 > 255) ; #xFF
	((r0 -= 32) ; #x20
	 (r4 = ((r0 / 96) << 7))
	 (r0 = (((r0 % 96) + r4) + 32)))) ; 32 is #x20
    (write-multibyte-character r1 r0)))

(defun mucs-ccl-read-char-1 ()
  '((read-multibyte-character r1 r0)
    (if (r0 > 255) ; #xFF
	((r4 = (r0 & 127)) ; #x7F
	 (r0 = (((r0 >> 7) * 96) + r4))
	 (r0 |= (r1 << 16)))
      ((r0 |= (r1 << 16))))))

(mucs-type-register-serialization
 'char-1
 'emacs-mule
 (quote `(,(mucs-ccl-write-char-1)))
 (quote `(,(mucs-ccl-read-char-1))))

;;
;; Internal state management functions
;;
(defvar mucs-ccl-internal-state-usage
  (make-vector mucs-code-range-bits nil))

(defun mucs-ccl-internal-state-reserve (name bit)
  (if (not (symbolp name))
      (signal 'wrong-type-argument
	      (list 'symbolp name)))
  (if (>= bit (length mucs-ccl-internal-state-usage))
      (error "Bit %d is too large.(%s)" bit name))
  (let ((slot (aref mucs-ccl-internal-state-usage bit)))
    (if (and name slot
	     (not (eq name slot)))
	(error "Bit %d have been already reserved.(%s)" bit name))
    (aset mucs-ccl-internal-state-usage bit name)
    (if name
	(put name 'mucs-ccl-internal-state-bit bit)
      (if slot
	  (put slot
	       'mucs-ccl-internal-state-bit nil)))))

(defun mucs-ccl-set-internal-state (name state)
  "Return a block that sets internal state to STATE for NAME."
  (let ((bit (get name 'mucs-ccl-internal-state-bit)))
    (if (not bit)
	(error "%s is not registered for internal state!"
	       name))
    (if state
	`((r5 |= ,(lsh 1 bit)))
      `((r5 &= ,(logxor (mucs-number-mask) (lsh 1 bit)))))))

(defun mucs-ccl-check-internal-state (name)
  "Return a statement that checks internal state for NAME."
  `(r5 & ,(lsh 1
	       (or (get name 'mucs-ccl-internal-state-bit)
		   (error "%s is not registered for internal state!"
			  name)))))

;;
;; Dealing with line separator problem.
;;

(mucs-ccl-internal-state-reserve 'previous-cr-p 0)

(defun mucs-ccl-write-char-1-dos ()
  `((if (r0 == ?\r)
	((if ,(mucs-ccl-check-internal-state 'previous-cr-p)
	     ((write ?\r))
	   ,(mucs-ccl-set-internal-state 'previous-cr-p t)))
      ((r4 = (r0 != ?\n))
       (if (,(mucs-ccl-check-internal-state 'previous-cr-p) & r4)
	   ((write ?\r)))
       ,@(mucs-ccl-set-internal-state 'previous-cr-p nil)
       ,@(mucs-ccl-write-char-1)))))

(mucs-type-register-serialization
 'char-1
 'emacs-mule-dos
 (quote `(,(mucs-ccl-write-char-1-dos)))
 'none)

;;;
;;; CCL program generator
;;;

;;
;;  MYO fundamental section.
;;

;; NOTE:
;;    MUCS-CCL defines a simple message to pass generated program
;; and data structure, which is called MYO.
;; The followings show the specification of MYO.
;;
;;    (myo . A-LIST)
;;          Special data structure for mucs-ccl.
;;          A-LIST has data generated by CCL generator.
;;          The reserved keys of the A-LIST are as
;;          follows(All of them are SYMBOL),
;;          and all MYO MUST have these keys.
;;          (a) ... ccl
;;                   generated CCL programs
;;          (b) ... elisp
;;                   Elisps that are supporsed to evaled
;;                   before CCL programs are registered.
;;          (c) ... table-set
;;                   Generated table-set that are supporsed to be
;;                   registered before CCL programs are registered.
;;
;;

(defsubst mucs-ccl-myo-p (data)
  (eq 'myo (car-safe data)))

(defsubst mucs-ccl-check-myo (data)
  (if (not (and (mucs-ccl-myo-p data)
		(assq 'elisp (cdr data))
		(assq 'ccl (cdr data))
		(assq 'table-set (cdr data))))
      (error "Invalid MYO:%S" data)))


(defsubst mucs-ccl-empty-myo ()
  (cons 'myo (list
	      (cons 'ccl nil)
	      (cons 'elisp nil)
	      (cons 'table-set nil))))

(defsubst mucs-ccl-myo-from-ccl (ccl)
  (cons 'myo (list (list 'ccl ccl)
		   (cons 'elisp nil)
		   (cons 'table-set nil))))

(defsubst mucs-ccl-myo-append (myo1 myo2)
  "Returns concatinated MYO1 and MYO2.
MYO1 and MYO2 may be destructed."
  (let ((alist1 (cdr myo1))
	(alist2 (cdr myo2))
	elem1 elem2)
    (while (setq elem1 (car alist1))
      (setq elem2 (assq (car elem1) alist2)
	    alist1 (cdr alist1))
      (if elem2
	  (progn
	    (setcdr elem1 (append (cdr elem1)
				  (cdr elem2)))
	    (setq alist2 (delq elem2 alist2)))))
    (nconc myo1 alist2)))

(defsubst mucs-ccl-myo-append-safe (myo1 myo2)
  "Returns concatinated MYO1 and MYO2.
MYO1 and MYO2 is never destructed."
  (let ((alist1 (cdr myo1))
	(alist2 (copy-sequence (cdr myo2)))
	result
	elem1 elem2)
    (while (setq elem1 (car alist1))
      (setq elem2 (assq (car elem1) alist2)
	    alist1 (cdr alist1))
      (if elem2
	  (progn
	    (setq result (cons
			  (append elem1
				  (cdr elem2))
			  result))
	    (setq alist2 (delq elem2 alist2)))
	(setq result (cons elem1
			   result))))
    (cons 'myo
	  (nconc result alist2))))


(defsubst mucs-ccl-myo-add-elisp (elisp myo)
  (let ((slot (assq 'elisp (cdr myo))))
    (setcdr slot (append (cdr slot) elisp))
    myo))

(defsubst mucs-ccl-myo-get-elisp (myo)
  (cdr (assq 'elisp (cdr myo))))

(defsubst mucs-ccl-myo-set-elisp (elisp myo)
  (setcdr (assq 'elisp (cdr myo)) elisp))


(defsubst mucs-ccl-myo-add-ccl (ccl myo)
  (let ((slot (assq 'ccl (cdr myo))))
    (setcdr slot (append (cdr slot) ccl))
    myo))

(defsubst mucs-ccl-myo-get-ccl (myo)
  (cdr (assq 'ccl (cdr myo))))

(defsubst mucs-ccl-myo-set-ccl (ccl myo)
  (setcdr (assq 'ccl (cdr myo)) ccl)
  myo)


(defsubst mucs-ccl-myo-add-table-set (table-set myo)
  (let ((slot (assq 'table-set (cdr myo))))
    (setcdr slot (append (cdr slot)
			 (list table-set)))
    myo))

(defsubst mucs-ccl-myo-get-table-set (myo)
  (cdr (assq 'table-set (cdr myo))))

(defsubst mucs-ccl-myo-set-table-set (ccl myo)
  (setcdr (assq 'table-set (cdr myo)) ccl))


;;
;; conversion configuration handler
;;

(defun mucs-ccl-bind-program (progs)
  (let ((myo (mucs-ccl-empty-myo))
	ret)
    (while progs
      (setq ret (car progs)
	    progs (cdr progs))
      (if (mucs-ccl-myo-p ret)
	  (setq myo (mucs-ccl-myo-append myo ret))
	(if (consp ret)
	    (setq myo (mucs-ccl-myo-add-ccl ret myo))
	  (if ret
	      (error "Unknown MUCS-CCL data:%S" ret)))))
    myo))

(defun mucs-ccl-stream-form (&rest args)
  (let ((myo (mucs-ccl-bind-program args)))
    (mucs-ccl-myo-set-ccl
     (list
      (append '(loop)
	      (mucs-ccl-myo-get-ccl myo)
	      '((repeat))))
     myo)))

;;
;; misc.
;;

(defun mucs-ccl-make-elisp-preparation-from-myo (myo)
  (append
   (mucs-ccl-myo-get-elisp myo)
   (if mucs-current-package
       (mapcar
	(function generate-table-set-registration-program)
	(mucs-ccl-myo-get-table-set myo)))))

;;;
;;; MUCS Conversion Engine API.
;;;

(defun mucs-convert (conversion object)
  (let ((ccl-object
	 (funcall
	  (mucs-type-get-ccl-representation
	   (car (mucs-conversion-get-conv-type conversion)))
	  object))
	(execute-vector
	 (make-vector 8 0)))
    (ccl-execute conversion
		 (cond ((numberp ccl-object)
			(aset execute-vector 0 ccl-object)
			execute-vector)
		       ((vectorp ccl-object)
			ccl-object)
		       (t
			(signal 'mucs-ccl-invalid-error
				(list object)))))
    (if (= (aref execute-vector 0) mucs-invalid-code)
	nil
      (funcall
       (mucs-type-get-elisp-representation
	(cdr (mucs-conversion-get-conv-type conversion)))
       (if (vectorp ccl-object)
	   execute-vector
	 (aref execute-vector 0))))))

(defun mucs-convert-region (start end conversion)
  "Convert the current region by specified conversion,
which is defined by `mucs-define-conversion'.
It returns the length of the encoded text."
  (interactive 
   (list (region-beginning)
	 (region-end)
	 (intern
	  (completing-read
	   "MUCS Conversion:"
	   (let (candlist)
	     (mapatoms
	      (lambda (x)
		(if (and (mucs-conversion-p x)
			 (eq (mucs-conversion-get-conv-type x)
			     'stream))
		    (setq candlist
			  (cons
			   (cons (symbol-name x) 0)
			   candlist)))))
	     candlist)))))
  (if (not (and (mucs-conversion-p conversion)
		(eq (mucs-conversion-get-conv-type
		     conversion)
		    'stream)))
      (error "%S is not MUCS conversion" conversion))
  (mucs-ccl-define-temporal-coding-system conversion)
  (encode-coding-region start end 'mucs-ccl-temporary))

(defun mucs-convert-string (string conversion &optional unibyte-p)
  "Convert STRING by specified conversion,
which is defined by `mucs-define-conversion'.
It returns the encoded text.

If UNIBYTE-P is non-nil, return a unibyte string as a result."
  (if (not (stringp string))
      (signal 'wrong-type-argument
	      (list 'stringp string)))
  (if (not (and (mucs-conversion-p conversion)
		(eq (mucs-conversion-get-conv-type
		     conversion)
		    'stream)))
      (error "%S is not MUCS conversion" conversion))
  (ccl-execute-on-string conversion (make-vector 9 nil)
			 string nil unibyte-p))

(defun mucs-ccl-setup-myo (config)
  (let ((myo (mucs-ccl-empty-myo))
	ret)
    (while config
      (setq ret (eval (car config))
	    config (cdr config))
      (if (consp ret)
	  (if (mucs-ccl-myo-p ret)
	      (setq myo (mucs-ccl-myo-append myo ret))
	    (setq myo (mucs-ccl-myo-add-ccl ret myo)))
	(if ret
	    (error "Invalid MUCS-CCL:%S" ret))))
    myo))

(defun mucs-setup-conversion (conv def)
  (let ((convtype (mucs-conversion-get-conv-type conv))
	(mucs-current-conversion conv)
	(mucs-current-type nil)
	(mag (mucs-conversion-definition-mag def))
	(config-main (mucs-conversion-definition-main-prog def))
	(config-eof (mucs-conversion-definition-eof-prog def))
	main-ccl-myo eof-ccl-myo
	ccl-program
	compiled-ccl)

    (if (consp convtype)
	(setq mucs-current-type (car convtype)))
    (setq main-ccl-myo (mucs-ccl-setup-myo config-main))
    (if (and (consp convtype)
	     (not (eq (cdr convtype) mucs-current-type)))
	(signal 'mucs-type-mismatch-error
		(cons mucs-current-type (cdr convtype))))
    (if (consp convtype)
	(setq mucs-current-type (car convtype)))
    (setq eof-ccl-myo (mucs-ccl-setup-myo config-eof))
;;; EOF CCL program is not executed when non-stream conversion.
;    (if (and (consp convtype)
;	     (not (eq (cdr convtype) mucs-current-type)))
;	(signal 'mucs-type-mismatch-error
;		(cons mucs-current-type (cdr convtype))))
    (setq ccl-program (list '\` ;;; for backquoting.
			    (list
			     mag
			     (mucs-ccl-myo-get-ccl main-ccl-myo)
			     (mucs-ccl-myo-get-ccl eof-ccl-myo))))
    (setq compiled-ccl (ccl-compile (eval ccl-program)))
    (mucs-conversion-set-program-and-compiled-code
     conv ccl-program compiled-ccl)
    (append
     (mucs-ccl-make-elisp-preparation-from-myo main-ccl-myo)
     (mucs-ccl-make-elisp-preparation-from-myo eof-ccl-myo)
     `((declare-ccl-program ,conv ,compiled-ccl)))))

(defun mucs-refresh-conversion (conv program)
  (let ((compiled-ccl (ccl-compile program)))
;    (message "modify %S!" conv)
    (register-ccl-program conv
			  compiled-ccl)
    (mucs-conversion-set-program-and-compiled-code
     conv program compiled-ccl)))

;;;
;;; MUCS-CCL standard library.
;;;

(defun mucs-ccl-if (expression true-part &optional false-part)
  (let (true-part-myo
	false-part-myo
	result-myo)
    (setq true-part-myo (mucs-ccl-bind-program (eval true-part)))
    (if false-part
	(progn
	  (setq false-part-myo (mucs-ccl-bind-program (eval false-part))
		result-myo (mucs-ccl-myo-append-safe
			    true-part-myo
			    false-part-myo))
	  (mucs-ccl-myo-set-ccl
	   `((if ,expression
		 ,(mucs-ccl-myo-get-ccl true-part-myo)
	       ,(mucs-ccl-myo-get-ccl false-part-myo)))
	   result-myo))
      (mucs-ccl-myo-set-ccl
       `((if ,expression
	     ,(mucs-ccl-myo-get-ccl true-part-myo)))
       true-part-myo))))

(put 'mucs-ccl-if 'lisp-indent-function 2)

(defun mucs-ccl-if-invalid (invalid-part &optional valid-part)
  (let (invalid-part-myo valid-part-myo result-myo)
    (setq invalid-part-myo (mucs-ccl-bind-program (eval invalid-part)))
    (if valid-part
	(progn
	  (setq valid-part-myo (mucs-ccl-bind-program (eval valid-part))
		result-myo (mucs-ccl-myo-append-safe
			    invalid-part-myo
			    valid-part-myo))
	  (mucs-ccl-myo-set-ccl
	   `((if (r0 == ,mucs-invalid-code)
		 ,(mucs-ccl-myo-get-ccl invalid-part-myo)
	       ,(mucs-ccl-myo-get-ccl valid-part-myo)))
	   result-myo))
      (mucs-ccl-myo-set-ccl
       `((if (r0 == ,mucs-invalid-code)
	     ,(mucs-ccl-myo-get-ccl invalid-part-myo)))
       invalid-part-myo))))

(defun mucs-ccl-if-valid (valid-part)
  (let ((valid-part-myo (mucs-ccl-bind-program (eval valid-part))))
    (mucs-ccl-myo-set-ccl
     `((if (r0 != ,mucs-invalid-code)
	   ,(mucs-ccl-myo-get-ccl valid-part-myo)))
     valid-part-myo)))

(defun mucs-ccl-if-invalid-repeat ()
  (mucs-ccl-if-invalid '(quote (((repeat))))))

;;
;; CCL registration APIs.
;;

(defun mucs-ccl-register-ccl-program (name ccl-block)
  (mucs-register-object 'mucs-ccl-required name)
;  (message "MCCLREG(%S):%S" name ccl-block)
  (put name
       'mucs-ccl-required-ccl-program
       ccl-block))

(defun mucs-ccl-generate-registration-program ()
  (let ((ccl-pgm-list
	 (mucs-unembedded-object-list 'mucs-ccl-required))
	name myo result)
    (while (setq name (car ccl-pgm-list))
      (setq myo (mucs-ccl-setup-myo
		 (get name 'mucs-ccl-required-ccl-program)))
      (setq result
	    (append
	     result
	     (mucs-ccl-make-elisp-preparation-from-myo myo)
	     `((register-ccl-program
		',name
		,(ccl-compile 
		  (list 0
			(mucs-ccl-myo-get-ccl myo)))))))
      (mucs-notify-embedment 'mucs-ccl-required name)
      (setq ccl-pgm-list (cdr ccl-pgm-list)))
;   (message "MCCLREGFIN:%S" result)
    `(progn
       (setq mucs-ccl-facility-alist
	     (quote ,mucs-ccl-facility-alist))
       ,@result)))

;;; Add hook for embedding translation informations to a package.
(add-hook 'mucs-package-definition-end-hook
	  (function mucs-ccl-generate-registration-program))

;;
;; Common I/O interface.
;;

(defun mucs-ccl-read (type serialize)
  (setq mucs-current-type type)
  (mucs-ccl-bind-program
   (eval (mucs-type-get-serialize-method type serialize t))))

(defun mucs-ccl-write (serialize)
  (if mucs-current-type
      (mucs-ccl-if-valid
       (mucs-type-get-serialize-method
	mucs-current-type serialize nil))
    (error "Current TYPE is not set.  Cannot write.")))

;;
;; Short CCL routine.
;;

(defun mucs-ccl-add-program (reg add)
  (if (not (symbolp reg))
      (signal 'wrong-type-argument
	      (list 'symbolp reg)))
  (if (not (numberp add))
      (signal 'wrong-type-argument
	      (list 'numberp add)))
  (let ((sym
	 (intern (format "mucs-ccl-add-%S-%d" reg add))))
    (if (not (mucs-registered-p 'mucs-ccl-required sym))
	(progn
	  (mucs-ccl-register-ccl-program
	   sym
	   `((quote ((,reg += ,add)))))
	  (register-ccl-program
	   sym
	   (ccl-compile `(0 ((,reg += ,add)))))))
    sym))

(defun mucs-ccl-nop-program ()
  (let ((sym
	 (intern "mucs-ccl-nop")))
    (if (not (mucs-registered-p 'mucs-ccl-required sym))
	(progn
	  (mucs-ccl-register-ccl-program
	   sym
	   '((quote ())))
	  (register-ccl-program
	   sym
	   (ccl-compile `(0 ())))))
    sym))

(provide 'mucs-ccl)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.