public static void Exit( this NeuInterpreter interpreter, NeuNode node) { var frame = interpreter.Stack.First(); /// var frameNode = frame.Node as NeuNode; if (frameNode == null) { throw new Exception(); } /// if (!Equals(frameNode, node)) { throw new Exception(); } /// interpreter.Stack.Pop(); }
public static NeuOperation?CreateOperation( this Interpreter <NeuFrame, NeuOperation> interpreter, String?name, String?moduleName, String?namespaceName, String?typeName, NeuNode node) { if (interpreter.OperationExists(name, moduleName, namespaceName, typeName)) { throw new Exception(); } /// var op = new NeuOperation(name, moduleName, namespaceName, typeName, node, false, true); interpreter.VTable.Add(op); return(op); }
public static void Unwind( this NeuInterpreter interpreter, int enterPos, NeuNode node) { var exitPos = interpreter.Stack.Count(); /// var additionalStackFrames = exitPos - enterPos; if (additionalStackFrames > 0) { for (var i = additionalStackFrames; i > 0; --i) { var frame = interpreter.Stack.Pop(); /// switch (frame) { default: // TODO: add to results? // throw new Exception(); break; } } } else if (additionalStackFrames < 0) { throw new Exception(); } }
public static void Enter( this NeuInterpreter interpreter, NeuNode node) { interpreter.Stack.Push(new NeuScopeFrame(node)); }
public static NeuOperation Execute( this NeuInterpreter interpreter, NeuNode node, params object[] arguments) { interpreter.Enter(node); /// /// // TODO: Add hoists /// var enterPos = interpreter.Stack.Count(); /// var lastValue = NeuOperation.Void; /// var done = false; /// for (var i = 0; i < node.Children.Count() && !done; i++) { var child = node.Children.ElementAt(i); /// if (child is NeuPunc) { continue; } /// var childResult = interpreter.Execute(child); /// switch (childResult) { case NeuReturnResult returnResult: lastValue = returnResult; done = true; break; /// case NeuValue value: lastValue = value; break; /// default: break; } } /// interpreter.Unwind(enterPos, node); /// interpreter.Exit(node); /// return(lastValue); }