Changeset 21628 for lang/elisp

Show
Ignore:
Timestamp:
10/19/08 18:47:57 (3 months ago)
Author:
lieutar
Message:

implemented call-with-current-continuation

Location:
lang/elisp/escm/trunk
Files:
5 added
1 removed
21 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/escm/trunk/DEVELOPERSTOOLS.el

    r12594 r21628  
    55    (setq load-path (cons dir load-path))) 
    66 
    7   (require 'escm) 
     7  (require 'escm-devel) 
    88  (global-set-key [?\C-c ?e ?a] 'escm-debug::activate) 
    99  (global-set-key [?\C-c ?e ?d] 'escm-debug::deactivate) 
     
    1313                    (setq escm-default-vm nil) 
    1414                    (message "default vm is resetted."))) 
     15 
    1516  (global-set-key [?\C-c ?e ?e] 'escm-eval-last-sexp)) 
    16  
    1717 
    1818;; dired 
     
    2020 
    2121 
     22 
     23 
     24 
    2225;; sample codes 
    2326(when nil 
    2427 
    25   (escm-vm::eval (escm-vm::new)  '(+ 0 1 (* 2 3) 4)) 
    26   (escm-vm::eval (escm-vm::new)  '(if nil 1 2)) 
    27   (escm-vm::eval (escm-vm::new) 
    28                  '((lambda () 
    29                      (define (fact n) (if (= n 1) n (* n (fact (- n 1))))) 
    30                      (fact 1 
    31  
    32   (escm-vm::eval 
    33    (escm-vm::new) 
    34    '((lambda () 
    35        (message (call/cc (lambda (cont) 
    36                            (cont "abc"))))))) 
    37  
    38 (escm-vm::eval 
    39  (escm-vm::new) 
    40  '((lambda () 
    41      (define (fib n) 
    42        (define (iter a b n) 
    43          (if (= n 0) (+ a b) (iter b (+ a b) (- n 1)))) 
    44        (iter 0 1 n)) 
    45      (fib 10)))) 
    46  
    47 (insert (format "%S" 
    48                 (escm-vm::byte-compile 
    49                  (escm-vm::new) 
    50                  '((define (fib n) 
    51                      (define (iter a b n) 
    52                        (if (= n 0) (+ a b) (iter b (+ a b) (- n 1)))) 
    53                      (iter 0 1 n)) 
    54                    (fib 10))))) 
    55  
    56 (when nil 
    5728 
    5829  (escm-vm::eval 
     
    6031   '((lambda () 
    6132       (define (fib n) 
    62          (if (< n 2) 
    63              1 
    64            (+ (fib (- n 2)) 
    65               (fib (- n 1))))) 
     33         (define (iter a b n) 
     34           (if (= n 0) (+ a b) (iter b (+ a b) (- n 1)))) 
     35         (iter 0 1 n)) 
    6636       (fib 10)))) 
    6737 
    68   (escm-vm::eval 
    69    (escm-vm::new) 
    70    '((lambda () 
    71        (define (fib-iter a b n) 
    72          (if (= 0 n) 
    73              (+ a b) 
    74            (fib-iter b 
    75                      (+ a b) 
    76                      (- n 1)))) 
    77        (define (fib n) (fib-iter 0 1 n)) 
    78        (fib 12)))) 
    79 ;;  
     38   (escm-vm::eval 
     39    (escm-vm::new) 
     40    '((lambda () 
     41        (define (fib n) 
     42          (if (< n 2) 
     43              1 
     44            (+ (fib (- n 2)) 
     45               (fib (- n 1))))) 
     46        (fib 10)))) 
     47    
     48   (escm-vm::eval 
     49    (escm-vm::new) 
     50    '((lambda () 
     51        (define (fib-iter a b n) 
     52          (if (= 0 n) 
     53              (+ a b) 
     54            (fib-iter b 
     55                      (+ a b) 
     56                      (- n 1)))) 
     57        (define (fib n) (fib-iter 0 1 n)) 
     58        (fib 12)))) 
    8059 
    81   (let* ((def '((define (fib-iter a b n) 
    82                   (if (= 0 n) 
    83                       (+ a b) 
    84                     (fib-iter b 
    85                               (+ a b) 
    86                               (- n 1)))) 
    87                 (define (fib n) (fib-iter 0 1 n)))) 
    88          (bm   (lambda (x) 
    89                  (escm-util::benchmark 
    90                   (escm-vm::eval (escm-vm::new) x)) 
    91                  escm-util::benchmark::result))) 
    92     (list (funcall bm nil) 
    93           (funcall bm `((lambda () ,@def ))) 
    94           (funcall bm `((lambda () ,@def (fib 1)))) 
    95           (funcall bm `((lambda () ,@def (fib 10)))) 
    96           (funcall bm `((lambda () ,@def (fib 15)))))) 
     60    
     61   (let* ((def '((define (fib-iter a b n) 
     62                   (if (= 0 n) 
     63                       (+ a b) 
     64                     (fib-iter b 
     65                               (+ a b) 
     66                               (- n 1)))) 
     67                 (define (fib n) (fib-iter 0 1 n)))) 
     68          (bm   (lambda (x) 
     69                  (escm-util::benchmark 
     70                   (escm-vm::eval (escm-vm::new) x)) 
     71                  escm-util::benchmark::result))) 
     72     (list (funcall bm nil) 
     73           (funcall bm `((lambda () ,@def ))) 
     74           (funcall bm `((lambda () ,@def (fib 1)))) 
     75           (funcall bm `((lambda () ,@def (fib 10)))) 
     76           (funcall bm `((lambda () ,@def (fib 15)))))) 
    9777 
    98   (escm-vm::eval (escm-vm::new) '`a) 
     78   (escm-vm::eval (escm-vm::new) '`a) 
     79   (escm-vm::eval 
     80    (escm-vm::new) '((lambda () 
     81                       (define-syntax a (lambda (_ . x) (list 'quote x))) 
     82                       (a b c)))) 
    9983 
    10084 
    101   (escm-vm::eval 
    102    (escm-vm::new) '((lambda () 
    103                       (define-syntax a (lambda (_ . x) (list 'quote x))) 
    104                       (a b c)))) 
     85   (define (fact n) 
     86     (if (= n 1)        n (* n (fact (- n 1))))) 
    10587 
    106  
    107   (define (fact n) (if (= n 1) 
    108                        n 
    109                      (* n (fact (- n 1))))) 
    110   (fact 20) 
    111   ) 
     88   (fact 20) 
     89   ) 
  • lang/elisp/escm/trunk/Makefile.in

    r12594 r21628  
    22EMACS=@EMACS@ 
    33SITELISP=@SITELISP@ 
     4TAR=@TAR@ 
    45 
    5 ELDIR=src/elisp 
    6 ESCMDIR=src/escm 
     6ELS=@ELS@ 
    77 
    8 ELS= escm-util.minimal.el \ 
    9      escm-test.el \ 
    10      escm-util.el \ 
    11      escm-cbos.el \ 
    12 \ 
    13      escm-base.el \ 
    14 \ 
    15      escm-env.el \ 
    16 \ 
    17      escm-arity.el \ 
    18      escm-proc.el \ 
    19 \ 
    20      escm-syntax.el \ 
    21      escm-iblock-content.el \ 
    22      escm-iblock.el \ 
    23      escm-icode.el \ 
    24      escm-elizer.el \ 
    25      escm-compile.el \ 
    26      escm-port.el \ 
    27 \ 
    28      escm-debug.el \ 
    29      escm-vm.el \ 
    30      escm.el  
    31  
     8INSTDIR=$(SITELISP)/escm 
    329EMACSFLAGS= -batch -q -L . 
    3310 
     
    3512 
    3613.el.elc: 
    37         $(EMACS) $(EMACSFLAGS) -f batch-byte-compile $< 
     14        @echo 
     15        @echo Compiling $< ..... 
     16        @if test -f $@ ; then rm $@ ; fi 
     17        @$(EMACS) $(EMACSFLAGS) -l escm.el -f batch-byte-compile $< 
    3818 
    3919.escm.escmc: 
    4020        $(EMACS) $(EMACSFLAGS) -l escm.el -f escm-batch-byte-compile $< 
    4121 
    42 prelude.escm: genprelude escm/init.escm 
    43         ./genprelude escm/init.escm >$@ 
    4422 
    45 all: elc escmc 
     23#all: elc escmc 
     24all: elc 
    4625 
    47 elc:  $(ELS:.el=.elc) 
     26elc:  escm.elc 
    4827 
    49 escmc: prelude.escmc 
     28escmc: escm/prelude.escmc 
     29 
     30distname: 
     31        @echo  escm-` \ 
     32                grep escm-version escm-base.el \ 
     33                        | sed -e 's/[( )"]\|defconst\|escm-version//g' \ 
     34                ` 
     35install:  all 
     36        mkdir -p  $(INSTDIR) 
     37        cp $(ELS) $(INSTDIR) 
     38        cp $(ELS:.el=.elc) $(INSTDIR) 
     39        cp -r escm test $(INSTDIR) 
     40        chmod 777 $(INSTDIR)/test 
    5041 
    5142clean: 
    52         find . -type f -name \*.elc |xargs rm 
    53         find . -type f -name \*.escmc |xargs rm 
    54  
    55 install: install.el all 
    56         mkdir -p $(SITELISP)/escm 
    57         cp -r escm test $(SITELISP)/escm/escm 
    58         cp $(ELS) $(ELS:.el=.elc) $(SITELISP)/escm 
     43        find . -type f -name \*.elc   |xargs rm -f 
     44        find . -type f -name \*.escmc |xargs rm -f 
    5945 
    6046uninstall: 
    61         rm -rf $(SITELISP)/escm 
     47        rm -rf $(INSTDIR) 
    6248 
    6349distclean: clean 
    64         rm -rf config.log config.status Makefile 
     50        rm -rf config.log config.status Makefile MANIFEST autom4te.cache  
     51        rm -rf .configure.swp 
     52 
     53dist: MANIFEST 
     54        cat MANIFEST |xargs $(TAR) -cvzf `$(MAKE) distname`.tar.gz  
     55 
     56MANIFEST: 
     57        echo $@ > $@ 
     58        find .  | grep -v $@ \ 
     59                | grep -v 'config\..*' \ 
     60                | grep -v 'autom4te\.cache' \ 
     61                | grep -v '\.elc$$' \ 
     62                | grep -v '\.escmc' \ 
     63                | grep -v '\.configure.swp' \ 
     64                | grep -v '\.tar\.[bg]z$$' \ 
     65                >> $@ 
     66 
     67@DEPENDENCIES@ 
  • lang/elisp/escm/trunk/configure.in

    r10671 r21628  
    1 AC_INIT(escm.el) 
    2 AC_ARG_WITH([ emacs ] , 
     1AC_INIT(escm,0.001,lieutar@1dk.jp) 
     2AC_PREREQ(2.6) 
     3 
     4 
     5############################################################ 
     6AC_SUBST(EMACSFLAGS) 
     7EMACSFLAGS="-batch -no-site-file -q -L ." 
     8 
     9## 
     10AC_SUBST(ELS) 
     11ELS=`echo escm*.el` 
     12echo el files ... $ELS 
     13 
     14## 
     15AC_PATH_PROGS(TAR, gtar tar) 
     16 
     17## 
     18AC_SUBST(EMACS) 
     19AC_ARG_WITH(emacs, 
    320            AS_HELP_STRING([--with-emacs@<:@=PATH@:>@], 
    421                           [PATH=emacs, xemacs, mule...]), 
    5             [ EMACS=$withval ], 
    6             [ AC_PATH_PROGS(EMACS, emacs xemacs mule, emacs) ]) 
     22            [ EMACS=$withval; ],[ 
     23            AC_PATH_PROGS(EMACS, emacs xemacs mule, emacs) 
     24            ]) 
    725 
     26echo emacs ... $EMACS 
     27econf="$EMACS $EMACSFLAGS -l emacs-config.el -f" 
     28 
     29## 
     30AC_SUBST(SITELISP) 
     31AC_ARG_WITH(site-lisp, 
     32            AC_HELP_STRING([--with-site-lisp=@<:@PATH@:>@]), 
     33            [SITELISP=$with_site_lisp;],[ 
     34            SITELISP=`$econf 'site-lisp'`;]) 
     35echo site-lisp ... $SITELISP 
     36 
     37## 
     38AC_SUBST(DEPENDENCIES) 
     39echo Check dependencies ... 
     40DEPENDENCIES=`$econf dependencies escm*.el` 
     41 
     42 
     43## 
    844AC_OUTPUT(Makefile) 
  • lang/elisp/escm/trunk/emacs-config.el

    r10654 r21628  
     1;;; emacs-config.el ---  
     2 
     3;; Copyright (C) 2008  root 
     4 
     5;; Author: root <lieutar@lieutar@1dk.jp> 
     6;; Keywords:  
     7 
     8;; This file is free software; you can redistribute it and/or modify 
     9;; it under the terms of the GNU General Public License as published by 
     10;; the Free Software Foundation; either version 3, or (at your option) 
     11;; any later version. 
     12 
     13;; This file is distributed in the hope that it will be useful, 
     14;; but WITHOUT ANY WARRANTY; without even the implied warranty of 
     15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     16;; GNU General Public License for more details. 
     17 
     18;; You should have received a copy of the GNU General Public License 
     19;; along with GNU Emacs; see the file COPYING.  If not, write to 
     20;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
     21;; Boston, MA 02110-1301, USA. 
     22 
     23;;; Commentary: 
     24 
     25;;  
     26 
     27 
     28(defun args () 
     29  "Returns commandline arguments that contains function name and following arguments." 
     30  (cdr (member "-f" command-line-args))) 
     31 
     32(defun echo () 
     33  "Outputs command line arguments." 
     34  (print (cdr (args)))) 
     35 
     36;;  
    137(defun site-lisp () 
     38  "Prints a path to a site-lisp directory." 
    239  (let ((dir (car (apply  
    340                   'append 
     
    946                           load-path))))) 
    1047    (princ dir))) 
     48 
     49 
     50;; 
     51(defun read-dependency (file files) 
     52  "Read all dependency of an emacs lisp FILE in a set of FILES. 
     53Targets of this survey is only require form." 
     54  (let ((buf (find-file file)) 
     55        (R   ())) 
     56    (set-buffer buf) 
     57    (goto-char 1) 
     58    (while (re-search-forward "(require\\s +'\\([^) \t]+\\)" nil t) 
     59      (let ((match (intern (match-string 1)))) 
     60        (when (member (format "%s.el" match) files) 
     61          (setq R (cons match R))))) 
     62    (kill-buffer buf) 
     63    R)) 
     64 
     65(defun dependencies () 
     66  "Print dependencies of files that was given as command line arguments. 
     67An output of this function is formatted as Makefile targets and its dependencies." 
     68  (let ((files (cdr (args)))) 
     69      (princ (concat (mapconcat (lambda (f) 
     70                                  (format "%sc: %s %s" 
     71                                          f 
     72                                          f 
     73                                          (mapconcat (lambda (f) 
     74                                                       (format "%s.elc" f)) 
     75                                                     (read-dependency f 
     76                                                                      files) 
     77                                                     " "))) 
     78                                files 
     79                                "\n") 
     80                     "\n")))) 
     81 
  • lang/elisp/escm/trunk/escm-arity.el

    r10671 r21628  
    3939 
    4040(defsubst escm-arity::new (argspec) 
    41   "" 
     41  "Creates and returns a new escm-arity object by argspec." 
    4242  (let ((new (create-escm-arity)) 
    4343        (fields   ()) 
     
    6060 
    6161(defsubst escm-arity::inject-args! (self env args) 
     62  "Inject values of the ARGS into the given ENV by the SELF spec." 
    6263  (let ((p        (escm-arity::get-length   self)) 
    6364        (at-least (escm-arity::get-at-least self))) 
  • lang/elisp/escm/trunk/escm-base.el

    r12594 r21628  
     1;;; escm-base.el ---  
     2 
     3;; Copyright (C) 2008  root 
     4 
     5;; Author: root <root@localhost.localdomain> 
     6;; Keywords:  
     7 
     8;; This file is free software; you can redistribute it and/or modify 
     9;; it under the terms of the GNU General Public License as published by 
     10;; the Free Software Foundation; either version 3, or (at your option) 
     11;; any later version. 
     12 
     13;; This file is distributed in the hope that it will be useful, 
     14;; but WITHOUT ANY WARRANTY; without even the implied warranty of 
     15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     16;; GNU General Public License for more details. 
     17 
     18;; You should have received a copy of the GNU General Public License 
     19;; along with GNU Emacs; see the file COPYING.  If not, write to 
     20;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
     21;; Boston, MA 02110-1301, USA. 
     22 
     23;;; Commentary: 
     24 
     25;;  
     26 
     27;;; Code: 
     28 
     29 
    130(require 'escm-util) 
    231(require 'escm-cbos) 
     
    1443  (escm-object::to-string self)) 
    1544 
    16  
    1745;; errors for escm 
    1846(escm-util::define-signals 
     
    2048   (escm-syntax-error  "") 
    2149   (escm-void-variable "") 
    22    (escm-unsupported   ""))) 
    23  
    24  
    25  
     50   (escm-unsupported   "") 
     51   (escm-syntax-pattern-expression-is-illegal ""))) 
    2652 
    2753;; variables 
     54(defconst escm-version          "0.01.01") 
    2855(defconst escm-compiler-version 0.01) 
    29 (defconst escm-icode::indent "" "") 
     56(defconst escm-icode::indent   "") 
    3057 
    3158;; utilities that only in this project. 
     
    4471 
    4572(provide 'escm-base) 
     73;;; escm-base.el ends here 
  • lang/elisp/escm/trunk/escm-cbos.el

    r12594 r21628  
    33;; Copyright (C) 2008  Free Software Foundation, Inc. 
    44 
    5 ;; Author: ;;; <onishi@THOTH> 
     5;; Author: ;;; <lieutar@1dk.jp> 
    66;; Keywords: oop 
    77 
     
    3535   (escm-cbos::error::no-such-method "No such method"))) 
    3636 
    37 (defconst escm-cbos::default-method nil) 
    38 (defconst escm-cbos::class-vmt      nil) 
    39 (defconst escm-cbos::class-fields   nil) 
     37(defgroup escm-cbos () "" 
     38  :group 'programming 
     39  ) 
     40 
     41(defconst escm-cbos::default-method nil 
     42  "The symbol for the plist that is used as dictionary for methods.") 
     43 
     44(defconst escm-cbos::class-vmt      nil 
     45  "The symbol for the plist that is used as virtual method table.") 
     46 
     47(defconst escm-cbos::class-fields   nil 
     48  "The symbol for the plist that is used as dictionary of specification of fields of classes.") 
    4049 
    4150(defsubst escm-cbos::classp (sym) 
    42   "returns true if sym is escm::cbos class." 
     51  "Returns true if sym is escm::cbos class." 
    4352  (and (symbolp sym) 
    4453       (plist-member (symbol-plist 'escm-cbos::class-fields) sym) 
    4554       t)) 
    4655 
    47 (defsubst escm-cbos::get-class (obj) 
    48   "" 
    49   (and (arrayp obj) 
    50        (< 0 (length obj)) 
    51        (let ((cls (aref obj 0))) 
     56(defsubst escm-cbos::get-class (object) 
     57  "Returns symbol of a class name from escm-cbos OBJECT." 
     58  (and (arrayp object) 
     59       (< 0 (length object)) 
     60       (let ((cls (aref object 0))) 
    5261         (when (escm-cbos::classp cls) 
    5362           cls)))) 
     
    5665 
    5766(defsubst escm-cbos::inheritance-list (class) 
    58   "" 
     67  "Returns list that contains classes. 
     68 The list contains ancestor of the given CLASS and itself. 
     69" 
    5970  (when (escm-cbos::classp class) 
    6071    (symbol-value (get 'escm-cbos::class-vmt class)))) 
    6172 
    6273(defsubst escm-cbos::get-fields-of (class) 
    63   "" 
     74  "Returns symbols of the fields of the CLASS." 
    6475  (get 'escm-cbos::class-fields class)) 
    6576 
     
    8697 
    8798(defun escm-cbos::register-class  (name super fields) 
     99  "" 
    88100  (eval (cdr (escm-cbos::make-class-info name super fields)))) 
    89101 
    90102(defmacro escm-cbos::define-method (class name args &rest body) 
    91   "defines method of escm-cbos objects."    
     103  "Defines method of escm-cbos objects."    
    92104  `(progn 
    93105     (when (not (fboundp ',name)) 
     
    109121 
    110122 
     123 
    111124(defmacro escm-cbos::delete-method (class name) 
    112125  "" 
    113   (put (get 'escm-cbos::class-vmt ',class) ',name nil)) 
     126  `(put (get 'escm-cbos::class-vmt ',class) ',name nil)) 
    114127 
    115128(defsubst escm-cbos::find-method1 (sym name) 
     129  "" 
    116130  (let ((meth  nil) 
    117131        (ilist (symbol-value sym))) 
     
    123137 
    124138(defun escm-cbos::find-method (class method-name) 
     139  "" 
    125140  (let ((ilist (escm-cbos::inheritance-list class))) 
    126141    (escm-cbos::find-method1 'ilist method-name))) 
    127142 
    128143(defsubst escm-cbos::run-method (name obj args) 
     144  "" 
    129145  (let* ((class (escm-cbos::get-class obj)) 
    130146         (ilist (symbol-value (get 'escm-cbos::class-vmt class))) 
     
    139155 
    140156 
    141  
    142157(defun escm-cbos::expand-method (args body) 
     158  "" 
    143159  `(lambda ,(cons '*ilist* (cons '*method-name*  args)) 
    144160     ,@(escm-util::walk-node 
    145161        (lambda (x) 
    146162          (if (listp x) 
    147               (cond ((eq 'super (car x)) 
     163            (cond ((eq 'super (car x)) 
    148164                     `(apply 
    149165                       (or (escm-cbos::find-method '*ilist* *method-name*) 
     
    165181 
    166182(defun escm-cbos::make-accessor (spec p) 
     183  "" 
    167184  (let* ((spec      (if (listp spec) spec (list spec))) 
    168185         (f         (car spec)) 
     
    193210" 
    194211  (let* ((name      (car inhspec)) 
    195          (super     (or (cadr inhspec) 'escm-cbos::Object)) 
     212         (super     (or (cadr inhspec) 
     213                        'escm-cbos::Object)) 
     214         (document  (or (caddr inhspec) 
     215                        "undocumented class.")) 
    196216         (classinfo (escm-cbos::make-class-info name super fields)) 
    197217         (fields    (car classinfo)) 
     
    199219         (new       (intern (format "create-%s" name))) 
    200220         (pred      (intern (format "%s-p"      name)))) 
     221 
    201222    `(progn 
    202223       ,(cdr classinfo) 
     224 
     225       (defvar ,name ',name ,document) 
     226 
    203227       (defsubst ,new () 
    204228         (let ((new (make-vector ,(+ 1 len) nil))) 
     
    220244     (:foreground "black" :background "white")) 
    221245</