Exemplo n.º 1
0
 protected override FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs)
 {
     return new FuncitonFunction(outputs, DeclarationName);
 }
Exemplo n.º 2
0
 public LessThanNode(FuncitonFunction thisFunction, Node left, Node right)
     : base(thisFunction, left, right)
 {
 }
Exemplo n.º 3
0
 protected abstract FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs);
Exemplo n.º 4
0
 public LambdaExpressionParameterNode(FuncitonFunction thisFunction, int id)
     : base(thisFunction)
 {
     LambdaParameterId = id;
 }
Exemplo n.º 5
0
 public LambdaInvocationOutputNode(FuncitonFunction thisFunction, int outputPosition, LambdaInvocation invocation)
     : base(thisFunction)
 {
     OutputPosition = outputPosition;
     Invocation = invocation;
 }
Exemplo n.º 6
0
 public NandNode(FuncitonFunction thisFunction, Node left, Node right)
     : base(thisFunction)
 {
     Left = left;
     Right = right;
 }
Exemplo n.º 7
0
            public int LambdaParameterId; // for GetExpression

            #endregion Fields

            #region Constructors

            public LambdaExpressionParameterNode(FuncitonFunction thisFunction)
                : base(thisFunction)
            {
                LambdaParameterId = LambdaParameterCounter++;
            }
Exemplo n.º 8
0
 public CrossWireNode(FuncitonFunction thisFunction, Node left, Node right)
     : base(thisFunction)
 {
     Left = left;
     Right = right;
 }
Exemplo n.º 9
0
 public InputNode(FuncitonFunction thisFunction, int inputPosition)
     : base(thisFunction)
 {
     InputPosition = inputPosition;
 }
Exemplo n.º 10
0
 public Call(FuncitonFunction function, Node[] inputs)
 {
     Function = function;
     Inputs = inputs;
 }
Exemplo n.º 11
0
 public CallOutputNode(FuncitonFunction thisFunction, int outputPosition, Call call)
     : base(thisFunction)
 {
     if (call == null)
         throw new ArgumentNullException("call");
     OutputPosition = outputPosition;
     Call = call;
 }
Exemplo n.º 12
0
 public StdInNode(FuncitonFunction thisFunction)
     : base(thisFunction)
 {
 }
Exemplo n.º 13
0
 public ShiftLeftNode(FuncitonFunction thisFunction, Node left, Node right)
     : base(thisFunction, left, right)
 {
 }
Exemplo n.º 14
0
 public Node(FuncitonFunction thisFunction)
 {
     _thisFunction = thisFunction;
 }
Exemplo n.º 15
0
 protected override FuncitonFunction createFuncitonFunction(FuncitonFunction.Node[] outputs)
 {
     return new FuncitonProgram(outputs);
 }
Exemplo n.º 16
0
 public LambdaExpressionNode(FuncitonFunction thisFunction)
     : base(thisFunction)
 {
 }
Exemplo n.º 17
0
            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;
            }
Exemplo n.º 18
0
 public LiteralNode(FuncitonFunction thisFunction, BigInteger literal)
     : base(thisFunction)
 {
     _result = literal;
 }