/**
 * Copyright (c) 2013 Stefan Marr, stefan.marr@vub.ac.be
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package som.interpreter;

import java.math.BigInteger;

import som.vm.constants.Blocks;
import som.vm.constants.Classes;
import som.vm.constants.Globals;
import som.vmobjects.SAbstractObject;
import som.vmobjects.SBlock;
import som.vmobjects.SBlock.SBlock1;
import som.vmobjects.SBlock.SBlock2;
import som.vmobjects.SBlock.SBlock3;
import som.vmobjects.SClass;
import som.vmobjects.SInvokable;
import som.vmobjects.SInvokable.SMethod;
import som.vmobjects.SInvokable.SPrimitive;
import som.vmobjects.SObject;
import som.vmobjects.SSymbol;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.TypeSystem;

@TypeSystem({   boolean.class,
                   long.class,
             BigInteger.class,
                 String.class,
                 double.class,
                 SClass.class,
                SObject.class,
                 SBlock.class,
                SSymbol.class,
             SInvokable.class,
        SAbstractObject.class,
               Object[].class})
public class Types {

  public static SClass getClassOf(final Object obj) {
    CompilerAsserts.neverPartOfCompilation();
    assert obj != null;

    if (obj instanceof SAbstractObject) {
      return ((SAbstractObject) obj).getSOMClass();
    } else if (obj instanceof Boolean) {
      if ((boolean) obj) {
        return Globals.trueClass;
      } else {
        return Globals.falseClass;
      }
    } else if (obj instanceof Long || obj instanceof BigInteger) {
      return Classes.integerClass;
    } else if (obj instanceof String) {
      return Classes.stringClass;
    } else if (obj instanceof Double) {
      return Classes.doubleClass;
    } else if (obj instanceof SMethod) {
      return Classes.methodClass;
    } else if (obj instanceof SPrimitive) {
      return Classes.primitiveClass;
    } else if (obj instanceof SBlock1) {
      return Blocks.blockClass1;
    } else if (obj instanceof SBlock2) {
      return Blocks.blockClass2;
    } else if (obj instanceof SBlock3) {
      return Blocks.blockClass3;
    } else if (obj instanceof Object[]) {
      return Classes.arrayClass;
    }

    TruffleCompiler.transferToInterpreter("Should not be reachable");
    throw new RuntimeException("We got an object that should be covered by the above check: " + obj.toString());
  }
}

@@ -1193,40 +1193,8 @@
 r;%0A%0A
-import som.vm.constants.Blocks;%0A
 impo
@@ -1348,241 +1348,45 @@
 ts.S
-Block.SBlock1;%0Aimport som.vmobjects.SBlock.SBlock2;%0Aimport som.vmobjects.SBlock.SBlock3;%0Aimport som.vmobjects.SClass;%0Aimport som.vmobjects.SInvokable;%0Aimport som.vmobjects.SInvokable.SMethod;%0Aimport som.vmobjects.SInvokable.SPrimitiv
+Class;%0Aimport som.vmobjects.SInvokabl
 e;%0Ai
@@ -2567,386 +2567,8 @@
 ss;%0A
-    %7D else if (obj instanceof SMethod) %7B%0A      return Classes.methodClass;%0A    %7D else if (obj instanceof SPrimitive) %7B%0A      return Classes.primitiveClass;%0A    %7D else if (obj instanceof SBlock1) %7B%0A      return Blocks.blockClass1;%0A    %7D else if (obj instanceof SBlock2) %7B%0A      return Blocks.blockClass2;%0A    %7D else if (obj instanceof SBlock3) %7B%0A      return Blocks.blockClass3;%0A
     

Remove redundant classes in Types.java, already covered by SAbstractObject