java.io: PrintStream
authorBernhard Urban <lewurm@gmail.com>
Wed, 25 Apr 2012 20:47:47 +0000 (22:47 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 25 Apr 2012 21:53:09 +0000 (23:53 +0200)
Makefile
Mate/BasicBlocks.hs
Mate/Utilities.hs
Mate/X86CodeGen.hs
ffi/native.c
java/io/PrintStream.java [new file with mode: 0644]
java/lang/System.java [new file with mode: 0644]
tests/Native2.java [new file with mode: 0644]

index 335313767b402dc43dd49d18818183e062534b3c..2b4182d46c57c28e13e35a28701e2d9884639e1d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 SHELL := bash
 
 JAVAC := javac
-JAVA_FILES := $(wildcard tests/*.java)
+JAVA_FILES := $(wildcard tests/*.java java/lang/*.java java/io/*.java)
 CLASS_FILES := $(JAVA_FILES:.java=.class)
 HS_FILES := $(wildcard Mate/*.hs)
 HS_BOOT := $(wildcard Mate/*.hs-boot)
@@ -58,6 +58,8 @@ test: mate $(CLASS_FILES)
        @printf "should be:  0x%08x 0x%08x\n" 0x33 0x44
        ./$< tests/Instance4 | grep mainresult
        @printf "should be:  0x%08x 0x%08x\n" 0x1337 0x1337
+       ./$< tests/Native2 | grep "printstream"
+       @printf "should be:   0x%08x\n" 0x1337
 
 %.class: %.java
        $(JAVAC) $<
index 229325d6a36423514d95f29dee312746a215854b..c5d974330e42129f7f11fc9d2901365590e99915 100644 (file)
@@ -171,6 +171,7 @@ calculateInstructionOffset = cio' (0, Nothing)
       IF_ICMP _ w16 -> twotargets w16
       GOTO w16 -> onetarget w16
       IRETURN -> notarget
+      ARETURN -> notarget
       RETURN -> notarget
       _ -> ((off, Nothing), x):next
     where
index 4ede7ba61b0779871b7b28ca3e04a769fb299b8f..208a09617a2c1d4fbec81355a710d77b5e8a852d 100644 (file)
@@ -47,6 +47,7 @@ methodHaveReturnValue :: Class Resolved -> Word16 -> Bool
 methodHaveReturnValue cls idx = case ret of
     ReturnsVoid -> False;
     (Returns IntType) -> True;
+    (Returns (ObjectType _)) -> True;
     _ -> error "methodHaveReturnValue: todo"
   where
   (CMethod _ nt) = (constsPool cls) M.! idx
index 2c4e70e907289e4c87fd8326e6a66b6802697f64..2db7a979a0ad5730748325ccdca3b4ad3a1b7ba9 100644 (file)
@@ -312,6 +312,7 @@ emitFromBB method cls hmap =  do
         jmp $ getLabel sid lmap
 
     emit RETURN = do mov esp ebp; pop ebp; ret
+    emit ARETURN = emit IRETURN
     emit IRETURN = do
         pop eax
         mov esp ebp
index f335c5cf0d81cb87c8f7398ff3f0cc1308b611a7..25c159adef1b840672eb888f2e93833a30e81c3b 100644 (file)
@@ -14,3 +14,8 @@ void tests_Instance5__printX___I_V(int a)
 {
        printf("printX: 0x%08x\n", a);
 }
+
+void java_io_PrintStream__printf___I_V(int a)
+{
+       printf("printstream: 0x%08x\n", a);
+}
diff --git a/java/io/PrintStream.java b/java/io/PrintStream.java
new file mode 100644 (file)
index 0000000..89fe534
--- /dev/null
@@ -0,0 +1,6 @@
+package java.io;
+
+public class PrintStream {
+       public native void printf(int a);
+       public native void println(String a);
+}
diff --git a/java/lang/System.java b/java/lang/System.java
new file mode 100644 (file)
index 0000000..38b62dd
--- /dev/null
@@ -0,0 +1,7 @@
+package java.lang;
+
+import java.io.*;
+
+public class System {
+       public static PrintStream out = new PrintStream();
+}
diff --git a/tests/Native2.java b/tests/Native2.java
new file mode 100644 (file)
index 0000000..0c3c701
--- /dev/null
@@ -0,0 +1,7 @@
+package tests;
+
+public class Native2 {
+       public static void main(String []args) {
+               System.out.printf(0x1337);
+       }
+}