忍者ブログ

LAL 昭和な気まぐれ飛行機

LALのブログです。 http://eisl.kan-be.com/index.html

Easy-ISLisp Ver0.86

I updated Easy-ISLisp. It is ver0.86.
http://eisl.kan-be.com/library/easyislisp1.html

I added type inference to the compiler. It is still incomplete.
However, the compiler generates efficient code for the simple example below.
You can invoke type inference by giving the "type" symbol to the second argument of the compile-file function.
I am still improving type inference.


examples
(defun tarai(x y z)
  (the <fixnum> x)(the <fixnum> y)(the <fixnum> z)
  (if (<= x y)
      y
      (tarai (tarai (- x 1) y z)
             (tarai (- y 1) z x)
             (tarai (- z 1) x y))))

(defun fib (n)
  (the <fixnum> n)
  (cond ((= n 1) 1)
        ((= n 2) 1)
        (t (+ (fib (- n 1)) (fib (- n 2))))))

(defun fib* (n)
  (cond ((= n 1.0) 1.0)
        ((= n 2.0) 1.0)
        (t (+ (fib* (- n 1.0)) (fib* (- n 2.0))))))

(defun ack (m n)
  (the <fixnum> m)(the <fixnum> n)
  (cond ((= m 0)(+ n 1))
        ((= n 0)(ack (- m 1) 1))
        (t (ack (- m 1) (ack m (- n 1))))))
       
execution
kenichi@ubuntu:~/lineisl$ ./eisl -c compiler.lsp
Easy-ISLisp Ver0.86
> (compile-file "tarai.lsp" 'type)
inferencing PACK
inferencing TARAI
inferencing FIB
inferencing FIB*
inferencing ACK
inferencing TAK
inferencing LISTN
inferencing TAKL
inferencing CTAK
inferencing CTAK-AUX
initialize
pass1
pass2
compiling PACK
compiling TARAI
compiling FIB
compiling FIB*
compiling ACK
compiling GFIB
compiling TAK
compiling LISTN
compiling TAKL
compiling CTAK
compiling CTAK-AUX
finalize
invoke GCC
T
> (load "tarai.o")
T
> (time (tarai 12 6 0))
Elapsed Time(second)=0.024223
<undef>
> (time (fib 40))
Elapsed Time(second)=0.291127
<undef>
> (time (fib* 40.0))
Elapsed Time(second)=0.447728
<undef>
> (time (ack 4 1))
Elapsed Time(second)=3.797493
<undef>
>

And also...

I added a translater from M expression to S expression in the attached file of Easy-ISLisp.
http://eisl.kan-be.com/library/easyislisp1.html
The file name is "mexp.lsp".
The following is an example of it's execution.
I reproduced old-fashioned LISP.


kenichi@ubuntu:~/lineisl$ ./eisl
Easy-ISLisp Ver0.86
> (load "mexp.lsp")
T
> (mexp)
Meta expression translater
M> 1+2.
3
M> foo[x;y] <= x^2+y^2.
FOO
M> foo[2;3].
13
M> fact[n] <= [=[n;0] -> 1;t -> n*fact[n-1]].
FACT
M> fact[10].
3628800
M> quit[].
T
>
PR

コメント

プロフィール

HN:
笹川
性別:
非公開

最新記事

P R