vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 16 Oct 2012 12:42:00 +0200
changeset 106 346633cd13d6
parent 99 67e892757752
child 115 3d5597011af0
permissions -rw-r--r--
Fixing license in all files
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 /*
    19 Java 4 Browser Bytecode Translator
    20 Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    21 
    22 This program is free software: you can redistribute it and/or modify
    23 it under the terms of the GNU General Public License as published by
    24 the Free Software Foundation, version 2 of the License.
    25 
    26 This program is distributed in the hope that it will be useful,
    27 but WITHOUT ANY WARRANTY; without even the implied warranty of
    28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    29 GNU General Public License for more details.
    30 
    31 You should have received a copy of the GNU General Public License
    32 along with this program. Look for COPYING file in the top folder.
    33 If not, see http://opensource.org/licenses/GPL-2.0.
    34 */
    35 package org.apidesign.vm4brwsr;
    36 
    37 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    38 
    39 /**
    40  *
    41  * @author Jaroslav Tulach <jtulach@netbeans.org>
    42  */
    43 public class StaticMethod {
    44     private static int cnt;
    45 
    46     public static int minusOne() {
    47         return -1;
    48     }
    49     
    50     public static Object none(int x, int y) {
    51         Object toRet = null;
    52         for (int i = x; i < y; i++) {
    53             if (i == 2) {
    54                 toRet = null;
    55             } else {
    56                 toRet = new Object();
    57             }
    58         }
    59         return toRet;
    60     }
    61     
    62     public static int sum(int x, int y) {
    63         return x + y;
    64     }
    65     public static float power(float x) {
    66         return x * x;
    67     }
    68     public static double minus(double x, long y) {
    69         return x - y;
    70     }
    71     public static int div(byte c, double d) {
    72         return (int)(d / c);
    73     }
    74     public static int mix(int a, long b, byte c, double d) {
    75         return (int)((b / a + c) * d);
    76     }
    77     public static long xor(int a, long b) {
    78         return a ^ b;
    79     }
    80     public static long orOrAnd(boolean doOr, int a, int b) {
    81         return doOr ? a | b : a & b;
    82     }
    83     public static int shiftLeft(int what, int much) {
    84         return what << much;
    85     }
    86     public static int shiftArithmRight(int what, int much, boolean signed) {
    87         if (signed) {
    88             return what >> much;
    89         } else {
    90             return what >>> much;
    91         }
    92     }
    93     public static long factRec(int n) {
    94         if (n <= 1) {
    95             return 1;
    96         } else {
    97             return n * factRec(n - 1);
    98         }
    99     }
   100     public static long factIter(int n) {
   101         long res = 1;
   102         for (int i = 2; i <= n; i++) {
   103             res *= i;
   104         }
   105         return res;
   106     }
   107     public static int inc4() {
   108         cnt++;
   109         cnt+=2;
   110         cnt++;
   111         return cnt;
   112     }
   113     
   114     @JavaScriptBody(
   115         args={"i","j"}, body="return (i + j).toString();"
   116     )
   117     public static String i2s(int i, int j) {
   118         throw new IllegalStateException();
   119     }
   120     
   121     static {
   122         // check order of initializers
   123         StaticUse.NON_NULL.equals(new Object());
   124     }
   125 }