Exemplo n.º 1
0
        public static Lambda GenerateGlobalScopeConstructor(this Project globalScope, Context ctx)
        {
            var nodesToDeclare    = globalScope.NodesDeclaredInScope();
            var nodesToInitialize = globalScope.NodesToInitializeInScope();

            // Making a new name for the transformed application ctor that takes an App as parameter
            // This is so we can still keep the regular ctor for use in other ux files
            var mutatingAppCtorName = ctx.Names.GetUniqueName();
            var names  = ctx.Names.Reserve(mutatingAppCtorName).GenerateNames(nodesToDeclare);
            var newCtx = ctx.With(names: names);

            var declarations = nodesToDeclare.GetDeclarations(newCtx).ToImmutableList();

            var appCtor = declarations.FirstOrDefault(decl => decl.IsAppConstructor());

            if (appCtor == null)
            {
                throw new MissingAppTag();
            }

            return(new Lambda(
                       Signature.Action(Variable.This),
                       localVariables:
                       declarations,
                       statements:
                       nodesToInitialize.GetInitializations(newCtx)
                       .Concat(nodesToDeclare.RegisterGlobalKeys(newCtx))
                       .Concat(new [] { new CallLambda(new ReadVariable(appCtor.Variable), new ReadVariable(Variable.This)) })));
        }
Exemplo n.º 2
0
 public static IBinaryMessage Execute(ObjectIdentifier id, Func <Expression, Statement> objectTransform)
 {
     return(new BytecodeUpdated(
                new Lambda(
                    Signature.Action(),
                    Enumerable.Empty <BindVariable>(),
                    new[] { ExecuteStatement(id, objectTransform) })));
 }
Exemplo n.º 3
0
 static Statement ExecuteStatementMultiple(ObjectIdentifier id, Func <Expression, Statement[]> objectTransform)
 {
     return(new CallStaticMethod(
                TryExecuteOnObjectsWithTag,
                new StringLiteral(id.ToString()),
                new Lambda(
                    Signature.Action(Variable.This),
                    Enumerable.Empty <BindVariable>(),
                    objectTransform(new ReadVariable(Variable.This)))));
 }
Exemplo n.º 4
0
 public IObservable <CoalesceEntry> CreateMessages(FileDataWithMetadata <T> file)
 {
     try
     {
         return(_statementToExecute(file)
                .Select(s => new[] { s }.MakeExecute())
                .ToCoalesceEntry(file.Metadata.ToString(), addFirst: true));
     }
     catch (Exception)
     {
         return(Observable.Return(new BytecodeUpdated(new Lambda(Signature.Action(), Enumerable.Empty <BindVariable>(), Enumerable.Empty <Statement>())))
                .ToCoalesceEntry("invalid-file-dependency"));
     }
 }
Exemplo n.º 5
0
        IObservable <CoalesceEntry> ReifyProject(IObservable <ProjectBytecode> bytecode, IObservable <BytecodeUpdated> bytecodeUpdated, CoalesceEntryCache cache, IObservable <IEnumerable <AbsoluteFilePath> > assets)
        {
            int idx             = 0;
            var bytecodeUpdates = bytecodeUpdated.Select(m => m.ToCoalesceEntry(BytecodeUpdated.MessageType + (++idx)))
                                  .Publish()
                                  .RefCount();

            var clearOldUpdates = bytecodeUpdates
                                  .Buffer(bytecode)
                                  .Select(
                oldUpdates =>
            {
                var cachedUpdates = new List <CoalesceEntry>();
                foreach (var oldUpdate in oldUpdates)
                {
                    cachedUpdates.Add(new CoalesceEntry()
                    {
                        BlobData    = Optional.None(),
                        CoalesceKey = oldUpdate.CoalesceKey
                    });
                }
                return(cachedUpdates);
            })
                                  .SelectMany(t => t);

            var reify = bytecode.WithLatestFromBuffered(assets, (bc, ass) =>
            {
                var waitForDependencies = Task.WaitAll(new []
                {
                    bc.Dependencies.Select(d => cache.HasEntry(d.ToString()))
                    .ToObservableEnumerable()
                    .FirstAsync()
                    .ToTask(),
                    ass.Select(d => cache.HasEntry(d.ToString()))
                    .ToObservableEnumerable()
                    .FirstAsync()
                    .ToTask()
                }, TimeSpan.FromSeconds(60));

                if (waitForDependencies == false)
                {
                    throw new TimeoutException("Failed to load all assets dependencies.");
                }

                try
                {
                    return(new BytecodeGenerated(
                               new ProjectBytecode(
                                   reify: new Lambda(
                                       Signature.Action(Variable.This),
                                       Enumerable.Empty <BindVariable>(),
                                       new[]
                    {
                        ExpressionConverter.BytecodeFromSimpleLambda(() => ObjectTagRegistry.Clear()),

                        new CallLambda(bc.Reify, new ReadVariable(Variable.This)),
                    }),
                                   metadata: bc.Metadata,
                                   dependencies: bc.Dependencies))
                           .ToCoalesceEntry(BytecodeGenerated.MessageType));
                }
                catch (Exception)
                {
                    return(new BytecodeUpdated(
                               new Lambda(
                                   Signature.Action(),
                                   Enumerable.Empty <BindVariable>(),
                                   Enumerable.Empty <Statement>()))
                           .ToCoalesceEntry("invalid-byte-code"));
                }
            })
                        .CatchAndRetry(TimeSpan.FromSeconds(15),
                                       e =>
            {
                _logMessages.OnNext("Failed to refresh because: " + e.Message);
            });

            return(Observable.Merge(clearOldUpdates, reify, bytecodeUpdates));
        }
