Package xscript.runtime.instruction

Source Code of xscript.runtime.instruction.XInstructionNew

package xscript.runtime.instruction;

import java.io.IOException;

import xscript.runtime.XChecks;
import xscript.runtime.XVirtualMachine;
import xscript.runtime.clazz.XInputStream;
import xscript.runtime.clazz.XOutputStream;
import xscript.runtime.genericclass.XClassPtr;
import xscript.runtime.genericclass.XGenericClass;
import xscript.runtime.threads.XMethodExecutor;
import xscript.runtime.threads.XThread;

public class XInstructionNew extends XInstruction {

  private XClassPtr xClass;
 
  public XInstructionNew(XClassPtr xClass){
    this.xClass = xClass;
  }
 
  public XInstructionNew(XInputStream inputStream) throws IOException{
    xClass = XClassPtr.load(inputStream);
  }
 
  @Override
  public void run(XVirtualMachine vm, XThread thread, XMethodExecutor methodExecutor) {
    XGenericClass rClass = xClass.getXClass(vm, methodExecutor.getDeclaringClass(), methodExecutor);
    XChecks.checkAccess(methodExecutor.getDeclaringClass().getXClass(), rClass.getXClass());
    long pointer = vm.getObjectProvider().createObject(rClass);
    methodExecutor.oPush(pointer);
  }

  @Override
  protected void save(XOutputStream outputStream) throws IOException {
    xClass.save(outputStream);
  }

  @Override
  public String getSource() {
    return "new "+xClass;
  }

}
TOP

Related Classes of xscript.runtime.instruction.XInstructionNew

TOP
Copyright © 2018 www.massapi.com. 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.