public void Dispose() { // releases gc refs just in case block = null; vf = null; runner = null; }
private void RunForEach(ForEachStatementSyntax node) { var list = RunExpression(node.Expression); var e = list.GetEnumerator(); Vars = new VarFrame(Vars); while (true) { if (e.MoveNext() == false) { break; } Vars.SetValue($"{node.Identifier}", e.Current.Wrap()); Run(node.Statement); if (Halt == HaltType.Continue || Halt == HaltType.YieldReturn) { Halt = HaltType.None; } if (Halt != HaltType.None) { break; } } Vars = Vars.Parent; if (Halt == HaltType.Break) { Halt = HaltType.None; } }
private HybInstance RunArrowExpressionClause(ArrowExpressionClauseSyntax node, VarFrame vf) { Vars = vf; var ret = RunExpression(node.Expression); Vars = Vars.Parent; return(ret); }
internal int RunBlock(BlockSyntax node, VarFrame vf, int pc = 0) { var prevVars = Vars; Vars = vf; var children = node.ChildNodes().ToArray(); if (children.Length == pc) { return(-1); } for (; pc < children.Length; pc++) { var child = children[pc]; try { Run(child); } catch (Exception e) when(Catches.Count > 0) { Console.WriteLine(e); foreach (var c in Catches.Reverse()) { if (c.RunCatch(e)) { break; } } } if (Ctx.IsExpird()) { throw new TimeoutException(); } if (Halt != HaltType.None) { pc++; break; } } Vars = prevVars; return(pc); }
private void ActionBody(SeparatedSyntaxList <ParameterSyntax> ps, BlockSyntax body, params object[] args) { var vf = new VarFrame(Vars); for (int i = 0; i < ps.Count; i++) { vf.SetValue($"{ps[i].Identifier}", HybInstance.Object(args[i])); } RunBlock(body as BlockSyntax, vf); if (Halt == HaltType.Return) { Halt = HaltType.None; } }
private void RunFor(ForStatementSyntax node) { Vars = new VarFrame(Vars); Run(node.Declaration); while (true) { if (node.Condition != null) { var cond = RunExpression(node.Condition); if (IsTrueOrEquivalent(cond) == false) { break; } } Run(node.Statement); if (Halt == HaltType.Continue) { Halt = HaltType.None; } if (Halt != HaltType.None) { break; } foreach (var expr in node.Incrementors) { RunExpression(expr); } } if (Halt == HaltType.Break) { Halt = HaltType.None; } Vars = Vars.Parent; }
public bool RunCatch(Exception e) { foreach (var c in TryNode.Catches) { var type = $"{c.Declaration.Type}"; var rt = Runner.Resolver.GetType(type); if (rt == null) { continue; } if (e.GetType().IsSubclassOf(rt)) { var vf = new VarFrame(Runner.Vars); vf.SetValue($"{c.Declaration.Identifier}", HybInstance.Object(e)); Runner.RunBlock(c.Block, vf); return(true); } } return(false); }
public VarCapture(VarFrame parent) : base(parent) { }
internal HybInstance RunMethod(SSInterpretMethodInfo method, HybInstance[] args) { Ret = null; Ctx.PushMethod(method); var node = ((SSInterpretMethodInfo)method).Declaration; var vf = new VarFrame(null); var count = 0; foreach (var p in method.Parameters) { if (p.DefaultValue == null) { continue; } vf.SetValue(p.Id, p.DefaultValue); } foreach (var arg in args) { var p = method.Parameters[count++]; if (p.IsParams) { break; } vf.SetValue(p.Id, arg); } if (method.IsVaArg) { var paramId = node.ParameterList.Parameters.Last() .Identifier.Text; var vaArgs = args.Skip(count - 1).ToArray(); vf.SetValue(paramId, HybInstance.ObjectArray(vaArgs)); } Frames.Push(Vars); Vars = null; if (node.Body != null) { if (method.ReturnType != null && // ctor doesn't have return type method.ReturnType.IsCompiledType && method.ReturnType.CompiledType == typeof(IEnumerator)) { var enumerator = new SSEnumerator(this, node.Body, vf); Ret = HybInstance.Object(enumerator); } else { RunBlock(node.Body, vf); } } else { Ret = RunArrowExpressionClause(node.ExpressionBody, vf); } Vars = Frames.Pop(); if (Halt == HaltType.Return) { Halt = HaltType.None; } Ctx.PopMethod(); return(Ret); }
internal SSEnumerator(Runner runner, BlockSyntax node, VarFrame vf) { this.runner = runner; this.block = node; this.vf = vf; }
public VarFrame(VarFrame parent) { this.Parent = parent; }