示例#1
0
 def testevalu13(self):
     lisp = readLisp("(define add1 (lambda (a) (+ a 1)))")
     evall(lisp,self.env)
     
     lisp = readLisp("(add1 5)")
     val =  evall(lisp,self.env)
     self.assert_(val == LispInteger(6))
示例#2
0
 def testevalu14(self):
     lisp = readLisp("(define addSum1 (lambda (a b) (+ a b 1)))")
     evall(lisp,self.env)
     
     lisp = readLisp("(addSum1 5 6)")
     val =  evall(lisp,self.env)
     self.assert_(val == LispInteger(12))
示例#3
0
 def testevalu15(self):
     lisp = readLisp("(define somethingStrange (lambda (a b c d ) (+ a b 1 (- c b) (- c d a) (+ a (+ 1 2 c)))))")
     evall(lisp,self.env)
     
     lisp = readLisp("(somethingStrange 1 2 3 4)")
     val =  evall(lisp,self.env)
     evall(readLisp("(somethingStrange 44 33 88 8)"),self.env)
     self.assert_(val == LispInteger(10))
示例#4
0
    def testLambdaBegin(self):
        lisp = readLisp("(lambda (x) (- 5 x) (+ 5 x))")
        val = evall(lisp,self.env)
        self.assert_(isinstance(val,UserFunction))
        
        lisp = readLisp('(lambda (x) (print "Foobar") 5)')
        val = evall(lisp,self.env)
        self.assert_(isinstance(val,UserFunction))

        lisp = readLisp('((lambda (x) (print "Hallo Welt") (+ 5 x)) 5)')
        val = evall(lisp,self.env)
        self.assert_(val == LispInteger(10))
示例#5
0
 def testSet(self):
     lisp = readLisp("(set! a 555)")
     evall(lisp,self.env)
     self.assert_(self.env.get(new(LispSymbol,"a"))==LispInteger(555))
     lisp = readLisp("(set! ab 666)")
     try:
         evall(lisp,self.env)
         self.fail("Exception not thrown")
     except SymbolNotFound:
         pass
     
     lisp = readLisp('(set! a "Foo")')
     evall(lisp,self.env)
     self.assert_(self.env.get(new(LispSymbol,"a"))==LispString("Foo"))
示例#6
0
 def testByteCode(self):
     env = Enviroment()
     #func = evall(readLisp("(define a 5)"),env)
     
    # func = evall(readLisp("(define (foo x) (+ 5 x))"),env)
     lisp = readLisp("(define asd (lambda (x y z a) (+ x y z a x)))")
     func = evall(lisp,env)
     lisp = readLisp("(define foo (lambda (x) (asd x 2 3 4)))")
     func = evall(lisp,env)
     foo= evall(readLisp("(foo 1)"),env)
 #    result = evall(readLisp("(foo 3)"),env)
     print func
   #  print func.optcode
    # print func.bytecode
     #print func.literals
     print foo
示例#7
0
    def aatest_something_long_with_all_this_cool_set_and_closure_stuff(self):
        lispStr = '''
        (define (make-point x y)
  (define (get-x)
    x)
  (define (get-y)
    y)
  (define (set-x! newX)
    (set! x newX))
  (define (set-y! newY)
    (set! y newY))
  (define (area)
    (* x y))
  (define (error)
    (print "mist"))
    
      (define (dispatch op)
    (if (eq? op 'get-x)
        get-x
    (if (eq? op 'get-y)
        get-y
    (if (eq? op 'set-x!)
        set-x!
    (if (eq? op 'set-y!)
        set-y!
    (if (eq? op 'area)
        area
        error))))))
  
  dispatch)

        '''
        lisp= readLisp(lispStr)
        val= evall(lisp,self.env)
        val = evall(readLisp("(make-point 5 6)"),self.env)
        self.assert_(isinstance(val,UserFunction))
示例#8
0
 def testevalu4(self):
     lisp = readLisp("(+ 5 4)")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(9))
示例#9
0
 def testBegin(self):
     lisp = readLisp("(begin (+ 3 5) (+ 3 4))")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(7))
