public OpcodeStream(ParseStream strm, ExecutionStack stack) { _jumpTable = new JumpTable(); opCodes = new ArrayList(); currentIP = new Stack(); Init(strm, stack); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(2); int offSet = environment.OpCodes.JumpTable.GetIndex(Arguments[0].Value.StringValue); int argCount = Arguments[1].Value.IntegerValue; LexicalScope ls = new LexicalScope(environment.GlobalScope); ExecutionStack s = new ExecutionStack(ls); if(argCount > 0) { ExecutionStackItem [] tmpItems = new ExecutionStackItem[argCount]; for(int i = 0; i < argCount; i++) { tmpItems[i] = environment.LocalStack.PopItem(); } for(int i = argCount - 1; i >= 0; i--) { s.PushItem(tmpItems[i]); } } environment.PushStack(s); environment.OpCodes.PushCurrentIPAndSet(offSet); }
private void Init(ParseStream strm, ExecutionStack stack) { InstructionPointer = 0; Hashtable ocTypes = InitOpCodes(); while(true) { string word = null; if(strm.ReadWord(ref word)) { if(ocTypes.ContainsKey(word)) { OpCode oc = OpCode.Create(ocTypes[word] as Type); oc.Line = strm.CurrentLine; if(oc != null) { bool addToOpcodes = true; oc.ReadArguments(strm, stack.Scope); if(oc.GetType().IsSubclassOf(typeof(LabelOpCode))) { string name = (oc as LabelOpCode).GetName(); JumpTable.AddIndex(name, opCodes.Count); addToOpcodes = false; } if(addToOpcodes) { opCodes.Add(oc); } } else { throw new ParseException( string.Format("Activate Opcode: {0}", word), string.Format("Unable to activate Opcode: {0}", word)); } } else { throw new ParseException("Valid token", string.Format("Unexpected token found: {0}", word) ); } } else { break; } } }
public void PushStack(ExecutionStack stack) { executionStacks.Push(stack); }