projects
/
hs-java.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some documentation.
[hs-java.git]
/
TestGen.hs
diff --git
a/TestGen.hs
b/TestGen.hs
index 0e5ff90184b7f05fea5e31c167707559e8f24554..c8cd0ef3c91578696e3db0355efc384f76225343 100644
(file)
--- a/
TestGen.hs
+++ b/
TestGen.hs
@@
-14,10
+14,13
@@
import qualified Java.IO
test :: Generate ()
test = do
withClassPath $ do
test :: Generate ()
test = do
withClassPath $ do
+ -- Add current directory (with Hello.class) to ClassPath
addDirectory "."
addDirectory "."
+ -- Load method signature: Hello.hello()
helloJava <- getClassMethod "./Hello" "hello"
helloJava <- getClassMethod "./Hello" "hello"
+ -- Initializer method. Just calls java.lang.Object.<init>
newMethod [ACC_PUBLIC] "<init>" [] ReturnsVoid $ do
setStackSize 1
newMethod [ACC_PUBLIC] "<init>" [] ReturnsVoid $ do
setStackSize 1
@@
-25,6
+28,7
@@
test = do
invokeSpecial Java.Lang.object Java.Lang.objectInit
i0 RETURN
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
hello <- newMethod [ACC_PUBLIC, ACC_STATIC] "hello" [IntType] ReturnsVoid $ do
setStackSize 8
@@
-45,15
+49,18
@@
test = do
pop
i0 RETURN
pop
i0 RETURN
+ -- Main class method.
newMethod [ACC_PUBLIC, ACC_STATIC] "main" [arrayOf Java.Lang.stringClass] ReturnsVoid $ do
setStackSize 1
iconst_5
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 ()
invokeStatic "Test" hello
i0 RETURN
return ()
+main :: IO ()
main = do
testClass <- generate [] "Test" test
B.writeFile "Test.class" (encodeClass testClass)
main = do
testClass <- generate [] "Test" test
B.writeFile "Test.class" (encodeClass testClass)