all: mate $(CLASS_FILES)
test: mate $(CLASS_FILES)
- ./$< tests/Fib | grep mainresult
+ ./$< tests/While | grep -e "^result"
+ @printf "should be: 0x%08x 0x%08x\n" 0x19 0x19
+ ./$< tests/Fib | grep -e "^result"
@printf "should be: 0x%08x\n" 0x2ac2
- ./$< tests/Fac | grep mainresult
+ ./$< tests/Fac | grep -e "^result"
@printf "should be: 0x%08x\n" 0x63e1a
- ./$< tests/ArgumentPassing1 | grep mainresult
+ ./$< tests/ArgumentPassing1 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x92 $$(((0 - 0x1337) & 0xffffffff))
- ./$< tests/DifferentClass1 | grep mainresult
+ ./$< tests/DifferentClass1 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 8 13
- ./$< tests/Native1 | egrep -i -e '^printsomething: '
- @printf "should be: woot 0x%08x 0x%08x woot 0x%08x\n" 0x1337 0x1338 0x15a5
- ./$< tests/Static1 | grep mainresult
+ ./$< tests/Static1 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x33
- ./$< tests/Static2 | grep mainresult
+ ./$< tests/Static2 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x55
- ./$< tests/Static3 | grep mainresult
+ ./$< tests/Static3 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x6dd
- ./$< tests/Static4 | grep mainresult
+ ./$< tests/Static4 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x33 0x77
- ./$< tests/Static5 | grep mainresult
+ ./$< tests/Static5 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x33 0x33
- ./$< tests/Static6 | grep mainresult
+ ./$< tests/Static6 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x33
- ./$< tests/Static7 | grep mainresult
+ ./$< tests/Static7 | grep -e "^result"
@printf "should be: 0x%08x\n" $$((0x1337 + 0x555))
- ./$< tests/Static8 | grep mainresult
+ ./$< tests/Static8 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x33 $$((0x1337 + 0x555))
- ./$< tests/CallConv1 | grep mainresult
+ ./$< tests/CallConv1 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x1337
- ./$< tests/CallConv2 | grep mainresult
+ ./$< tests/CallConv2 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x1337
- ./$< tests/CallConv3 | grep mainresult
+ ./$< tests/CallConv3 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x 0x%08x 0x%08x\n" 0x1000 0x300 0x30 0x7
- ./$< tests/Instance1 | grep mainresult
+ ./$< tests/Instance1 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x55 0x11
- ./$< tests/Instance2 | grep mainresult
+ ./$< tests/Instance2 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x198 0x22
- ./$< tests/Instance3 | grep mainresult
+ ./$< tests/Instance3 | grep -e "^result"
@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"
+ ./$< tests/Native2 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x1337
- ./$< tests/Native3 | egrep -e "^Hello World"
+ ./$< tests/Native3 | egrep -e "^result"
@printf "should be: %s\n" "Hello World"
- ./$< tests/Strings1 | egrep -c -e "^okay :-\)"
+ ./$< tests/Strings1 | egrep -c -e "^result"
@printf "should be: %d\n" 3
- ./$< tests/Array1 | grep "printstream"
+ ./$< tests/Array1 | grep -e "^result"
@printf "should be: 0x%08x 0x%08x\n" 0x264 0x8
- ./$< tests/Integer1 | grep mainresult
+ ./$< tests/Integer1 | grep -e "^result"
@printf "should be: 0x%08x\n" 0x1337
- ./$< tests/VarArgs1 | grep mainresult
+ ./$< tests/VarArgs1 | grep -e "^result"
%.class: %.java
$(JAVAC) $<
emit' insn = emit insn >> return Nothing
emit :: J.Instruction -> CodeGen e s ()
- emit POP = do -- print dropped value
- calladdr <- getCurrentOffset
- -- '5' is the size of the `call' instruction ( + immediate)
- let w32_calladdr = 5 + calladdr
- let trapaddr = (fromIntegral getaddr :: Word32)
- call (trapaddr - w32_calladdr)
+ emit POP = do -- dropp value
add esp (4 :: Word32)
emit DUP = push (Disp 0, esp)
emit AASTORE = emit IASTORE
-public class AbsurdlyHuge
-{
-public static int absurdlyHuge(int x)
-{
-for(int i=0;i<x;i++)
-{
-for(int u=0;u<x;u++)
-{
-for(int k=0;k<x;k++)
-{
-for(int v=0;v<x;v++)
-{
-for(int w=0;w<x;w++)
-{
-for(int z=0;z<x;z++)
-{
-for(int g=0;w<x;w++)
-{
-if(i+u+k+v+w+z<x)
-{
-return absurdlyHuge(k+v);
-}
-else
-{
-return absurdlyHuge(w+z);
-}
-}
-}
-}
-}
-}
-}
-}
-return 0;
-}
+package tests;
+
+public class AbsurdlyHuge {
+ public static int absurdlyHuge(int x) {
+ for(int i=0;i<x;i++) {
+ for(int u=0;u<x;u++) {
+ for(int k=0;k<x;k++) {
+ for(int v=0;v<x;v++) {
+ for(int w=0;w<x;w++) {
+ for(int z=0;z<x;z++) {
+ for(int g=0;w<x;w++) {
+ if(i+u+k+v+w+z<x) {
+ return absurdlyHuge(k+v);
+ } else {
+ return absurdlyHuge(w+z);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return 0;
+ }
- public static void main(String[] args)
- {
- absurdlyHuge(1);
- }
+ public static void main(String[] args) {
+ System.out.printf("result: 0x%08x\n", absurdlyHuge(1));
+ }
}
public class ArgumentPassing1 {
public static void main(String []args) {
- myadder(23, 4, 0x77); // 0x92
+ System.out.printf("result: 0x%08x\n", myadder(23, 4, 0x77)); // 0x92
noreturn(23, 4, 0x77); // nothing
- noargs(); // 0x1337
+ System.out.printf("result: 0x%08x\n", noargs()); // 0x1337
}
public static int myadder(int a, int b, int c) {
for (int i = 0; i < 0x8; i++) {
sum += arr[i];
}
- System.out.printf(sum); // 0x264
- System.out.printf(arr.length); // 0x8
+ System.out.printf("result: 0x%08x\n", sum); // 0x264
+ System.out.printf("result: 0x%08x\n", arr.length); // 0x8
}
}
public static void main(String []args) {
int sum = 0;
sum += manyVars(0x1348);
- id(sum); // 0x1337
- }
-
- public static int id(int a) {
- return a;
+ System.out.printf("result: 0x%08x\n", sum);
}
public static int manyVars(int a) {
public static void main(String []args) {
int sum = 0;
sum += manyVars(0x125A, 0x11, 0x33, 0x44);
- id(sum); // 0x1337
- }
-
- public static int id(int a) {
- return a;
+ System.out.printf("result: 0x%08x\n", sum);
}
public static int manyVars(int a, int b, int c, int d) {
public class CallConv3 {
public static void main(String []args) {
- manyVars_A(0x1000, 0x300, 0x30, 0x7);
- manyVars_B(0x1000, 0x300, 0x30, 0x7);
- manyVars_C(0x1000, 0x300, 0x30, 0x7);
- manyVars_D(0x1000, 0x300, 0x30, 0x7);
+ System.out.printf("result: 0x%08x\n", manyVars_A(0x1000, 0x300, 0x30, 0x7));
+ System.out.printf("result: 0x%08x\n", manyVars_B(0x1000, 0x300, 0x30, 0x7));
+ System.out.printf("result: 0x%08x\n", manyVars_C(0x1000, 0x300, 0x30, 0x7));
+ System.out.printf("result: 0x%08x\n", manyVars_D(0x1000, 0x300, 0x30, 0x7));
}
public static int manyVars_A(int a, int b, int c, int d) {
public class DifferentClass1 {
public static void main(String[] args) {
- Fib.fib(5);
- Fib.fib(6);
+ System.out.printf("result: 0x%08x\n", Fib.fib(5));
+ System.out.printf("result: 0x%08x\n", Fib.fib(6));
}
}
public static void main(String args[]) {
int sum = 0;
for (int i = 0; i < 10; i++) {
- // fac(i);
sum += fac(i);
}
- id(sum);
- // System.out.printf("fac: 0x%08x\n", sum);
- }
-
- public static int id(int i) {
- return i;
+ System.out.printf("result: 0x%08x\n", sum);
+ // System.out.printf("result: 0x%08x\n", facFor(0x10));
}
public static int fac(int a) {
return b;
}
- public static int facFor(int n){
- int p = 1;
- for(int i=1;i<=n;i++)
- {
- p = p * i;
+ public static int facFor(int n) {
+ int p = 1;
+ for(int i = 1; i <= n; i++) {
+ p *= i;
}
return p;
}
public class Fib {
public static int fib(int n) {
- if(n<=1) return 1;
- else return fib(n-1) + fib(n-2);
+ if (n <= 1)
+ return 1;
+ else
+ return fib(n - 1) + fib(n - 2);
}
public static void main(String[] args) {
- fib(20);
- // System.out.printf("%x\n", fib(20));
+ System.out.printf("result: 0x%08x\n", fib(20));
}
}
id(a.x); // 0x11
}
- public static int id(int a) {
- // System.out.printf("0x%08x\n", a);
- return a;
+ public static void id(int a) {
+ System.out.printf("result: 0x%08x\n", a);
}
}
b.x = 0x22; sum += b.x; // 0x22
b.y = 0x33; sum += b.y; // 0x33
Instance1.id(sum); // 0x198
- b.getX(); // 0x22
+ System.out.printf("0x%08x\n", b.getX()); // 0x22
}
public int getX() {
int sum = 0;
Instance3 a = new Instance3();
a.setX(0x33);
- a.getX(); // 0x33
+ System.out.printf("result: 0x%08x\n", a.getX()); // 0x33
a.setX(0x44);
- a.getX(); // 0x44
+ System.out.printf("result: 0x%08x\n", a.getX()); // 0x44
}
}
+++ /dev/null
-package tests;
-
-public class Instance4 extends Instance2 {
- public Instance4() {
- x = 0x11;
- y = 0x22;
- }
-
- public static void main(String []args) {
- Instance2 a = new Instance4();
- a.getX(); // 0x1337
- Instance4 b = (Instance4) a;
- b.getX(); // 0x1337;
- }
-
- public int getX() {
- return 0x1337;
- }
-}
+++ /dev/null
-package tests;
-
-public class Instance5 {
- public int x;
- public Instance5() {
- x = 0x11;
- }
-
- public static void main(String []args) {
- Instance5 a = new Instance5();
-
- a.setX(0x1337);
- a.printX(a.x);
- }
-
- public void setX(int a) {
- this.x = a;
- }
-
- public native void printX(int x);
-}
public class Integer1 {
public static void main(String []args) {
Integer a = new Integer(0x1337);
- a.intValue(); // 0x1337
+ System.out.printf("result: 0x%08x\n", a.intValue()); // 0x1337
}
}
+++ /dev/null
-package tests;
-
-public class Native1 {
- public static void main(String []args) {
- printSomething();
- for (int i = 0; i < 2; i++)
- printNumber(0x1337 + i);
- printSomething();
- printNumber(0x15a5);
- }
-
- public static void printNumber(int a) {
- printSomething(a);
- }
-
- public static native void printSomething();
- public static native void printSomething(int a);
-}
public class Native2 {
public static void main(String []args) {
- System.out.printf(0x1337);
+ System.out.printf("result: 0x%08x\n", 0x1337);
}
}
public class Native3 {
public static void main(String []args) {
- System.out.println("Hello World");
+ System.out.println("result: Hello World");
}
}
public static void main(String []args) {
setNumbers();
- addNumbers(); // 0x33
+ System.out.printf("result: 0x%08x\n", addNumbers()); // 0x33
}
public static void setNumbers() {
// in Static2 as in Static1
Static1.x = 0x33;
Static1.y = 0x22;
- Static1.addNumbers();
+ System.out.printf("result: 0x%08x\n", Static1.addNumbers());
}
}
sum += Static1.addNumbers(); // 0x33
Static3.z = 0x11;
sum += Static3.addNumbers(); // 0x44
- getSum(); // 0x666 + 0x33 + 0x44 = 0x6dd
- // System.out.printf("%x\n", getSum());
+ System.out.printf("result: 0x%08x\n", getSum()); // 0x666 + 0x33 + 0x44 = 0x6dd
}
public static int getSum() {
public static void main(String []args) {
Static1.setNumbers();
Static4.setNumbers();
- Static1.addNumbers(); // 0x33
- // System.out.printf("%x\n", Static1.addNumbers());
- Static4.addNumbers(); // 0x77
- // System.out.printf("%x\n", Static4.addNumbers());
+ System.out.printf("result: 0x%08x\n", Static1.addNumbers()); // 0x33
+ System.out.printf("result: 0x%08x\n", Static4.addNumbers()); // 0x77
}
public static void setNumbers() {
public static void main(String []args) {
Static5.setNumbers();
- Static5.addNumbers(); // 0x33
- Static1.addNumbers(); // 0x33
- // System.out.printf("%x\n", Static5.addNumbers());
+ System.out.printf("result: 0x%08x\n", Static5.addNumbers()); // 0x33
+ System.out.printf("result: 0x%08x\n", Static1.addNumbers()); // 0x33
}
}
}
public static void main(String []args) {
- addNumbers(); // 0x33
+ System.out.printf("result: 0x%08x\n", addNumbers()); // 0x33
}
public static int addNumbers() {
}
public static void main(String []args) {
- addNumbers(); // 0x188c
- // System.out.printf("%x\n", addNumbers());
+ System.out.printf("result: 0x%08x\n", addNumbers()); // 0x188c
}
}
}
public static void main(String []args) {
- Static8.addNumbers(); // 0x188c
- // System.out.printf("%x\n", Static8.addNumbers());
+ System.out.printf("result: 0x%08x\n", Static8.addNumbers()); // 0x188c
}
}
static {
Static8_local.x = 0x11;
Static8_local.y = 0x22;
- Static8_local.addNumbers(); // 0x33
- // System.out.printf("%x\n", addNumbers());
+ System.out.printf("result: 0x%08x\n", addNumbers()); // 0x33
}
public static int addNumbers() {
String c = "wtf";
if (a == b) {
- System.out.println("okay :-)");
+ System.out.println("result: okay :-)");
} else {
- System.out.println("bad :-(");
+ System.out.println("result: bad :-(");
}
if (a != c) {
- System.out.println("okay :-)");
+ System.out.println("result: okay :-)");
} else {
- System.out.println("bad :-(");
+ System.out.println("result: bad :-(");
}
if (a == c) {
- System.out.println("bad :-(");
+ System.out.println("result: bad :-(");
} else {
- System.out.println("okay :-)");
+ System.out.println("result: okay :-)");
}
}
}
+++ /dev/null
-package tests;
-
-public class Test {
- private static int foo;
- private static int bar;
-
- public static void main(String [] args) {
- foo = 0x42;
- bar = 2 * foo;
- }
-}
package tests;
public class While {
+ public static void main(String []args) {
+ System.out.printf("result: f: 0x%08x\n", f(4, 6));
+ System.out.printf("result: g: 0x%08x\n", g(4, 6));
+ }
+
public static int f(int a, int b) {
do {
a += b;