private void InitScopesByTree(ScopeTreeNode node, RuntimeScope parent) { foreach (var n in node.Children) { if (n.Scope == null) { continue; } InitScopesByTree(n, new RuntimeScope(parent, n.Scope)); } }
private static void UpdateScopeTreeAfterOpen(IScope scope, ParseContext context) { var newNode = new ScopeTreeNode(scope); if (context.CurrentNode != null) { context.CurrentNode.AddChild(newNode); } else { context.ScopeTree.AddNode(newNode); } context.CurrentNode = newNode; }
public Function Function(List args, CodeBlock block) { var functionsScope = new ScopeTreeNode(Permanency.NonPermanent, Interpreter.CurrentScopeNode); Func<List<Value>, Value> code = delegate(List<Value> list) { var tempScope = new ScopeTreeNode(Permanency.NonPermanent, functionsScope.Parent); Interpreter.EnterScope(tempScope); for (int i = 0; i < list.Count; ++i) { var name = args.InnerList[i].Var.OriginalName; Interpreter.CurrentScopeNode.AddToScope(name, list[i]); } var ret = block.Execute(Interpreter); if (ret.Type <= ValueType.ReturnValue) ret = (ret as ReturnValue).InnerValue; Interpreter.ExitScope(); return ret; }; var fun = new CSharpFunction(code, Fixity.Prefix, args.InnerList.Count) { FunctionScope = functionsScope }; fun.Signature.InputSignature.Clear(); args.Select(v => v.Type).ToList().ForEach(t => fun.Signature.InputSignature.Add(t == ValueType.BlankIdentifier ? ValueType.Uncertain : t)); return fun; }