示例#10
0
 def testDefineBegin(self):
     lisp = readLisp('(define (foo x) (print "Hello World") (write "FOOOBAR") (- 5 2) (+ 5 1))')
     val = evall(lisp,self.env)
     lisp2 = readLisp("(foo 5)")
     val = evall(lisp2,self.env)
     self.assert_(val==LispInteger(6))
示例#11
0
 def testevalu12(self):
     lisp = readLisp("(lambda (a) (+ a 1))")
     val = evall(lisp,self.env)
     self.assert_(isinstance(val, UserFunction))
示例#12
0
 def testevalu11(self):
     lisp = readLisp("(if (eq? 5 5) (+ 5 6) (+ 4 3))")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(11))
示例#13
0
 def testevalu16(self):
     lisp = readLisp("(define (func a b) (+ a b))")
     evall(lisp,self.env)
     val= evall(readLisp("(func 10 20)"),self.env)
     self.assert_(val == LispInteger(30))
示例#14
0
def testLoop():
    lisp = readLisp("(loop 100)")
    for i in range(1000):
#    for i in range(1):
        evall(lisp,env)
示例#15
0
def testDefine():
    lisp = readLisp("(define (foo x) (+ x 3 4))")
    for i in range(10000):
        evall(lisp,env)
示例#16
0
 def testeval_begin_in_function(self):
     lisp = readLisp("(define foo (lambda (x) (begin (+ 4 3) (+ 2 3))))")
     val = evall(lisp,self.env)
     lisp2 = readLisp("(foo)")
     val = evall(lisp2,self.env)
     self.assert_(val == LispInteger(5))
示例#17
0
 def testeval_if_in_function_F(self):
     lisp = readLisp("((lambda (x) (if FALSE 5 6)))")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(6))
示例#18
0
 def testevalu3(self):
     lisp = readLisp("a")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(5))
示例#19
0
 def testevalu1(self):
     lisp = readLisp("4")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(4))
示例#20
0
 def testeval_if_in_function_with_complex_cond(self):
     lisp = readLisp("((lambda (x) (if (>? 4 3) (if (>? 3 5) (+ 3 2) (+ 5 9)) (+ 3 6))))")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(14))
示例#21
0
 def testevalu6(self):
     lisp = readLisp("(+ (+ a 4) 4 1)")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(14))
示例#22
0
from LISP.Eval import evall
from LISP.Reader import readLisp
from LISP import Enviroment
env = Enviroment();

def testPlus():
    lisp = readLisp("(+ 5 4)")
    for i in range(10000):
        val = evall(lisp,env)

def testDefine():
    lisp = readLisp("(define (foo x) (+ x 3 4))")
    for i in range(10000):
        evall(lisp,env)
        
lisp = readLisp("(define (foo x) (+ x 3 4))")
evall(lisp,env)
def testSomefunction():
    lisp=readLisp("(foo 5)")
    for i in range(1):
        evall(lisp,env)
        
lisp = readLisp("(define (loop n) (if (eq? n 1) 1 (loop (- n 1))))")
evall(lisp, env)
print "start"
def testLoop():
    lisp = readLisp("(loop 100)")
    for i in range(1000):
#    for i in range(1):
        evall(lisp,env)
def val1():    
示例#23
0
 def testevalu7(self):
     lisp = readLisp("(- 4 1)")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(3))
示例#24
0
def testSomefunction():
    lisp=readLisp("(foo 5)")
    for i in range(1):
        evall(lisp,env)
示例#25
0
 def testevalu8(self):
     evall(readLisp("(define xxx 666)"),self.env)
     lisp = readLisp("(- xxx 1)")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(665))
示例#26
0
def testPlus():
    lisp = readLisp("(+ 5 4)")
    for i in range(10000):
        val = evall(lisp,env)
示例#27
0
 def testevalu10(self):
     lisp = readLisp("(if FALSE (+ 5 6) (+ 4 3))")
     val = evall(lisp,self.env)
     self.assert_(val == LispInteger(7))