From 66501b5950881002845adee90c609ae64594a8b9 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 25 Apr 2012 22:47:47 +0200 Subject: [PATCH] java.io: PrintStream --- Makefile | 4 +++- Mate/BasicBlocks.hs | 1 + Mate/Utilities.hs | 1 + Mate/X86CodeGen.hs | 1 + ffi/native.c | 5 +++++ java/io/PrintStream.java | 6 ++++++ java/lang/System.java | 7 +++++++ tests/Native2.java | 7 +++++++ 8 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 java/io/PrintStream.java create mode 100644 java/lang/System.java create mode 100644 tests/Native2.java diff --git a/Makefile b/Makefile index 3353137..2b4182d 100644 --- 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) $< diff --git a/Mate/BasicBlocks.hs b/Mate/BasicBlocks.hs index 229325d..c5d9743 100644 --- a/Mate/BasicBlocks.hs +++ b/Mate/BasicBlocks.hs @@ -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 diff --git a/Mate/Utilities.hs b/Mate/Utilities.hs index 4ede7ba..208a096 100644 --- a/Mate/Utilities.hs +++ b/Mate/Utilities.hs @@ -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 diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 2c4e70e..2db7a97 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -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 diff --git a/ffi/native.c b/ffi/native.c index f335c5c..25c159a 100644 --- a/ffi/native.c +++ b/ffi/native.c @@ -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 index 0000000..89fe534 --- /dev/null +++ b/java/io/PrintStream.java @@ -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 index 0000000..38b62dd --- /dev/null +++ b/java/lang/System.java @@ -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 index 0000000..0c3c701 --- /dev/null +++ b/tests/Native2.java @@ -0,0 +1,7 @@ +package tests; + +public class Native2 { + public static void main(String []args) { + System.out.printf(0x1337); + } +} -- 2.25.1