public override void execute(StackFrame frame) { if (depth > 0){ throw new ToyVMException("Don't support dup2 with depth of " + depth,frame); } Object obj = frame.popOperand(); Object obj2 = null; if (frame.hasMoreOperands()){ obj2 = frame.popOperand(); } /*System.Collections.Stack temp = new System.Collections.Stack(); for (int i = 0; i < depth; i++){ temp.Push(frame.popOperand()); } frame.pushOperand(obj); // insert at depth depth while (temp.Count > 0){ frame.pushOperand(temp.Pop()); } */ frame.pushOperand(obj); // put the duplicated one back on top if (obj2 != null){ frame.pushOperand(obj2); } frame.pushOperand(obj); // put the duplicated one back on top if (obj2 != null){ frame.pushOperand(obj2); } }
public override void execute(StackFrame frame) { Object o = frame.popOperand(); if (! (o is NullValue)){ Heap.HeapReference heapRef = (Heap.HeapReference) o; // we only handle class right now ClassFile tClass = (ClassFile) heapRef.type; do { if (tClass.GetName().Equals(className)){ frame.pushOperand(1); return; } if (tClass.implements(className)){ frame.pushOperand(1); return; } tClass = tClass.GetSuperClassFile(); } while (tClass != null); } frame.pushOperand(0); }
public override void execute(StackFrame frame) { float value2 = Single.Parse(frame.popOperand().ToString()); float value1 = Single.Parse(frame.popOperand().ToString()); // TODO: handle NaN if (value1 > value2) { frame.pushOperand(1); } else if (value1.Equals(value2)) { frame.pushOperand(0); } else { frame.pushOperand(-1); } }
public override void execute(StackFrame frame) { int count = (int) frame.popOperand(); string className = reference.getClassName(); if (! className.StartsWith("[")){ frame.pushOperand(Heap.GetInstance().newArray(ToyVMClassLoader.loadClass(className),count)); } else { frame.pushOperand(Heap.GetInstance().new2DArray(className.Substring(1),count)); } }
public override void execute(StackFrame frame) { long val1 = (long) frame.popOperand(); long val2 = (long) frame.popOperand(); frame.pushOperand(val1 & val2); }
public override void execute(StackFrame frame) { double val1 = (double) frame.popOperand(); double val2 = (double) frame.popOperand(); frame.pushOperand(val2 - val1); }
public override void execute(StackFrame frame) { int val1 = (int) frame.popOperand(); int val2 = (int) frame.popOperand(); frame.pushOperand(val1 & val2); }
public override void execute(StackFrame frame) { Object obj = frame.popOperand(); System.Collections.Stack temp = new System.Collections.Stack(); for (int i = 0; i < depth; i++){ temp.Push(frame.popOperand()); } frame.pushOperand(obj); // insert at depth depth while (temp.Count > 0){ frame.pushOperand(temp.Pop()); } frame.pushOperand(obj); // put the duplicated one back on top }
public override void execute(StackFrame frame) { float val1 = (float) frame.popOperand(); float val2 = (float) frame.popOperand(); frame.pushOperand(val1 + val2); }
public override void execute(StackFrame frame) { //ToyVMObject obj = new ToyVMObject(classRef); Heap.HeapReference heapRef = Heap.GetInstance().newInstance(ToyVMClassLoader.loadClass(classRef.getClassName())); if (log.IsDebugEnabled) log.DebugFormat("executing new from {0}",frame); frame.pushOperand(heapRef); }
/** * Right shift val1 by amount in low 5 bits of val2 */ public override void execute(StackFrame frame) { int val2 = (int) frame.popOperand(); int val1 = (int) frame.popOperand(); val1 = (0xFFFF & ((val1 >> (val2 & 0x1F)))); frame.pushOperand(val1); }
// value1,value2 => ... public override void execute(StackFrame frame) { int value2 = (int) frame.popOperand(); int value1 = (int) frame.popOperand(); frame.pushOperand(value1 - (value1 / value2) * value2); // TODO: something is broken up higher //frame.pushOperand(0); }
/** * Left shift val1 by amount in low 5 bits of val2 */ public override void execute(StackFrame frame) { long val2 = (long) frame.popOperand(); long val1 = (long) frame.popOperand(); val1 = (0xFFFFFFFF & ((val1 << (int)(val2 & 0x3F)))); frame.pushOperand(val1); }
public override void execute(StackFrame frame) { double val1 = Double.Parse(frame.popOperand().ToString()); double val2 = Double.Parse(frame.popOperand().ToString()); //if (log.IsDebugEnabled) log.DebugFormat("val1 is {0}",val1.GetType()); //if (log.IsDebugEnabled) log.DebugFormat("val2 is {0}",val2.GetType()); frame.pushOperand(val1 * val2); }
public override void execute(StackFrame frame) { float val1 = Single.Parse(frame.popOperand().ToString()); float val2 = Single.Parse(frame.popOperand().ToString()); //if (log.IsDebugEnabled) log.DebugFormat("val1 is {0}",val1.GetType()); //if (log.IsDebugEnabled) log.DebugFormat("val2 is {0}",val2.GetType()); frame.pushOperand((float)val1 * (float)val2); }
public override void execute(StackFrame frame) { try { //if (log.IsDebugEnabled) log.DebugFormat("Local variable {0} is {1}",index,frame.getLocalVariables()[index]); frame.pushOperand(frame.getLocalVariables()[index]); } catch (Exception e){ throw new ToyVMException("Index is " + index,e,frame); } }
public override void execute(StackFrame frame) { if (reference is ConstantPoolInfo_String){ // TODO: This should actually use an instance of java/lang/String ClassFile stringClass = ToyVMClassLoader.loadClass("java/lang/String"); Heap.HeapReference stringRef = Heap.GetInstance().createString(stringClass,(ConstantPoolInfo_String)reference); frame.pushOperand(stringRef); } else if (reference is ConstantPoolInfo_Integer){ frame.pushOperand(((ConstantPoolInfo_Integer)reference).getValue()); } else if (reference is ConstantPoolInfo_Float){ frame.pushOperand(((ConstantPoolInfo_Float)reference).getValue()); } else { throw new ToyVMException("Expected string,integer or float, got " + reference,frame); } }
public override void execute(StackFrame frame) { ConstantPoolInfo_Class theClass = field.getTheClass(); //if (log.IsDebugEnabled) log.DebugFormat("Field class is {0}",theClass); //ClassFile fieldClass = ToyVMClassLoader.loadClass(theClass.getClassName()); Heap.HeapReference href = (Heap.HeapReference) frame.popOperand(); ToyVMObject obj = (ToyVMObject) href.obj; frame.pushOperand(obj.getFieldValue(field)); }
public override void execute(StackFrame frame) { if (log.IsDebugEnabled) log.DebugFormat("Executing {0}",frame); ConstantPoolInfo_Class classInfo = field.getTheClass(); ClassFile theClass = ToyVMClassLoader.loadClass(classInfo.getClassName()); if (log.IsDebugEnabled) log.DebugFormat("Retrieved {0} and will get value of {1}",classInfo,field); string fieldName = field.getNameAndType().getRefName(); frame.pushOperand(theClass.getStaticFieldValue(fieldName)); }
public override void execute(StackFrame frame) { try { frame.pushOperand((int) frame.getLocalVariables()[index]); } catch (InvalidCastException e){ foreach (Object o in frame.getLocalVariables()){ if (log.IsDebugEnabled) log.DebugFormat("Var:{0}",o); } throw new ToyVMException("Wanted int at " + index + " but got " + frame.getLocalVariables()[index],e,frame); } }
// ..., arrayref => ..., length public override void execute(StackFrame frame) { Object obj = frame.popOperand(); // special handling if (obj is ConstantPoolInfo_String){ ConstantPoolInfo_String stringObj = (ConstantPoolInfo_String) obj; frame.pushOperand(stringObj.getValue().ToCharArray().Length); } else if (obj is string){ frame.pushOperand(((string) obj).ToCharArray().Length); } else { Heap.HeapReference arrayRef = (Heap.HeapReference) obj; if (! arrayRef.isArray){ throw new ToyVMException("Expecting array but have " + arrayRef,frame); } frame.pushOperand(arrayRef.length); } }
public override void execute(StackFrame frame) { Object obj = frame.popOperand(); if (obj is NullValue){ frame.pushOperand(obj); return; } Heap.HeapReference heapRef = (Heap.HeapReference) obj; ClassFile S = heapRef.type; ClassFile T = ToyVMClassLoader.loadClass(className); if (! isArray){ while (S != null){ if ((! heapRef.isArray) && S == T){ frame.pushOperand(obj); return; } if (S.implements(className)){ frame.pushOperand(obj); return; } S = S.GetSuperClassFile(); } } else { if (heapRef.isArray && S == T){ frame.pushOperand(obj); return; } } throw new ToyVMException(String.Format("ClassCastException {0} {1} {2}",isArray,T,S),frame); }
/** * Grabs a character from the array and pushes onto stack as an integer */ public override void execute(StackFrame frame) { int index = (int) frame.popOperand(); Heap.HeapReference heapRef = (Heap.HeapReference) frame.popOperand(); if (! heapRef.isArray){ throw new ToyVMException("Expected array, got " + heapRef,frame); } System.Char[] arr = (System.Char[]) heapRef.obj; frame.pushOperand((int)arr[index]); }
public override void execute(StackFrame frame) { int val2 = ((int) frame.popOperand()) & 0x1f; int val1 = (int) frame.popOperand(); if (val1 >= 0){ val1 = val1 >> val2; } else { val1 = (val1 >> val2) + (2 << ~val2); } frame.pushOperand(val1); }
public override void execute(StackFrame frame) { int val = (int) frame.popOperand(); frame.pushOperand((int)((short)val)); }
public override void execute(StackFrame frame) { frame.pushOperand(NullValue.INSTANCE); }
public override void execute(StackFrame frame) { double val1 = Double.Parse(frame.popOperand().ToString()); frame.pushOperand((long) val1); }
public override void execute(StackFrame frame) { int val = (int) frame.popOperand(); frame.pushOperand((double)val); }
public override void execute(StackFrame frame) { int pc = frame.getProgramCounter(); frame.pushOperand(pc + size); frame.setProgramCounter(pc + branch - size); }
public override void execute(StackFrame frame) { frame.pushOperand((int)((short)value)); }