public override void Execute(NetStack stack) { dynamic r = stack.Pop(); dynamic l = stack.Pop(); stack.Push(l + r); //throw new ArgumentException(string.Format("Cannot add operands of type {0} and {1}", l.GetType().Name, r.GetType().Name)); }
public NetStack Evaluate(NetStack stack, string input) { var statement = parser.Parse(input); try { statement.Evaluate(stack); } catch (Exception e) { throw new RuntimeException(e); } return stack; }
public override void Execute(NetStack stack) { var condition = stack.Pop<Statement>(); var body = stack.Pop<Statement>(); condition.Evaluate(stack); var result = stack.Pop<bool>(); while (result) { body.Evaluate(stack); condition.Evaluate(stack); result = stack.Pop<bool>(); } }
public void Evaluate(NetStack stack) { foreach(var token in Tokens) { try { token.Execute(stack); } catch (StackEmptyException) { throw new StackEmptyException(string.Format("\"{0}\" attempted to pop a frame while the stack was empty.", token.GetType().FullName)); } } }
public override void Execute(NetStack stack) { Statement functionBody; try { functionBody = stack.GetFunction(label); } catch (KeyNotFoundException) { throw new RuntimeBinderException(string.Format("Failed to call function (no binding for \"{0}\" exists).", label)); } functionBody.Evaluate(stack); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Netstack REPL."); var runtime = new NetstackRuntime(); bool quitRequested = false; NetStack stack = new NetStack(); while (!quitRequested) { Console.Write("> "); var input = Console.ReadLine(); if(input == "quit") { quitRequested = true; }else { try { stack = runtime.Evaluate(stack.Clear(), input); var previousColour = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.White; Console.Write("--> "); Console.WriteLine(stack.ToString()); Console.ForegroundColor = previousColour; } catch (RuntimeException e) { var previousColour = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Execution halted: " + e.InnerException.Message); Console.ForegroundColor = previousColour; } catch (SyntaxException e) { var previousColour = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Parsing fail: " + e.InnerException.Message); Console.ForegroundColor = previousColour; } } } Console.WriteLine("Goodbye"); }
public override void Execute(NetStack stack) { var top = stack.Pop(); var bottom = stack.Pop(); stack.Push(top).Push(bottom); }
public override void Execute(NetStack stack) { dynamic r = stack.Pop(); dynamic l = stack.Pop(); stack.Push(l > r); }
public override void Execute(NetStack stack) { var l = stack.Pop(); var r = stack.Pop(); stack.Push(l.Equals(r)); }
public override void Execute(NetStack stack) { stack.Clear(); }
public override void Execute(NetStack stack) { stack.Pop(); }
public override void Execute(NetStack stack) { Console.Write("input> "); stack.Push(Console.ReadLine()); }
public override void Execute(NetStack stack) { var label = stack.Pop<string>(); stack.Push(new FunctionLabel(label)); }
public override void Execute(NetStack stack) { var val = stack.Pop(); stack.Push(val).Push(val); }
public abstract void Execute(NetStack stack);
public override void Execute(NetStack stack) { stack.Push(value); }
public override void Execute(NetStack stack) { dynamic variable = stack.Pop(); stack.Push(++variable); }
public override void Execute(NetStack stack) { var offset = stack.Pop<long>(); var value = stack.Peek(offset); stack.Push(value); }
public override void Execute(NetStack stack) { stack.Push(new Parser().Parse(stack.Pop<string>())); }
public NetStack Evaluate(string input) { var stack = new NetStack(); return Evaluate(stack, input); }
public override void Execute(NetStack stack) { stack.Push(stack.Pop<long>() - 1); }
public override void Execute(NetStack stack) { var statement = stack.Pop() as Statement; statement.Evaluate(stack); }
public override void Execute(NetStack stack) { stack.Reset(); }
public override void Execute(NetStack stack) { stack.Push(this); }
public override void Execute(NetStack stack) { var label = stack.Pop<FunctionLabel>(); var body = stack.Pop<Statement>(); stack.BindFunction(body, label.Label); }