jaroslav@106: /** jaroslav@106: * Back 2 Browser Bytecode Translator jaroslav@106: * Copyright (C) 2012 Jaroslav Tulach jaroslav@106: * jaroslav@106: * This program is free software: you can redistribute it and/or modify jaroslav@106: * it under the terms of the GNU General Public License as published by jaroslav@106: * the Free Software Foundation, version 2 of the License. jaroslav@106: * jaroslav@106: * This program is distributed in the hope that it will be useful, jaroslav@106: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@106: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@106: * GNU General Public License for more details. jaroslav@106: * jaroslav@106: * You should have received a copy of the GNU General Public License jaroslav@106: * along with this program. Look for COPYING file in the top folder. jaroslav@106: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@106: */ jaroslav@0: /* jaroslav@0: Java 4 Browser Bytecode Translator jaroslav@0: Copyright (C) 2012-2012 Jaroslav Tulach jaroslav@0: jaroslav@0: This program is free software: you can redistribute it and/or modify jaroslav@0: it under the terms of the GNU General Public License as published by jaroslav@0: the Free Software Foundation, version 2 of the License. jaroslav@0: jaroslav@0: This program is distributed in the hope that it will be useful, jaroslav@0: but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@0: GNU General Public License for more details. jaroslav@0: jaroslav@0: You should have received a copy of the GNU General Public License jaroslav@0: along with this program. Look for COPYING file in the top folder. jaroslav@0: If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@0: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@0: jaroslav@94: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@94: jaroslav@0: /** jaroslav@0: * jaroslav@0: * @author Jaroslav Tulach jaroslav@0: */ jaroslav@0: public class StaticMethod { jaroslav@9: private static int cnt; jaroslav@48: jaroslav@48: public static int minusOne() { jaroslav@48: return -1; jaroslav@48: } jaroslav@9: jaroslav@46: public static Object none(int x, int y) { jaroslav@46: Object toRet = null; jaroslav@46: for (int i = x; i < y; i++) { jaroslav@46: if (i == 2) { jaroslav@46: toRet = null; jaroslav@46: } else { jaroslav@46: toRet = new Object(); jaroslav@46: } jaroslav@46: } jaroslav@46: return toRet; jaroslav@46: } jaroslav@46: jaroslav@0: public static int sum(int x, int y) { jaroslav@0: return x + y; jaroslav@0: } jaroslav@1: public static float power(float x) { jaroslav@1: return x * x; jaroslav@1: } jaroslav@2: public static double minus(double x, long y) { jaroslav@2: return x - y; jaroslav@2: } jaroslav@3: public static int div(byte c, double d) { jaroslav@3: return (int)(d / c); jaroslav@3: } jaroslav@3: public static int mix(int a, long b, byte c, double d) { jaroslav@3: return (int)((b / a + c) * d); jaroslav@3: } jaroslav@6: public static long xor(int a, long b) { jaroslav@6: return a ^ b; jaroslav@6: } jaroslav@7: public static long orOrAnd(boolean doOr, int a, int b) { jaroslav@7: return doOr ? a | b : a & b; jaroslav@7: } jaroslav@93: public static int shiftLeft(int what, int much) { jaroslav@93: return what << much; jaroslav@93: } jaroslav@93: public static int shiftArithmRight(int what, int much, boolean signed) { jaroslav@93: if (signed) { jaroslav@93: return what >> much; jaroslav@93: } else { jaroslav@93: return what >>> much; jaroslav@93: } jaroslav@93: } jaroslav@4: public static long factRec(int n) { jaroslav@4: if (n <= 1) { jaroslav@4: return 1; jaroslav@4: } else { jaroslav@4: return n * factRec(n - 1); jaroslav@4: } jaroslav@4: } jaroslav@5: public static long factIter(int n) { jaroslav@5: long res = 1; jaroslav@5: for (int i = 2; i <= n; i++) { jaroslav@5: res *= i; jaroslav@5: } jaroslav@5: return res; jaroslav@5: } jaroslav@9: public static int inc4() { jaroslav@9: cnt++; jaroslav@9: cnt+=2; jaroslav@9: cnt++; jaroslav@9: return cnt; jaroslav@9: } jaroslav@94: jaroslav@94: @JavaScriptBody( jaroslav@99: args={"i","j"}, body="return (i + j).toString();" jaroslav@94: ) jaroslav@99: public static String i2s(int i, int j) { jaroslav@94: throw new IllegalStateException(); jaroslav@94: } jaroslav@97: jaroslav@97: static { jaroslav@97: // check order of initializers jaroslav@97: StaticUse.NON_NULL.equals(new Object()); jaroslav@97: } jaroslav@0: }