X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=hs-java.git;a=blobdiff_plain;f=TestGen.hs;h=c8cd0ef3c91578696e3db0355efc384f76225343;hp=0e5ff90184b7f05fea5e31c167707559e8f24554;hb=68480a027565cce928726f5aaa6b6a6e9638617f;hpb=59fdc71dedd2203ebd919ab2edad6a867c68dcb8 diff --git a/TestGen.hs b/TestGen.hs index 0e5ff90..c8cd0ef 100644 --- a/TestGen.hs +++ b/TestGen.hs @@ -14,10 +14,13 @@ import qualified Java.IO test :: Generate () test = do withClassPath $ do + -- Add current directory (with Hello.class) to ClassPath addDirectory "." + -- Load method signature: Hello.hello() helloJava <- getClassMethod "./Hello" "hello" + -- Initializer method. Just calls java.lang.Object. newMethod [ACC_PUBLIC] "" [] ReturnsVoid $ do setStackSize 1 @@ -25,6 +28,7 @@ test = do invokeSpecial Java.Lang.object Java.Lang.objectInit i0 RETURN + -- Declare hello() method and bind it's signature to hello. hello <- newMethod [ACC_PUBLIC, ACC_STATIC] "hello" [IntType] ReturnsVoid $ do setStackSize 8 @@ -45,15 +49,18 @@ test = do pop i0 RETURN + -- Main class method. newMethod [ACC_PUBLIC, ACC_STATIC] "main" [arrayOf Java.Lang.stringClass] ReturnsVoid $ do setStackSize 1 iconst_5 + -- Call previously declared method invokeStatic "Test" hello i0 RETURN return () +main :: IO () main = do testClass <- generate [] "Test" test B.writeFile "Test.class" (encodeClass testClass)