protected override Expression GetBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { var uninitialized = new HashSet <INode>(); NodeUtils.GatherUninitializedIds(EntryPoint, symbols, letEntries, initializedIds, uninitialized); var initialized = new List <Expression>(); foreach (var node in uninitialized) { var symbol = symbols[node]; if (!initializedIds.Contains(symbol)) { symbols.Remove(node); var binding = node.compile(symbols, letEntries, initializedIds, conditionalIds); symbols[node] = symbol; initialized.Add(Expression.NewSetId(symbol, binding)); initializedIds.Add(symbol); } } initialized.Add(Utils.MakeAnon( Inputs, EntryPoint.compile(symbols, letEntries, initializedIds, conditionalIds))); return(Expression.NewBegin(Utils.SequenceToFSharpList(initialized))); }
protected override Expression compileBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { return(Expression.NewBegin( Utils.SequenceToFSharpList( Inputs.Select( x => arguments[x].compile(symbols, letEntries, initializedIds, conditionalIds))))); }
private static Expression WrapLets( Expression body, Dictionary <INode, string> symbols, List <INode> bindings) { return(Expression.NewLet( Utils.SequenceToFSharpList( bindings.Select(x => symbols[x]) .Concat(bindings.Select(x => symbols[x] + "-init"))), Utils.SequenceToFSharpList( Enumerable.Repeat( Expression.NewBegin(FSharpList <Expression> .Empty), bindings.Count) .Concat(Enumerable.Repeat(Expression.NewNumber_E(0), bindings.Count))), body)); }
private Expression __compileBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { string symbol; if (symbols.TryGetValue(this, out symbol)) { var body = Expression.NewId(symbol); if (conditionalIds.Contains(symbol)) { symbols.Remove(this); var binding = compile(symbols, letEntries, initializedIds, conditionalIds); symbols[this] = symbol; body = Expression.NewIf( Expression.NewId(symbol + "-init"), body, Expression.NewBegin( Utils.MakeFSharpList( Expression.NewSetId(symbol, binding), Expression.NewSetId(symbol + "-init", Expression.NewNumber_E(1)), body))); } else if (!initializedIds.Contains(symbol)) { symbols.Remove(this); var binding = compile(symbols, letEntries, initializedIds, conditionalIds); symbols[this] = symbol; body = Expression.NewBegin( Utils.MakeFSharpList( Expression.NewSetId(symbol, binding), Expression.NewSetId(symbol + "-init", Expression.NewNumber_E(1)), body)); initializedIds.Add(symbol); } return(body); } else { return(compileBody(symbols, letEntries, initializedIds, conditionalIds)); } }
protected override Expression compileBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { var arg = arguments.First().Value.compile( symbols, letEntries, initializedIds, conditionalIds); //idle :: (() -> A) -> A //Evaluates the given function in the Revit Idle thread. var idle = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( args => { var f = (args[0] as Value.Function).Item; if (dynSettings.Controller.DynamoViewModel.RunInDebug) { return(f.Invoke(FSharpList <Value> .Empty)); } return(IdlePromise <Value> .ExecuteOnIdle( () => f.Invoke(FSharpList <Value> .Empty))); })); //startTransaction :: () -> () //Starts a Dynamo Transaction. var startTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (_node.Controller.RunCancelled) { throw new CancelEvaluationException(false); } if (!dynSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.InIdleThread = true; dynRevitSettings.Controller.InitTransaction(); } return(Value.NewDummy("started transaction")); })); //endTransaction :: () -> () //Ends a Dynamo Transaction. var endTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (!dynRevitSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.EndTransaction(); dynRevitSettings.Controller.InIdleThread = false; dynSettings.Controller.DynamoViewModel.OnRequestLayoutUpdate(this, EventArgs.Empty); _node.ValidateConnections(); } else { _node.setDirty(false); } return(Value.NewDummy("ended transaction")); })); /* (define (idleArg) * (startTransaction) * (let ((a <arg>)) * (endTransaction) * a)) */ var idleArg = Expression.NewFun( FSharpList <FScheme.Parameter> .Empty, Expression.NewBegin( Utils.SequenceToFSharpList(new List <Expression> { Expression.NewList_E( Utils.SequenceToFSharpList( new List <Expression> { startTransaction })), Expression.NewLet( Utils.SequenceToFSharpList( new List <string> { "__result" }), Utils.SequenceToFSharpList( new List <Expression> { arg }), Expression.NewBegin( Utils.SequenceToFSharpList( new List <Expression> { Expression.NewList_E( Utils.SequenceToFSharpList( new List <Expression> { endTransaction })), Expression.NewId("__result") }))) }))); // (idle idleArg) return(Expression.NewList_E( Utils.SequenceToFSharpList(new List <Expression> { idle, idleArg }))); }