Exemplo n.º 6
0
        static Expression GetPropertyExpression(Context ctx, Property property, Optional <Expression> maybeObj)
        {
            var propertyName = property.GetMemberName();
            var propertyType = property.Facet.DataType.GetTypeName();

            var vars = ctx.Names;

            var propObj = vars.GetUniqueName();

            vars = vars.Reserve(propObj);

            var value = vars.GetUniqueName();

            vars = vars.Reserve(value);

            var origin = vars.GetUniqueName();

            vars = vars.Reserve(origin);

            if (ctx.IsDeclaredInUx(property))
            {
                var setter = new Lambda(
                    signature: Signature.Action(propObj, value, origin),
                    localVariables: new BindVariable[0],
                    statements: new Statement[]
                {
                    new CallStaticMethod(
                        StaticMemberName.Parse("Uno.UX.SimulatedProperties.Set"),
                        new ReadVariable(propObj),
                        new StringLiteral(propertyName.Name),
                        new ReadVariable(value),
                        new ReadVariable(origin))
                });

                var getter = new Lambda(
                    signature: new Signature(List.Create(new Parameter(TypeName.Parse("object"), propObj)), propertyType),
                    localVariables: new BindVariable[0],
                    statements: new Statement[]
                {
                    new Return(
                        new CallStaticMethod(
                            StaticMemberName.Parse("Uno.UX.SimulatedProperties.Get"),
                            new ReadVariable(propObj),
                            new StringLiteral(propertyName.Name))),
                });

                var mp = (IMutableProperty)property.Facet;

                return(new Instantiate(
                           UxPropertyType.Parameterize(propertyType),
                           setter,
                           getter,
                           maybeObj.Or((Expression) new StringLiteral(null)),
                           // the only null we've got is string
                           new StringLiteral(propertyName.Name),
                           new BooleanLiteral(mp.OriginSetterName != null)
                           ));
            }
            else
            {
                var obj = maybeObj.Or((Expression) new ReadVariable(propObj));

                var setter = new Lambda(
                    signature: Signature.Action(propObj, value, origin),
                    localVariables: new BindVariable[0],
                    statements: new[]
                {
                    property.SetValueStatement(ctx, obj, new ReadVariable(value), new ReadVariable(origin))
                });

                var getter = new Lambda(
                    signature: new Signature(List.Create(new Parameter(TypeName.Parse("object"), propObj)), propertyType),
                    localVariables: new BindVariable[0],
                    statements: new[]
                {
                    new Return(property.GetValueStatement(ctx, obj))
                });

                var mp = (IMutableProperty)property.Facet;

                return(new Instantiate(
                           UxPropertyType.Parameterize(propertyType),
                           setter,
                           getter,
                           maybeObj.Or((Expression) new StringLiteral(null)),
                           // the only null we've got is string
                           new StringLiteral(propertyName.Name),
                           new BooleanLiteral(mp.OriginSetterName != null)
                           ));
            }
        }