protected override FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs) { return new FuncitonFunction(outputs, DeclarationName); }
public LessThanNode(FuncitonFunction thisFunction, Node left, Node right) : base(thisFunction, left, right) { }
protected abstract FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs);
public LambdaExpressionParameterNode(FuncitonFunction thisFunction, int id) : base(thisFunction) { LambdaParameterId = id; }
public LambdaInvocationOutputNode(FuncitonFunction thisFunction, int outputPosition, LambdaInvocation invocation) : base(thisFunction) { OutputPosition = outputPosition; Invocation = invocation; }
public NandNode(FuncitonFunction thisFunction, Node left, Node right) : base(thisFunction) { Left = left; Right = right; }
public int LambdaParameterId; // for GetExpression #endregion Fields #region Constructors public LambdaExpressionParameterNode(FuncitonFunction thisFunction) : base(thisFunction) { LambdaParameterId = LambdaParameterCounter++; }
public CrossWireNode(FuncitonFunction thisFunction, Node left, Node right) : base(thisFunction) { Left = left; Right = right; }
public InputNode(FuncitonFunction thisFunction, int inputPosition) : base(thisFunction) { InputPosition = inputPosition; }
public Call(FuncitonFunction function, Node[] inputs) { Function = function; Inputs = inputs; }
public CallOutputNode(FuncitonFunction thisFunction, int outputPosition, Call call) : base(thisFunction) { if (call == null) throw new ArgumentNullException("call"); OutputPosition = outputPosition; Call = call; }
public StdInNode(FuncitonFunction thisFunction) : base(thisFunction) { }
public ShiftLeftNode(FuncitonFunction thisFunction, Node left, Node right) : base(thisFunction, left, right) { }
public Node(FuncitonFunction thisFunction) { _thisFunction = thisFunction; }
protected override FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs) { return new FuncitonProgram(outputs); }
public LambdaExpressionNode(FuncitonFunction thisFunction) : base(thisFunction) { }
public virtual FuncitonFunction Parse(Dictionary<string, unparsedFunctionDeclaration> unparsedFunctionsByName, Dictionary<node, unparsedFunctionDeclaration> unparsedFunctionsByNode, Dictionary<unparsedDeclaration, FuncitonFunction> parsedFunctions) { var processedEdges = new HashSet<edge>(); Action<edge> isCorrect = e => { processedEdges.Add(e); }; Action<edge> isFlipped = e => { if (processedEdges.Contains(e)) throw new ParseErrorException( new ParseError("Program is ambiguous: cannot determine the direction of this edge.", e.StartX, e.StartY, _source.SourceFile), new ParseError("... edge ends here.", e.EndX, e.EndY, _source.SourceFile)); e.Flip(); processedEdges.Add(e); }; // Deduce all the inputs and outputs on every node var q = new Queue<node>(Nodes); var enqueued = 0; while (q.Count > 0) { var node = q.Dequeue(); var edges = new[] { direction.Up, direction.Right, direction.Down, direction.Left } .Select(dir => Edges.SingleOrDefault(e => (e.StartNode == node && e.DirectionFromStartNode == dir) || (e.EndNode == node && e.DirectionFromEndNode == dir))).ToArray(); var known = edges.Select(e => e != null && processedEdges.Contains(e)).ToArray(); if (!node.Deduce(edges, known, unparsedFunctionsByName, unparsedFunctionsByNode, isCorrect, isFlipped, _source)) { q.Enqueue(node); enqueued++; if (enqueued == q.Count) { var funcName = this is unparsedFunctionDeclaration ? "function “{0}”".Fmt(((unparsedFunctionDeclaration) this).DeclarationName) : "the main program"; throw new ParseErrorException(new ParseError("Program is ambiguous: cannot determine the direction of all the edges in {0}.".Fmt(funcName), null, null, _source.SourceFile)); } } else enqueued = 0; } Helpers.Assert(Nodes.All(n => n.Edges != null && n.Connectors != null)); var outputs = new FuncitonFunction.Node[4]; parsedFunctions[this] = _function = createFuncitonFunction(outputs); _unparsedFunctionsByName = unparsedFunctionsByName; _unparsedFunctionsByNode = unparsedFunctionsByNode; _parsedFunctions = parsedFunctions; foreach (var node in Nodes.Where(n => n.Type == nodeType.End)) { Helpers.Assert(node.Edges[0] != null); Helpers.Assert(node.Edges[1] == null && node.Edges[2] == null && node.Edges[3] == null); outputs[(int) node.Edges[0].DirectionFromEndNode] = walk(node.Edges[0], edge.EmptyArray, node.Edges[0]).Item1; } return _function; }
public LiteralNode(FuncitonFunction thisFunction, BigInteger literal) : base(thisFunction) { _result = literal; }