Package xscript.runtime

Examples of xscript.runtime.XRuntimeException


  public static XInstruction load(XInputStream inputStream) throws IOException {
    int instruction = inputStream.readUnsignedByte();
    Class<? extends XInstruction> c = instructions[instruction];
    if(c==null){
      throw new XRuntimeException("Unknow instruction %s", instruction);
    }
    try {
      return c.getConstructor(XInputStream.class).newInstance(inputStream);
    } catch (InvocationTargetException e) {
      Throwable e1 = e.getTargetException();
      if(e1 instanceof IOException){
        throw (IOException)e1;
      }else if(e1 instanceof RuntimeException){
        throw (RuntimeException)e1;
      }
      throw new XRuntimeException(e1, "Error while creating instruction %s", instruction);
    } catch (Exception e) {
      e.printStackTrace();
      throw new XRuntimeException(e, "Error while creating instruction %s", instruction);
    }
  }
View Full Code Here


        outputStream.writeByte(i);
        instruction.save(outputStream);
        return;
      }
    }
    throw new XRuntimeException("Unknown instruction type %s", instruction.getClass());
  }
View Full Code Here

    state = XClass.STATE_RUNNABLE;
  }

  @Override
  public void save(XOutputStream outputStream) throws IOException {
    throw new XRuntimeException("Can't save Primitive Classes");
  }
View Full Code Here

    case DOUBLE:
      return new XGenericClass(vm.getClassProvider().DOUBLE);
    case VOID:
      return new XGenericClass(vm.getClassProvider().VOID);
    }
    throw new XRuntimeException("Unknown primitiveID %s", i);
  }
View Full Code Here

    long value = methodExecutor.pop(getPrimitiveID(vm));
    if(XModifier.isFinal(field.getModifier())){
      if(methodExecutor.getMethod().getSimpleName().equals("<staticInit>") && methodExecutor.getMethod().getDeclaringClass()==field.getDeclaringClass()){
        field.finalSet(null, value);
      }else{
        throw new XRuntimeException("Try to write final field %s", field.getName());
      }
    }else{
      field.set(null, value);
    }
  }
View Full Code Here

    if(field==null){
      XClass xClass = vm.getClassProvider().getXClass(className);
      field = xClass.getField(fieldName);
      XChecks.checkAccess(methodExecutor.getMethod().getDeclaringClass(), field);
      if(!field.getType().equals(fieldType)){
        throw new XRuntimeException("Type of field %s has changed", field);
      }
      if(!XModifier.isStatic(field.getModifier())){
        throw new XRuntimeException("Field %s isn't static", field);
      }
    }
  }
View Full Code Here

  public XGenericClass getXClass(XVirtualMachine virtualMachine, XGenericClass genericClass, XGenericMethodProvider methodExecutor) {
    if(xClass==null){
      xClass = virtualMachine.getClassProvider().getXClass(className);
      genericID = xClass.getGenericID(genericName);
      if(genericID==-1)
        throw new XRuntimeException("Can't find generic class %s", genericName);
    }
    return xClass.getGeneric(genericClass, genericID);
  }
View Full Code Here

 
  public XMethodExecutor(XMethodExecutor parent, XMethod method, XGenericClass[] generics, long[] params) {
    this.parent = parent;
    this.method = method;
    if(XModifier.isNative(method.getModifier()))
      throw new XRuntimeException("Can't run native method %s", method);
    this.generics = generics;
    if(generics==null){
      if(method.getGenericParams()!=0)
        throw new XRuntimeException("Can't create a generic method %s without generic params, need %s generic params", method, method.getGenericParams());
    }else if(generics.length!=method.getGenericParams()){
      throw new XRuntimeException("Can't create a generic method %s with %s generic params, need %s generic params", method, generics.length, method.getGenericParams());
    }
    int pl = params.length;
    if(!XModifier.isStatic(method.getModifier())){
      XObject _this = method.getDeclaringClass().getVirtualMachine().getObjectProvider().getObject(params[0]);
      declaringClass = _this.getXClass();
      pl--;
    }
    if(pl!=method.getParamCount()){
      throw new XRuntimeException("Wrong number of arguments got %s but need %s", method.getParamCount(), pl);
    }
    stack = new long[method.getMaxStackSize()];
    stackType = new byte[method.getMaxStackSize()];
    local = new long[method.getMaxLocalSize()];
  }
View Full Code Here

    return l;
  }
 
  public long[] pop(){
    if(stackPointer==0)
      throw new XRuntimeException("Stack underflow");
    long[] l = new long[2];
    l[0] = stack[--stackPointer];
    l[1] = stackType[stackPointer];
    return l;
  }
View Full Code Here

  }
 
  public long pop(int primitiveID) {
    long[] l = pop();
    if(l[1]!=primitiveID)
      throw new XRuntimeException("Can't cast %s to %s", XPrimitive.getName((int) l[1]), XPrimitive.getName(primitiveID));
    return l[0];
  }
View Full Code Here

TOP

Related Classes of xscript.runtime.XRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.