public void Next() { if (runtimeData.InstructionStack.Count > 0) { int id = runtimeData.InstructionStack.Pop(); if (id == InstructionStack.ROOT_FLAG) { root.Accept(visitor); } else if (id == InstructionStack.CLOSE_LOCAL_SCOPE_FLAG) { runtimeData.ScopeStack.Close(); Next(); } else if (id == InstructionStack.CLOSE_FORMAL_SCOPE_FLAG) { runtimeData.ScopeStack.Close(); Next(); } else if (id == InstructionStack.CALL_FLAG) { CallStackElement elem = runtimeData.CallStack.Pop(); Next(); } else { root.NodeMap[id].Accept(visitor); } } else { funcCaller.End(); } }
public void Visit(ReturnStmt returnStmt, object[] args) { RightValue returnValue = exprProcessor.Eval(returnStmt.Expression); int id; do { id = kernel.RuntimeData.InstructionStack.Pop(); if (id == InstructionStack.CLOSE_LOCAL_SCOPE_FLAG) { kernel.RuntimeData.ScopeStack.Close(); } else if (id == InstructionStack.CLOSE_FORMAL_SCOPE_FLAG) { kernel.RuntimeData.ScopeStack.Close(); } else if (id == InstructionStack.CALL_FLAG) { CallStackElement elem = kernel.RuntimeData.CallStack.Pop(); if (elem.ReturnDest != null) { kernel.RuntimeData.ScopeStack.SetValue(elem.ReturnDest, returnValue); } } } while (id != InstructionStack.CALL_FLAG); kernel.Next(); }
public void Visit(FunctionCallStmt funcCallStmt, object[] args) { FormalScope formalScope = new FormalScope(); foreach (KeyValuePair <string, Expr.Expression> actual in funcCallStmt.ParamMap) { Expr.RightValue rightValue = exprProcessor.Eval(actual.Value); formalScope.SetValue(actual.Key, rightValue); } kernel.RuntimeData.ScopeStack.Open(formalScope); kernel.RuntimeData.ScopeStack.Open(new LocalScope()); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CALL_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_LOCAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_FORMAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(root.FuncDefMap[funcCallStmt.Name].FuncDefContent); CallStackElement elem = new CallStackElement(); elem.Destination = root.FuncDefMap[funcCallStmt.Name]; elem.Location = funcCallStmt.Location; elem.ReturnDest = exprProcessor.GetVarName(funcCallStmt.ReturnDest); kernel.RuntimeData.CallStack.Push(elem); kernel.Next(); }
public void Visit(IncludeStmt includeStmt, object[] args) { kernel.RuntimeData.ScopeStack.Open(new LocalScope()); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CALL_FLAG); //kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_FORMAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_LOCAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(root.SubPlotMap[includeStmt.SubPlot].Content); CallStackElement elem = new CallStackElement(); elem.Destination = root.SubPlotMap[includeStmt.SubPlot]; elem.Location = includeStmt.Location; elem.ReturnDest = null; kernel.RuntimeData.CallStack.Push(elem); kernel.Next(); }
internal void Push(CallStackElement element) { callStack.Push(element); }