Permalink
Browse files

Added basic test script

darcs-hash:20060722121818-974a0-8bc37a91af88c8e3b4c7d0a81946f81724867873.gz
  • Loading branch information...
eb
eb committed Jul 22, 2006
1 parent c669db8 commit 6e4fec4db6eb7a803ef97a958a82afb3d16c237a
Showing with 253 additions and 0 deletions.
  1. +3 −0 Makefile
  2. +2 −0 tests/Makefile
  3. +39 −0 tests/adder.e
  4. +7 −0 tests/expected
  5. +7 −0 tests/hworld.e
  6. +8 −0 tests/intthing.e
  7. +45 −0 tests/listy.e
  8. +61 −0 tests/tailcall.e
  9. +51 −0 tests/tailfact.e
  10. +30 −0 tests/test.pl
View
@@ -27,6 +27,9 @@ clean:
$(MAKE) -C evm clean
cd ESC; rm -f *.o *.hi esc
+test:
+ make -C tests
+
esc: .PHONY package install
cd ESC; ghc $(GHCOPTS) --make Main.lhs -o esc -package epivm
View
@@ -0,0 +1,2 @@
+test:
+ perl test.pl
View
@@ -0,0 +1,39 @@
+main () -> Unit =
+ print(natToInt(adder(three, two, three, four, five)))
+
+adder (arity:Data, acc:Data) -> Any =
+ case arity of {
+ Con 0 () -> acc
+ | Con 1 (k:Data) -> adderAux(k, acc)
+ }
+
+adderAux (k:Data, acc:Data, n:Data) -> Any =
+ adder(k,plus(acc,n))
+
+zero () -> Data = Con 0 ()
+one () -> Data = Con 1 (zero)
+two () -> Data = Con 1 (one)
+three () -> Data = Con 1 (two)
+four () -> Data = Con 1 (three)
+five () -> Data = Con 1 (four)
+six () -> Data = Con 1 (five)
+seven () -> Data = Con 1 (six)
+eight () -> Data = Con 1 (seven)
+nine () -> Data = Con 1 (eight)
+ten () -> Data = Con 1 (nine)
+
+print (x:Int) -> Unit =
+ let foo:Unit = foreign Unit "printInt" (x:Int) in unit
+
+natToInt (x:Data) -> Int =
+ case x of {
+ Con 0 () -> 0
+ | Con 1 (k:Data) -> 1+natToInt(k)
+ }
+
+plus (x:Data, y:Data) -> Data =
+ case x of {
+ Con 0 () -> y
+ | Con 1 (k:Data) -> Con 1 (plus(k, y))
+ }
+
View
@@ -0,0 +1,7 @@
+
+14
+Hello world!
+362880
+1, 1, 1, nil
+362880
+362880
View
@@ -0,0 +1,7 @@
+putStr (x:String) -> Unit =
+ foreign Unit "putStr" (x:String)
+
+main () -> Unit =
+ putStr("Hello world!\n")
+
+
View
@@ -0,0 +1,8 @@
+print (x:Int) -> Unit =
+ let foo:Unit = foreign Unit "printInt" (x:Int) in unit
+
+main () -> Unit =
+ print(foo(9))
+
+foo (x:Int) -> Int =
+ if x<=0 then 1 else x*foo(x-1)
View
@@ -0,0 +1,45 @@
+%include "string.h"
+
+main () -> Unit = let foo:Unit = printList(take(3,ones)) in unit
+
+take (i:Int, x:Data) -> Data
+ = if (i==0) then Con 0 () else
+ case x of {
+ Con 0 () -> Con 0 ()
+ | Con 1 (y:Any,ys:Data) -> Con 1 (y, take(i-1, ys))
+ }
+
+testList () -> Data
+ = Con 1 (1, Con 1 (2, Con 1 (3, Con 1 (4, Con 1 (5, Con 0 ())))))
+
+ones () -> Data
+ = Con 1 (1, lazy(ones)) -- needs to be lazy or it runs forever!
+
+{- IO stuff -}
+
+printList (x:Data) -> Data
+ = case x of {
+ Con 1 (y:Int, ys:Data) ->
+ let foo:Unit = putStr(append(intToStr(y),", ")) in
+ printList(ys)
+ | Con 0 () -> putStrLn("nil")
+ }
+
+putStr (x:String) -> Unit =
+ foreign Unit "putStr" (x:String)
+
+putStrLn (x:String) -> Unit =
+ putStr(append(x,"\n"))
+
+readStr () -> String =
+ foreign String "readStr" ()
+
+append (x:String, y:String) -> String =
+ foreign String "append" (x:String, y:String)
+
+length (x:String) -> String =
+ foreign Int "strlen" (x:String)
+
+intToStr (x:Int) -> String =
+ foreign String "intToStr" (x:Int)
+
View
@@ -0,0 +1,61 @@
+{- Depending how much memory you have, you may need to reduce 'nine' -}
+
+main () -> Unit =
+ print(natToInt(fact(nine)))
+
+readStr () -> String =
+ foreign String "readStr" ()
+
+
+natrec (x:Data, z:Any, s:Fun) -> Any = natrectail(x,s,z)
+
+natrectail (x:Data, s:Fun, acc:Data) -> Any =
+ case x of {
+ Con 0 () -> acc
+ | Con 1 (k:Data) -> natrectail(k,s,s(k,acc))
+ }
+
+zero () -> Data = Con 0 ()
+one () -> Data = Con 1 (zero)
+two () -> Data = Con 1 (one)
+three () -> Data = Con 1 (two)
+four () -> Data = Con 1 (three)
+five () -> Data = Con 1 (four)
+six () -> Data = Con 1 (five)
+seven () -> Data = Con 1 (six)
+eight () -> Data = Con 1 (seven)
+nine () -> Data = Con 1 (eight)
+ten () -> Data = Con 1 (nine)
+
+print (x:Int) -> Unit =
+ let foo:Unit = foreign Unit "printInt" (x:Int) in unit
+
+{-
+natToInt (x:Data) -> Int =
+ case x of {
+ Con 0 () -> 0
+ | Con 1 (k:Data) -> 1+natToInt(k)
+ }
+-}
+
+natToInt (x:Data) -> Int =
+ natrec(x,0,n2isuc)
+
+n2isuc (k:Data, ih:Int) -> Int = 1+ih
+
+plus (x:Data, y:Data) -> Data =
+ natrec(x,y,plussuc)
+
+plussuc (k:Data, ih:Data) -> Data = Con 1 (ih)
+
+mult (x:Data, y:Data) -> Data =
+ natrec(x, Con 0 (), multsuc(y))
+
+multsuc (y:Data, k:Data, ih:Data) -> Data = plus(y, ih)
+
+fact (x:Data) -> Data =
+ case x of {
+ Con 0 () -> one()
+ | Con 1 (k:Data) -> mult(x, fact(k))
+ }
+
View
@@ -0,0 +1,51 @@
+{- Depending how much memory you have, you may need to reduce 'nine' -}
+
+main () -> Unit =
+ print(natToInt(fact(nine)))
+
+zero () -> Data = Con 0 ()
+one () -> Data = Con 1 (zero)
+two () -> Data = Con 1 (one)
+three () -> Data = Con 1 (two)
+four () -> Data = Con 1 (three)
+five () -> Data = Con 1 (four)
+six () -> Data = Con 1 (five)
+seven () -> Data = Con 1 (six)
+eight () -> Data = Con 1 (seven)
+nine () -> Data = Con 1 (eight)
+ten () -> Data = Con 1 (nine)
+
+print (x:Int) -> Unit =
+ let foo:Unit = foreign Unit "printInt" (x:Int) in unit
+
+natToInt(x:Data) -> Int = auxnatToInt(x,0)
+
+auxnatToInt (x:Data, acc:Int) -> Int =
+ case x of {
+ Con 0 () -> acc
+ | Con 1 (k:Data) -> auxnatToInt(k,1+acc)
+ }
+
+plus (x:Data, y:Data) -> Data =
+ case x of {
+ Con 0 () -> y
+ | Con 1 (k:Data) -> plus(k, Con 1 (y))
+ }
+
+mult(x:Data,y:Data) -> Data = auxmult(x,y,Con 0 ())
+
+auxmult (x:Data, y:Data, acc:Data) -> Data =
+ case x of {
+ Con 0 () -> acc
+ | Con 1 (k:Data) -> auxmult(k, y, plus(y, acc))
+ }
+
+fact (x:Data) -> Data =
+ case x of {
+ Con 0 () -> one()
+ | Con 1 (k:Data) -> mult(x, fact(k))
+ }
+
+apply (f:Fun, a:Any) -> Any =
+ f(a)
+
View
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+# Pretty basic testing - build and run all the .e files in the directory
+# and check that they give the expected output
+
+opendir DIR, ".";
+@files = readdir DIR;
+closedir DIR;
+
+system("echo \"\" > output");
+
+foreach $file (@files) {
+ if ($file=~/([^\.]+)\.e/) {
+ print "$file...\n";
+ system("esc $file >> output");
+ system("./$1 >> output");
+ system("rm $1");
+ }
+}
+
+$output = `cat output`;
+$expected = `cat expected`;
+
+print $output;
+
+if ($output ne $expected) {
+ print "ERRORS!!!!!\n";
+} else {
+ print "All OK\n";
+}

0 comments on commit 6e4fec4

Please sign in to comment.