vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 28 Sep 2012 14:58:21 +0200
changeset 48 4fca8ddf46de
parent 46 b07c7c256771
child 93 a236a9f137ac
permissions -rw-r--r--
Supporting iconst_m1
     1 /*
     2 Java 4 Browser Bytecode Translator
     3 Copyright (C) 2012-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 package org.apidesign.vm4brwsr;
    19 
    20 /**
    21  *
    22  * @author Jaroslav Tulach <jtulach@netbeans.org>
    23  */
    24 public class StaticMethod {
    25     private static int cnt;
    26 
    27     public static int minusOne() {
    28         return -1;
    29     }
    30     
    31     public static Object none(int x, int y) {
    32         Object toRet = null;
    33         for (int i = x; i < y; i++) {
    34             if (i == 2) {
    35                 toRet = null;
    36             } else {
    37                 toRet = new Object();
    38             }
    39         }
    40         return toRet;
    41     }
    42     
    43     public static int sum(int x, int y) {
    44         return x + y;
    45     }
    46     public static float power(float x) {
    47         return x * x;
    48     }
    49     public static double minus(double x, long y) {
    50         return x - y;
    51     }
    52     public static int div(byte c, double d) {
    53         return (int)(d / c);
    54     }
    55     public static int mix(int a, long b, byte c, double d) {
    56         return (int)((b / a + c) * d);
    57     }
    58     public static long xor(int a, long b) {
    59         return a ^ b;
    60     }
    61     public static long orOrAnd(boolean doOr, int a, int b) {
    62         return doOr ? a | b : a & b;
    63     }
    64     public static long factRec(int n) {
    65         if (n <= 1) {
    66             return 1;
    67         } else {
    68             return n * factRec(n - 1);
    69         }
    70     }
    71     public static long factIter(int n) {
    72         long res = 1;
    73         for (int i = 2; i <= n; i++) {
    74             res *= i;
    75         }
    76         return res;
    77     }
    78     public static int inc4() {
    79         cnt++;
    80         cnt+=2;
    81         cnt++;
    82         return cnt;
    83     }
    84 }