public override void execute(StackFrame frame) { Object val2 = frame.popOperand(); Object val1 = frame.popOperand(); //Heap.HeapReference val2 = (Heap.HeapReference) frame.popOperand(); //Heap.HeapReference val1 = (Heap.HeapReference) frame.popOperand(); bool eval = false; switch (opval){ case OP_EQ:{ eval = (val1 == val2); break; } case OP_NE:{ eval = (val1 != val2); break; } default: throw new ToyVMException("Not handling " + opval,frame); } if (eval){ int pc = frame.getProgramCounter(); frame.setProgramCounter(pc + branch - size); } }
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) { double val1 = (double) frame.popOperand(); double val2 = (double) frame.popOperand(); frame.pushOperand(val2 - val1); }
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) { frame.popOperand(); if (count == 2){ frame.popOperand(); } }
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) { 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 val = frame.popOperand(); int index = (int) frame.popOperand(); Heap.HeapReference heapRef = (Heap.HeapReference) frame.popOperand(); if (! heapRef.isArray){ throw new ToyVMException("Expected array, got " + heapRef,frame); } if (! heapRef.isPrimitive){ ArrayList arr = (ArrayList) heapRef.obj; arr[index] = val; } else if (heapRef.primitiveType.Equals(Type.GetType("System.Char[]"))){ ArrayList arr = (ArrayList) heapRef.obj; arr[index] = val; //System.Char[][] arr = (System.Char[][]) heapRef.obj; //Heap.HeapReference arrVal = (Heap.HeapReference)val; //arr[index] = (System.Char[])arrVal.obj; } else { throw new ToyVMException("Can't handle " + heapRef,frame); } if (log.IsDebugEnabled) log.DebugFormat("Stored {0} at index {1}",val,index); }
// 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); }
/** * 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); }
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) { 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) { 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); }
/** * 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) { ConstantPoolInfo_Class theClass = field.getTheClass(); if (log.IsDebugEnabled) log.DebugFormat("Field class is {0}",theClass); //ClassFile fieldClass = ToyVMClassLoader.loadClass(theClass.getClassName()); Object value = frame.popOperand(); Heap.HeapReference href = (Heap.HeapReference) frame.popOperand(); ToyVMObject obj = (ToyVMObject) href.obj; obj.setFieldValue(field,value); }
public override void execute(StackFrame frame) { byte val = (byte)((int)frame.popOperand()); int index = (int) frame.popOperand(); Heap.HeapReference heapRef = (Heap.HeapReference) frame.popOperand(); if (! heapRef.isArray){ throw new ToyVMException("Expected array, got " + heapRef,frame); } System.Byte[] arr = (System.Byte[]) heapRef.obj; arr[index] = val; }
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); }
// TODO: Actually implement threads public override void execute(StackFrame frame) { Heap.HeapReference heapRef = (Heap.HeapReference) frame.popOperand(); ToyVMObject obj = (ToyVMObject) heapRef.obj; obj.monitorExit(); }
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) { ClassFile clazz = ToyVMClassLoader.loadClass(method.GetClassInfo().getClassName()); ConstantPoolInfo_NameAndType nameAndType = method.GetMethodNameAndType(); if (log.IsDebugEnabled) log.DebugFormat("Will be executing {0} on {1}",nameAndType,clazz.GetName()); MethodInfo methodInfo = clazz.getMethod(nameAndType); // TODO: Need better way of handling access to the method if (methodInfo == null){ throw new ToyVMException("Unable to locate method " + nameAndType + " on " + clazz,frame); } StackFrame frame2 = new StackFrame(frame); int paramCount = method.getParameterCount(); frame2.setMethod(clazz,methodInfo,paramCount); if (log.IsDebugEnabled) log.DebugFormat("Have {0} parameters",paramCount); // Store the parameters from the operand stack // into the local variables of the outgoing frame for (int i = paramCount; i > 0; i--){ frame2.getLocalVariables()[i-1]=frame.popOperand(); if (log.IsDebugEnabled) log.DebugFormat("Parameter {0} = {1}",i,frame2.getLocalVariables()[i-1]); } clazz.execute(nameAndType,frame2); /*methodInfo.execute(frame2); if (methodInfo != null){ } else { throw new Exception("Unable to locate " + nameAndType.ToString()); } */ }
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); }
/** * * Operand stack * ..., objectref, [arg1, [arg2 ...]] ... */ public override void execute(StackFrame frame) { ClassFile clazz = ToyVMClassLoader.loadClass(method.GetClassInfo().getClassName()); ConstantPoolInfo_NameAndType nameAndType = method.GetMethodNameAndType(); if (log.IsDebugEnabled) log.DebugFormat("Will be executing {0} on {1}",nameAndType,clazz.GetName()); MethodInfo methodInfo = clazz.getMethod(nameAndType); StackFrame frame2 = new StackFrame(frame); int paramCount = method.getParameterCount(); frame2.setMethod(clazz,methodInfo,paramCount); if (log.IsDebugEnabled) log.DebugFormat("Have {0} parameters",paramCount); if (log.IsDebugEnabled) log.DebugFormat("Max Locals: {0}",methodInfo.getMaxLocals()); // push "this" as local variable 0 //frame2.setThis((ToyVMObject)(frame2.getLocalVariables()[0])); // Store the parameters from the operand stack // into the local variables of the outgoing frame for (int i = paramCount;i >= 0; i--){ frame2.getLocalVariables()[i]=frame.popOperand(); if (log.IsDebugEnabled) log.DebugFormat("Set variable {0}={1}",(i),frame2.getLocalVariables()[i]); } clazz.execute(nameAndType,frame2); //Environment.Exit(0); }
public override void execute(StackFrame frame) { Object returnVal = frame.popOperand(); if (returnVal is NullValue || returnVal is Heap.HeapReference || returnVal is ClassFile || returnVal is Thread){ frame.getPrev().pushOperand(returnVal); } else throw new ToyVMException("areturn inconsistent " + returnVal,frame); }
//..., value ... public override void execute(StackFrame frame) { if (log.IsDebugEnabled) log.DebugFormat("Executing " + this); ConstantPoolInfo_Class theClass = field.getTheClass(); if (log.IsDebugEnabled) log.DebugFormat("Field class is {0}",theClass); ClassFile fieldClass = ToyVMClassLoader.loadClass(theClass.getClassName()); fieldClass.setStaticFieldValue(field.getNameAndType().getRefName(),frame.popOperand()); if (log.IsDebugEnabled) log.DebugFormat("Static field {0} now has value {1}",field,fieldClass.getStaticFieldValue(field.getNameAndType().getRefName())); }
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) { Object oper = frame.popOperand(); if (log.IsDebugEnabled) log.DebugFormat("Oper is {0}",oper); int pc = frame.getProgramCounter(); bool eval = false; switch (opval){ case OP_NULL:{ eval = (oper is NullValue); break; } case OP_GE:{ eval = ((int) oper >= 0); break; } case OP_G: { eval = ((int) oper > 0); break; } case OP_NE: { eval = ((int) oper != 0); break; } case OP_NOTNULL: { eval = ! (oper is NullValue); break; } case OP_EQUALS: { eval = ((int)oper == 0); break; } case OP_LT: { eval = ((int) oper == -1); break; } case OP_LE: { eval = ((int) oper <= 0); break; } default:throw new ToyVMException("Don't know how to handle",frame); } if (eval){ frame.setProgramCounter(pc + branch - size); if (log.IsDebugEnabled) log.DebugFormat("Jumping to " + (frame.getProgramCounter() + size)); } }
// ..., 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); }
/** * * Operand stack * ..., objectref, [arg1, [arg2 ...]] ... */ public override void execute(StackFrame frame) { //ClassFile clazz = ToyVMClassLoader.loadClass(method.GetClassInfo().getClassName()); ConstantPoolInfo_NameAndType nameAndType = method.GetMethodNameAndType(); if (log.IsDebugEnabled) log.DebugFormat("Will be executing {0} on interface {1}",nameAndType,method.GetClassInfo().getClassName()); int paramCount = method.getParameterCount(); ArrayList locals = new ArrayList(); for (int i = 0; i <= paramCount; i++){ locals.Add(0); } // create temp version of the variables // so that we can get to the object // on the stack for (int i = paramCount; i >= 0; i--){ locals[i] = frame.popOperand(); } ClassFile clazz = ((Heap.HeapReference)locals[0]).type; StackFrame frame2 = new StackFrame(frame); frame2.setMethod(clazz,clazz.getMethod(nameAndType)); if (log.IsDebugEnabled) log.DebugFormat("Have {0} parameters",paramCount); for (int i = 0;i <= paramCount; i++){ frame2.getLocalVariables()[i] = locals[i]; } clazz.execute(nameAndType,frame2); //Environment.Exit(0); }