jaroslav@24: /** jaroslav@106: * Back 2 Browser Bytecode Translator jaroslav@106: * Copyright (C) 2012 Jaroslav Tulach jaroslav@24: * jaroslav@24: * This program is free software: you can redistribute it and/or modify jaroslav@24: * it under the terms of the GNU General Public License as published by jaroslav@24: * the Free Software Foundation, version 2 of the License. jaroslav@24: * jaroslav@24: * This program is distributed in the hope that it will be useful, jaroslav@24: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@24: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@24: * GNU General Public License for more details. jaroslav@24: * jaroslav@24: * You should have received a copy of the GNU General Public License jaroslav@24: * along with this program. Look for COPYING file in the top folder. jaroslav@24: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@8: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@8: jaroslav@8: /** jaroslav@8: * jaroslav@8: * @author Jaroslav Tulach jaroslav@8: */ jaroslav@8: public class Instance { jaroslav@8: private int i; jaroslav@8: protected short s; jaroslav@8: public double d; jaroslav@8: private float f; jaroslav@10: protected byte b = (byte)31; jaroslav@10: jaroslav@10: private Instance() { jaroslav@10: } jaroslav@8: jaroslav@8: public Instance(int i, double d) { jaroslav@8: this.i = i; jaroslav@8: this.d = d; jaroslav@8: } jaroslav@8: public byte getByte() { jaroslav@8: return b; jaroslav@8: } jaroslav@8: jaroslav@8: public void setByte(byte b) { jaroslav@8: this.b = b; jaroslav@8: } jaroslav@10: public static double defaultDblValue() { jaroslav@10: Instance create = new Instance(); jaroslav@10: return create.d; jaroslav@10: } jaroslav@8: jaroslav@10: public static byte assignedByteValue() { jaroslav@10: return new Instance().b; jaroslav@10: } jaroslav@8: public static double magicOne() { jaroslav@8: Instance i = new Instance(10, 3.3d); jaroslav@10: i.b = (byte)0x09; jaroslav@10: return (i.i - i.b) * i.d; jaroslav@8: } jaroslav@14: public static int virtualBytes() { jaroslav@13: Instance i = new InstanceSub(7, 2.2d); jaroslav@12: i.setByte((byte)0x0a); jaroslav@14: Instance i2 = new Instance(3, 333.0d); jaroslav@14: i2.setByte((byte)44); jaroslav@14: return i.getByte() + i2.getByte(); jaroslav@12: } jaroslav@15: public static float interfaceBytes() { jaroslav@15: GetByte i = new InstanceSub(7, 2.2d); jaroslav@15: return i.getByte(); jaroslav@15: } jaroslav@16: public static boolean instanceOf(boolean sub) { jaroslav@16: Instance i = createInstance(sub); jaroslav@16: return isInstanceSubOf(i); jaroslav@16: } jaroslav@30: public static int castsWork(boolean interfc) { jaroslav@30: Instance i = createInstance(true); jaroslav@30: if (interfc) { jaroslav@30: GetByte b = (GetByte)i; jaroslav@30: } else { jaroslav@30: InstanceSub s = (InstanceSub)i; jaroslav@30: } jaroslav@30: return 5; jaroslav@30: } jaroslav@30: jaroslav@16: private static boolean isInstanceSubOf(Instance instance) { jaroslav@16: return instance instanceof InstanceSub; jaroslav@16: } jaroslav@16: private static Instance createInstance(boolean sub) { jaroslav@16: return sub ? new InstanceSub(3, 0) : new Instance(); jaroslav@16: } jaroslav@16: private static boolean isNull() { jaroslav@16: return createInstance(true) == null; jaroslav@16: } jaroslav@8: }