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@94
|
20 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
jaroslav@94
|
21 |
|
jaroslav@0
|
22 |
/**
|
jaroslav@0
|
23 |
*
|
jaroslav@0
|
24 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
25 |
*/
|
jaroslav@0
|
26 |
public class StaticMethod {
|
jaroslav@9
|
27 |
private static int cnt;
|
jaroslav@48
|
28 |
|
jaroslav@48
|
29 |
public static int minusOne() {
|
jaroslav@48
|
30 |
return -1;
|
jaroslav@48
|
31 |
}
|
jaroslav@9
|
32 |
|
jaroslav@46
|
33 |
public static Object none(int x, int y) {
|
jaroslav@46
|
34 |
Object toRet = null;
|
jaroslav@46
|
35 |
for (int i = x; i < y; i++) {
|
jaroslav@46
|
36 |
if (i == 2) {
|
jaroslav@46
|
37 |
toRet = null;
|
jaroslav@46
|
38 |
} else {
|
jaroslav@46
|
39 |
toRet = new Object();
|
jaroslav@46
|
40 |
}
|
jaroslav@46
|
41 |
}
|
jaroslav@46
|
42 |
return toRet;
|
jaroslav@46
|
43 |
}
|
jaroslav@46
|
44 |
|
jaroslav@0
|
45 |
public static int sum(int x, int y) {
|
jaroslav@0
|
46 |
return x + y;
|
jaroslav@0
|
47 |
}
|
jaroslav@1
|
48 |
public static float power(float x) {
|
jaroslav@1
|
49 |
return x * x;
|
jaroslav@1
|
50 |
}
|
jaroslav@2
|
51 |
public static double minus(double x, long y) {
|
jaroslav@2
|
52 |
return x - y;
|
jaroslav@2
|
53 |
}
|
jaroslav@3
|
54 |
public static int div(byte c, double d) {
|
jaroslav@3
|
55 |
return (int)(d / c);
|
jaroslav@3
|
56 |
}
|
jaroslav@3
|
57 |
public static int mix(int a, long b, byte c, double d) {
|
jaroslav@3
|
58 |
return (int)((b / a + c) * d);
|
jaroslav@3
|
59 |
}
|
jaroslav@6
|
60 |
public static long xor(int a, long b) {
|
jaroslav@6
|
61 |
return a ^ b;
|
jaroslav@6
|
62 |
}
|
jaroslav@7
|
63 |
public static long orOrAnd(boolean doOr, int a, int b) {
|
jaroslav@7
|
64 |
return doOr ? a | b : a & b;
|
jaroslav@7
|
65 |
}
|
jaroslav@93
|
66 |
public static int shiftLeft(int what, int much) {
|
jaroslav@93
|
67 |
return what << much;
|
jaroslav@93
|
68 |
}
|
jaroslav@93
|
69 |
public static int shiftArithmRight(int what, int much, boolean signed) {
|
jaroslav@93
|
70 |
if (signed) {
|
jaroslav@93
|
71 |
return what >> much;
|
jaroslav@93
|
72 |
} else {
|
jaroslav@93
|
73 |
return what >>> much;
|
jaroslav@93
|
74 |
}
|
jaroslav@93
|
75 |
}
|
jaroslav@4
|
76 |
public static long factRec(int n) {
|
jaroslav@4
|
77 |
if (n <= 1) {
|
jaroslav@4
|
78 |
return 1;
|
jaroslav@4
|
79 |
} else {
|
jaroslav@4
|
80 |
return n * factRec(n - 1);
|
jaroslav@4
|
81 |
}
|
jaroslav@4
|
82 |
}
|
jaroslav@5
|
83 |
public static long factIter(int n) {
|
jaroslav@5
|
84 |
long res = 1;
|
jaroslav@5
|
85 |
for (int i = 2; i <= n; i++) {
|
jaroslav@5
|
86 |
res *= i;
|
jaroslav@5
|
87 |
}
|
jaroslav@5
|
88 |
return res;
|
jaroslav@5
|
89 |
}
|
jaroslav@9
|
90 |
public static int inc4() {
|
jaroslav@9
|
91 |
cnt++;
|
jaroslav@9
|
92 |
cnt+=2;
|
jaroslav@9
|
93 |
cnt++;
|
jaroslav@9
|
94 |
return cnt;
|
jaroslav@9
|
95 |
}
|
jaroslav@94
|
96 |
|
jaroslav@94
|
97 |
@JavaScriptBody(
|
jaroslav@94
|
98 |
args="i", body="return i.toString();"
|
jaroslav@94
|
99 |
)
|
jaroslav@94
|
100 |
public static String i2s(int i) {
|
jaroslav@94
|
101 |
throw new IllegalStateException();
|
jaroslav@94
|
102 |
}
|
jaroslav@97
|
103 |
|
jaroslav@97
|
104 |
static {
|
jaroslav@97
|
105 |
// check order of initializers
|
jaroslav@97
|
106 |
StaticUse.NON_NULL.equals(new Object());
|
jaroslav@97
|
107 |
}
|
jaroslav@0
|
108 |
}
|