2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.vm4brwsr;
20 import org.apidesign.bck2brwsr.core.JavaScriptBody;
24 * @author Jaroslav Tulach <jtulach@netbeans.org>
26 public class StaticMethod {
27 public static final int MISSING_CONSTANT = 1;
28 private static int cnt;
29 private static Object NULL;
31 public static int minusOne() {
35 public static Object none(int x, int y) {
37 for (int i = x; i < y; i++) {
47 public static boolean isNull() {
51 public static int sum(int x, int y) {
54 public static float power(float x) {
57 public static double minus(double x, long y) {
60 public static int div(byte c, double d) {
63 public static int mix(int a, long b, byte c, double d) {
64 return (int)((b / a + c) * d);
66 public static long xor(int a, long b) {
69 public static long orOrAnd(boolean doOr, int a, int b) {
70 return doOr ? a | b : a & b;
72 public static int shiftLeft(int what, int much) {
75 public static int shiftArithmRight(int what, int much, boolean signed) {
82 public static long factRec(int n) {
86 return n * factRec(n - MISSING_CONSTANT);
89 public static long factIter(int n) {
91 for (int i = 2; i <= n; i++) {
96 public static int inc4() {
103 public static int helloWorldLength(String x) {
104 return (StringSample.HELLO + x).length();
108 args={"i","j"}, body="\n\r\treturn (i + j).toString();"
110 public static String i2s(int i, int j) {
111 throw new IllegalStateException();
114 public static String castNull(boolean n) {
115 Object value = n ? null : "Ahoj";
116 return (String)value;
119 public static String swtch(int what) {
121 case 0: return "Jarda";
122 case 1: return "Darda";
123 case 2: return "Parda";
124 default: return "Marda";
127 public static String swtch2(int what) {
129 case 0: return "Jarda";
130 case 11: return "Darda";
131 case 22: return "Parda";
132 default: return "Marda";
136 public static int castString(Object o) {
137 return ((String)o).length();
140 public static int initInflater(int w, boolean nowrap) {
141 Instance i = new Instance(w, 0.0);
142 return i.sum(nowrap?-w:w, 1);
145 public static int intHolder() {
146 return new IntHolder(new Integer(10)).i.intValue();
149 private static class IntHolder {
152 public IntHolder(Integer i) {
157 public static String toStringArr() {
158 class N implements Next {
162 public boolean hasNext() {
167 public String next() {
169 case 0: return "Zero";
170 case 1: return "One";
171 case 2: return "Two";
172 case 3: return "Three";
173 case 4: return "Four";
175 throw new IllegalStateException();
178 return toString(null, new N()).toString();
181 static String toString(Object thiz, Next it) {
186 StringBuilder sb = new StringBuilder();
189 String e = it.next();
190 sb.append(e == thiz ? "(this Collection)" : e);
192 return sb.append(']').toString();
194 sb.append(',').append(' ');
198 static interface Next {
205 // check order of initializers
206 StaticUse.NON_NULL.equals(new Object());