jaroslav@0
|
1 |
/*
|
jaroslav@0
|
2 |
Java 4 Browser Bytecode Translator
|
jaroslav@0
|
3 |
Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@0
|
4 |
|
jaroslav@0
|
5 |
This program is free software: you can redistribute it and/or modify
|
jaroslav@0
|
6 |
it under the terms of the GNU General Public License as published by
|
jaroslav@0
|
7 |
the Free Software Foundation, version 2 of the License.
|
jaroslav@0
|
8 |
|
jaroslav@0
|
9 |
This program is distributed in the hope that it will be useful,
|
jaroslav@0
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@0
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@0
|
12 |
GNU General Public License for more details.
|
jaroslav@0
|
13 |
|
jaroslav@0
|
14 |
You should have received a copy of the GNU General Public License
|
jaroslav@0
|
15 |
along with this program. Look for COPYING file in the top folder.
|
jaroslav@0
|
16 |
If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@0
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@0
|
19 |
|
jaroslav@0
|
20 |
/**
|
jaroslav@0
|
21 |
*
|
jaroslav@0
|
22 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
23 |
*/
|
jaroslav@0
|
24 |
public class StaticMethod {
|
jaroslav@9
|
25 |
private static int cnt;
|
jaroslav@9
|
26 |
|
jaroslav@46
|
27 |
public static Object none(int x, int y) {
|
jaroslav@46
|
28 |
Object toRet = null;
|
jaroslav@46
|
29 |
for (int i = x; i < y; i++) {
|
jaroslav@46
|
30 |
if (i == 2) {
|
jaroslav@46
|
31 |
toRet = null;
|
jaroslav@46
|
32 |
} else {
|
jaroslav@46
|
33 |
toRet = new Object();
|
jaroslav@46
|
34 |
}
|
jaroslav@46
|
35 |
}
|
jaroslav@46
|
36 |
return toRet;
|
jaroslav@46
|
37 |
}
|
jaroslav@46
|
38 |
|
jaroslav@0
|
39 |
public static int sum(int x, int y) {
|
jaroslav@0
|
40 |
return x + y;
|
jaroslav@0
|
41 |
}
|
jaroslav@1
|
42 |
public static float power(float x) {
|
jaroslav@1
|
43 |
return x * x;
|
jaroslav@1
|
44 |
}
|
jaroslav@2
|
45 |
public static double minus(double x, long y) {
|
jaroslav@2
|
46 |
return x - y;
|
jaroslav@2
|
47 |
}
|
jaroslav@3
|
48 |
public static int div(byte c, double d) {
|
jaroslav@3
|
49 |
return (int)(d / c);
|
jaroslav@3
|
50 |
}
|
jaroslav@3
|
51 |
public static int mix(int a, long b, byte c, double d) {
|
jaroslav@3
|
52 |
return (int)((b / a + c) * d);
|
jaroslav@3
|
53 |
}
|
jaroslav@6
|
54 |
public static long xor(int a, long b) {
|
jaroslav@6
|
55 |
return a ^ b;
|
jaroslav@6
|
56 |
}
|
jaroslav@7
|
57 |
public static long orOrAnd(boolean doOr, int a, int b) {
|
jaroslav@7
|
58 |
return doOr ? a | b : a & b;
|
jaroslav@7
|
59 |
}
|
jaroslav@4
|
60 |
public static long factRec(int n) {
|
jaroslav@4
|
61 |
if (n <= 1) {
|
jaroslav@4
|
62 |
return 1;
|
jaroslav@4
|
63 |
} else {
|
jaroslav@4
|
64 |
return n * factRec(n - 1);
|
jaroslav@4
|
65 |
}
|
jaroslav@4
|
66 |
}
|
jaroslav@5
|
67 |
public static long factIter(int n) {
|
jaroslav@5
|
68 |
long res = 1;
|
jaroslav@5
|
69 |
for (int i = 2; i <= n; i++) {
|
jaroslav@5
|
70 |
res *= i;
|
jaroslav@5
|
71 |
}
|
jaroslav@5
|
72 |
return res;
|
jaroslav@5
|
73 |
}
|
jaroslav@9
|
74 |
public static int inc4() {
|
jaroslav@9
|
75 |
cnt++;
|
jaroslav@9
|
76 |
cnt+=2;
|
jaroslav@9
|
77 |
cnt++;
|
jaroslav@9
|
78 |
return cnt;
|
jaroslav@9
|
79 |
}
|
jaroslav@0
|
80 |
}
|