Changeset 7842 for lang/elisp

Show
Ignore:
Timestamp:
03/12/08 17:08:23 (9 months ago)
Author:
lieutar
Message:
 
Location:
lang/elisp/escm/trunk
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/escm/trunk/escm-arity.el

    r7383 r7842  
    11(require 'escm-util) 
    22(require 'escm-cbos) 
     3(require 'escm-test) 
     4(require 'escm-env) 
    35 
    4 (escm-cbos::define-class escm-arity 
     6(escm-cbos::define-class (escm-arity) 
    57                         length 
    68                         symbols 
     
    1921                (progn (setq fields  (cons head fields)) 
    2022                       (setq argspec tail)) 
    21               (throw 'error (format "wrong type argument: synbolp : %s" head)))) 
     23              (throw 'error "wrong type argument" 'synbolp head))) 
    2224        (progn (setq fields (cons argspec fields)) 
    2325               (setq at-least t) 
     
    2527    (escm-arity::set-symbols  new (reverse fields)) 
    2628    (escm-arity::set-length   new (length  fields)) 
    27     (escm-arity::set-at-least new at-least))) 
     29    (escm-arity::set-at-least new at-least) 
     30    new)) 
     31 
     32;;; test code 
     33(escm-test::define-test escm arity 
     34  (let ((z (escm-arity::new  ())) 
     35        (o (escm-arity::new  '(a b c))) 
     36        (a1 (escm-arity::new 'a)) 
     37        (a2 (escm-arity::new '(a . b)))) 
     38    (escm-test one1         (= 1 (escm-arity::get-length a1))) 
     39    (escm-test zero         (= 0 (escm-arity::get-length z))) 
     40    (escm-test three        (= 3 (escm-arity::get-length o))) 
     41    (escm-test not-at-least (not (escm-arity::get-at-least z))) 
     42    (escm-test at-least-2   (escm-arity::get-at-least a2)) 
     43    (escm-test at-least-1   (escm-arity::get-at-least a1)))) 
     44;; (escm-test::run 'escm 'arity) 
     45 
    2846 
    2947(defsubst escm-arity::inject-args! (self env args) 
     
    3856 
    3957(provide 'escm-arity) 
     58 
     59 
  • lang/elisp/escm/trunk/escm-cbos.el

    r7383 r7842  
    7878         (meth  (escm-cbos::find-method 'ilist name))) 
    7979    (if meth (apply meth (cons ilist (cons name (cons obj args)))) 
    80       (throw 'escm-cbos::error::no-such-method 
    81              (format "method \"%s.%s\" is not exist." class name))))) 
     80      (throw 'escm-cbos::error::no-such-method  
     81             (list "no such method" class name))))) 
    8282 
    8383(defun escm-cbos::expand-method (args body) 
     
    155155              fields))))) 
    156156 
     157(defun escm-cbos::report-class (class) 
     158  ) 
     159 
    157160 
    158161(escm-cbos::register-class 'escm-cbos::Object nil nil) 
  • lang/elisp/escm/trunk/escm-env.el

    r7840 r7842  
    11(require 'escm-util) 
    22(require 'escm-cbos) 
     3(require 'escm-test) 
    34 
    45(defconst escm-env::class-diagram " 
     
    5455                             val)))) 
    5556 
    56 (escm-test::define-test escm env 
    57   "" 
    58   (let* ((e (create-escm-env nil '(a b c))) 
    59          (f (create-escm-env e   '(d e f))) 
    60          (g (create-escm-env f   '(a)))) 
    61     (escm-test "gset! 0" (escm-env::gset! e 'a 1) t) 
    62     (escm-test "gref  0" (eq 1 (escm-env::gref e 'a))) 
    63     (escm-test "gset! 1" (escm-env::gset! f 'b 2) t) 
    64     (escm-test "gref  1" (eq 2 (escm-env::gref  e 'b))) 
    65     (escm-test "gset! 2" (escm-env::gset! g 'a 3) t) 
    66     (escm-test "gref  2" (and (eq 1 (escm-env::gref e 'a)) 
    67                               (eq 3 (escm-env::gref g 'a)))) 
    68     (escm-util::a (escm-env::make-referer f 'env 'a)) 
    69     (escm-util::a (escm-env::make-setter f 'env 'a '((aaa)))))) 
    70  
    71 ;;(escm-test::run 'escm 'env ) 
    72  
    7357;;;-----------;;; 
    7458;;;           ;;; 
     
    8064 
    8165;; override 
    82 (defsubst create-escm-env (parent syms) 
     66(defsubst create-escm-fixed-env (parent syms) 
    8367  (let ((new (escm-cbos::create-object 'escm-env (length syms))) 
    8468        (dic (make-symbol "*dic*")) 
     
    8670    (escm-env::set-parent new parent) 
    8771    (escm-env::set-dic    new dic) 
    88     (escm-env::set-ptr    new 3) 
     72    (escm-fixed-env::set-ptr    new 3) 
    8973    (mapcar (lambda (s) (put dic s (setq p (1+ p)))) syms) 
    9074    new)) 
     
    10084      (let ((parent (escm-env::get-parent self))) 
    10185        (if parent (escm-env::gref parent) 
    102           (throw 'escm-env::unbound (format "unbound symbol : %s" sym))))))) 
     86          (throw 'escm-env::unbound "unbound symbol" sym)))))) 
    10387 
    10488(escm-cbos::define-method escm-fixed-env escm-env::gset! (self sym val) 
     
    10791      (let ((parent (escm-env::get-parent self))) 
    10892        (if parent (escm-env::gset! parent sym val) 
    109           (throw 'escm-env::unbound (format "unbound symbol : %s" sym))))))) 
     93          (throw 'escm-env::unbound  "unbound symbol" sym)))))) 
     94 
     95;; test code for escm-test 
     96(escm-test::define-test escm env 
     97  "" 
     98  (let* ((e (create-escm-fixed-env nil '(a b c))) 
     99         (f (create-escm-fixed-env e   '(d e f))) 
     100         (g (create-escm-fixed-env f   '(a)))) 
     101    (escm-test "gset! 0" (escm-env::gset! e 'a 1)) 
     102    (escm-test "gref  0" (eq 1 (escm-env::gref e 'a))) 
     103    (escm-test "gset! 1" (escm-env::gset! f 'b 2)) 
     104    (escm-test "gref  1" (eq 2 (escm-env::gref  e 'b))) 
     105    (escm-test "gset! 2" (escm-env::gset! g 'a 3) t) 
     106    (escm-test "gref  2" (and (eq 1 (escm-env::gref e 'a)) 
     107                              (eq 3 (escm-env::gref g 'a)))) 
     108    (escm-util::a (escm-env::make-referer f 'env 'a)) 
     109    (escm-util::a (escm-env::make-setter f 'env 'a '((aaa)))))) 
     110;; (escm-test::run 'escm 'env ) 
    110111 
    111112;;;-------------;;; 
  • lang/elisp/escm/trunk/escm-test.el

    r7840 r7842  
    11(defconst escm-test::tests () "symbol for plist of tests.") 
    22 
     3(defface  escm-test::ok-face 
     4  '((((class color) (background light)) 
     5     (:foreground "black" :background "green")) 
     6    (((class color) (background dark)) 
     7     (:foreground "black" :background "green")) 
     8    (t ())) 
     9  "") 
     10 
     11(defface  escm-test::faild-face  
     12  '((((class color) (background light)) 
     13     (:foreground "white" :background "red")) 
     14    (((class color) (background dark)) 
     15     (:foreground "white" :background "red")) 
     16    (t ())) 
     17  "") 
     18 
    319(defmacro escm-test (name &rest x) 
     20  "" 
    421  `(let ((err (condition-case *error* 
    5                   (let ((err (eval (progn ,@x)))) (if (eq err t) nil err)) 
    6                 (error *error*)))) 
    7      (when err (setq failed (cons (cons ,name err) failed))))) 
     22                  (let ((err (eval (progn ,@x)))) 
     23                    (if (eq err t) nil (or err "failed"))) 
     24                (error 
     25                 (format "%S\n%s" 
     26                         *error* 
     27                         (with-output-to-string 
     28                           (backtrace))))))) 
     29     (setq report (cons (if err (progn (setq failed (1+ failed)) 
     30                                       (list ',name err))  ',name) 
     31                        report)))) 
    832 
    933(defun escm-test::run-test (reporter project name all) 
    1034  "Runs provided test." 
    11   (let* ((errors  ()) 
    12          (failed  ())) 
     35  (let* ((report  ()) 
     36         (errors  ()) 
     37         (failed  0)) 
    1338    (eval (cons 'progn all)) 
    14     (apply reporter (list project name  (length all) failed)))) 
     39    (apply reporter (list project name failed (reverse report))))) 
    1540 
    1641(defmacro escm-test::define-test (project name &rest body) 
     
    1843  `(put 'escm-test::tests 
    1944        ',project 
    20         (cons (cons ',name ',body) (get 'escm-test::tests ',project)))) 
     45        (cons (cons ',name ',body) 
     46              (get 'escm-test::tests ',project)))) 
    2147(put 'escm-test::define-test 'lisp-indent-function 'defun) 
    2248 
    23 (defun escm-test::report-single (project name all failed) 
     49(defun escm-test::report-single (project name failed report) 
    2450  "" 
    25   (if failed 
    26       (with-output-to-temp-buffer "*escm-test*" 
    27         (mapcar 
    28          'print 
    29          failed)) 
    30     (message "all tests successful."))) 
     51  (save-excursion 
     52    (let ((buf (get-buffer-create "*escm-test*"))) 
     53      (set-buffer buf) 
     54      (toggle-read-only -1) 
     55      (delete-region (point-min) (point-max)) 
     56      (insert 
     57       (mapconcat 
     58        (lambda (r) 
     59          (if (listp r) 
     60              (let ((head (format "%s :"    (car r)))) 
     61                (set-text-properties 
     62                 0 (length head) '(face escm-test::faild-face) head) 
     63                (concat head (format " %s" (cadr r)))) 
     64            (let ((ok (format "%s ... ok!" r))) 
     65              (set-text-properties 
     66               0 (length ok) '(face escm-test::ok-face) ok) 
     67              ok))) 
     68        report 
     69        "\n")) 
     70      (toggle-read-only 1) 
     71      (goto-char (point-min)) 
     72      (pop-to-buffer buf t t))) 
     73  (when (= failed 0) (message "all tests successful."))) 
    3174 
    3275(defun escm-test::project-alist () 
     
    5497  (let ((alist (get 'escm-test::tests project))) 
    5598    (if name 
    56         (escm-test::run-test 'escm-test::report-single project name (cdr (assoc name alist))) 
     99        (escm-test::run-test 'escm-test::report-single project name 
     100                             (cdr (assoc name alist))) 
    57101      (let ((failed ())) 
    58102        (mapcar (lambda (x) 
    59103                  (escm-test::run-test 
    60                    (lambda (project name all fail) 
    61                      (if fail nil 
     104                   (lambda (project name fail report) 
     105                     (if fail 
     106                         nil 
    62107                       (setq failed (cons fail failed)))) 
    63108                   project 
  • lang/elisp/escm/trunk/escm-util.el

    r7840 r7842  
    11(require 'cl) 
     2 
     3(apply (let ((s (make-symbol "*aa*"))) 
     4         (set s 123) 
     5         (eval `(lambda () (symbol-value ,s)))) ()) 
    26 
    37(defmacro escm-util::expand (&rest body) 
    48  "Expands anonymous macro as standard macro." 
    59  (cons 'progn (eval body))) 
     10 
     11(defmacro escm-util::text-with-properties (str &rest props) 
     12  "" 
     13  (let ((str ,str)) 
     14    (set-text-properties 0 (length str) props str) 
     15    str)) 
     16 
     17(defmacro escm-util::popup (name &rest body) 
     18  "" 
     19  `(save-excursion 
     20     (set-buffer    (get-buffer-create ,name)) 
     21     (toggle-read-only -1) 
     22     (delete-region (point-min) (point-max)) 
     23     ,@body 
     24     (toggle-read-only 1) 
     25     (goto-char (point-min)) 
     26     (pop-to-buffer (current-buffer) t t))) 
     27 
     28(defun escm-util::a (&rest args) 
     29  "Prints args to minibuffer." 
     30  (read-char (format "%S" args)) 
     31  nil) 
     32 
     33(defsubst escm-util::get-arity (fun) 
     34  "Returns arguments list of function." 
     35  (if (functionp fun) 
     36      (cond ((subrp fun) (subr-arity fun)) 
     37            ((listp fun) (cadr       fun)) 
     38            (t           (aref       fun 0))) 
     39    (throw 'error (format "wrong type argument: functionp %S" fun)))) 
     40 
    641 
    742;;; 
     
    5186          (nthcdr (+ n (or len 1))  list))) 
    5287 
    53 (defun escm-util::a (&rest args) 
    54   "Prints args to minibuffer." 
    55   (read-char (format "%S" args)) 
    56   nil) 
    57  
    58 (defsubst escm-util::get-arity (fun) 
    59   "Returns arguments list of function." 
    60   (if (functionp fun) 
    61       (cond ((subrp fun) (subr-arity fun)) 
    62             ((listp fun) (cadr       fun)) 
    63             (t           (aref       fun 0))) 
    64     (throw 'error (format "wrong type argument: functionp %S" fun)))) 
    6588 
    6689(provide 'escm-util)