Esempio n. 1
0
 public void Build(IFinalizedScope scope, IReadOnlyList <IAssignOperation> assignments, IEntryPointDefinition entryPoint)
 {
     buildableScope.Set(scope);
     buildableAssignments.Set(assignments);
     buildableEntryPoint.Set(entryPoint);
     type = InterfaceType.CreateAndBuild(scope.Members.Values.Select(x => MemberDefinition.CreateAndBuild(x.Value.Key, x.Value.Type, x.Value.Access)).ToList());
 }
Esempio n. 2
0
        public PointObject()
        {
            var keyX   = new NameKey("x");
            var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), Access.ReadWrite);
            var keyY   = new NameKey("y");
            var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), Access.ReadWrite);

            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic>()
            {
                new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("point"), new AnyType(), Access.ReadWrite), false)
            }),
                new[] {
                AssignOperation.CreateAndBuild(
                    ObjectDefiniton.CreateAndBuild(
                        Scope.CreateAndBuild(
                            new List <IsStatic> {
                    new IsStatic(localX, false),
                    new IsStatic(localY, false)
                }),
                        new IAssignOperation[] {
                    AssignOperation.CreateAndBuild(
                        ConstantNumber.CreateAndBuild(5),
                        MemberReference.CreateAndBuild(localX)),
                    AssignOperation.CreateAndBuild(
                        ConstantNumber.CreateAndBuild(2),
                        MemberReference.CreateAndBuild(localY))
                },
                        InterfaceType.CreateAndBuild(new [] { localX, localY })),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("point"), new AnyType(), Access.ReadWrite)))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }
Esempio n. 3
0
        public PairType()
        {
            var pairTypeNumber =
                InterfaceType.CreateAndBuild(
                    new List <IMemberDefinition> {
                MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), false),
                MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), false)
            });

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), false);

            var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> {
                new Scope.IsStatic(input, false)
            });

            var localX = MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), false);
            var localY = MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), false);

            var pairifyKey = new NameKey("pairify");
            var pairify    = MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), false);

            Module = ModuleDefinition.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <Scope.IsStatic> {
                new Scope.IsStatic(MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), false), false)
            }),
                new ICodeElement[] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        new NumberType(),
                        pairTypeNumber,
                        input,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        ObjectDefiniton.CreateAndBuild(
                            Scope.CreateAndBuild(
                                new List <Scope.IsStatic> {
                        new Scope.IsStatic(localX, false),
                        new Scope.IsStatic(localY, false)
                    }),
                            new IAssignOperation[] {
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localX)),
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localY))
                    }))
                },
                        new ICodeElement[0],
                        false),
                    MemberReference.CreateAndBuild(pairify))
            },
                new NameKey("pair-type"));
        }
Esempio n. 4
0
        public PairType()
        {
            var pairTypeNumber =
                InterfaceType.CreateAndBuild(
                    new List <IMemberDefinition> {
                MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), Access.ReadWrite),
                MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), Access.ReadWrite)
            });

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), Access.ReadWrite);

            var methodScope = Scope.CreateAndBuild(new List <IsStatic> {
                new IsStatic(input, false)
            });

            var localX = MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), Access.ReadWrite);
            var localY = MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), Access.ReadWrite);

            var pairifyKey = new NameKey("pairify");
            var pairify    = MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), Access.ReadWrite);

            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic> {
                new IsStatic(MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), Access.ReadWrite), false)
            }),
                new [] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        pairTypeNumber,
                        input,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        ObjectDefiniton.CreateAndBuild(
                            Scope.CreateAndBuild(
                                new List <IsStatic> {
                        new IsStatic(localX, false),
                        new IsStatic(localY, false)
                    }),
                            new IAssignOperation[] {
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localX)),
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localY))
                    },
                            InterfaceType.CreateAndBuild(new [] { localX, localY })))
                },
                        Array.Empty <ICodeElement>()),
                    MemberReference.CreateAndBuild(pairify))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }
Esempio n. 5
0
        public MirrorPointImplementation()
        {
            var keyX   = new NameKey("x");
            var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), false);

            var keyY   = new NameKey("y");
            var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), false);

            var contextKey = new NameKey("context");

            var context = MemberDefinition.CreateAndBuild(
                contextKey,
                InterfaceType.CreateAndBuild(
                    Scope.CreateAndBuild(
                        new List <Scope.IsStatic>()
            {
                new Scope.IsStatic(localX, false),
                new Scope.IsStatic(localY, false),
            }).Members),
                false);;

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new EmptyType(), false);

            var tempKey = new NameKey("temp");
            var temp    = MemberDefinition.CreateAndBuild(tempKey, new AnyType(), false);

            var implementationScope = Scope.CreateAndBuild(
                new List <Scope.IsStatic> {
                new Scope.IsStatic(input, false),
                new Scope.IsStatic(temp, false)
            });


            Module = ModuleDefinition.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <Scope.IsStatic>()
            {
                new Scope.IsStatic(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), false), false)
            }),
                new[] {
                AssignOperation.CreateAndBuild(
                    ImplementationDefinition.CreateAndBuild(
                        new EmptyType(),
                        context,
                        input,
                        implementationScope,
                        new ICodeElement[] {
                    AssignOperation.CreateAndBuild(
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)),
                        MemberReference.CreateAndBuild(temp)
                        ),
                    AssignOperation.CreateAndBuild(
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)),
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX))
                        ),
                    AssignOperation.CreateAndBuild(
                        MemberReference.CreateAndBuild(temp),
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY))
                        )
                },
                        new ICodeElement[0]),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), false)))
            },
                new NameKey("mirror-module"));
        }
Esempio n. 6
0
 public IVerifiableType Returns()
 {
     return(InterfaceType.CreateAndBuild(Scope.Members));
 }
Esempio n. 7
0
        public async Task Execute()
        {
            if (Running)
            {
                return;
            }

            outputBacking.consoleLines.Clear();
            task = Task.WhenAll(
                Task.Delay(1000),
                Task.Run(() =>
            {
                try
                {
                    var result = Run.CompileAndRun <Empty, Empty>(
                        "test",
                        InputValue,
                        null,
                        new[] {
                        new Tac.Backend.Emit.Assembly(
                            new NameKey("in"),
                            InterfaceType.CreateAndBuild(
                                new List <IMemberDefinition>()
                        {
                            MemberDefinition.CreateAndBuild(
                                new NameKey("read-number"),
                                MethodType.CreateAndBuild(
                                    new EmptyType(),
                                    new NumberType()),
                                Access.ReadOnly),
                            MemberDefinition.CreateAndBuild(
                                new NameKey("read-string"),
                                MethodType.CreateAndBuild(
                                    new EmptyType(),
                                    new StringType()),
                                Access.ReadOnly),
                            MemberDefinition.CreateAndBuild(
                                new NameKey("read-bool"),
                                MethodType.CreateAndBuild(
                                    new EmptyType(),
                                    new BooleanType()),
                                Access.ReadOnly)
                        }),
                            new InputBacking()),
                        new Tac.Backend.Emit.Assembly(
                            new NameKey("out"),
                            InterfaceType.CreateAndBuild(
                                new List <IMemberDefinition> {
                            MemberDefinition.CreateAndBuild(
                                new NameKey("write-number"),
                                MethodType.CreateAndBuild(
                                    new NumberType(),
                                    new EmptyType()),
                                Access.ReadOnly),
                            MemberDefinition.CreateAndBuild(
                                new NameKey("write-string"),
                                MethodType.CreateAndBuild(
                                    new StringType(),
                                    new EmptyType()),
                                Access.ReadOnly),
                            MemberDefinition.CreateAndBuild(
                                new NameKey("write-bool"),
                                MethodType.CreateAndBuild(
                                    new BooleanType(),
                                    new EmptyType()),
                                Access.ReadOnly)
                        }),
                            outputBacking)
                    });

                    result.Switch(
                        val =>
                    {
                        // it has to return empty otherwise we crash
                    },
                        errors =>
                    {
                        foreach (var error in errors)
                        {
                            outputBacking.consoleLines.Add("error: " + error);
                        }
                    });
                }
                catch (Exception e)
                {
                    outputBacking.consoleLines.Add(e.Message);
                }
            }));
            await task;
        }
Esempio n. 8
0
 internal static IInterpetedStaticScope EmptyStaticScope()
 {
     return(StaticScope(new ConcurrentIndexed <IKey, IInterpetedMember>(), InterfaceType.CreateAndBuild(new List <IMemberDefinition>())));
 }
        public MirrorPointImplementation()
        {
            var keyX   = new NameKey("x");
            var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), Access.ReadWrite);

            var keyY   = new NameKey("y");
            var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), Access.ReadWrite);

            var contextKey = new NameKey("context");

            var context = MemberDefinition.CreateAndBuild(
                contextKey,
                InterfaceType.CreateAndBuild(
                    Scope.CreateAndBuild(
                        new List <IsStatic>()
            {
                new IsStatic(localX, false),
                new IsStatic(localY, false),
            }).Members.Values.Select(x => x.Value).ToList()),
                Access.ReadWrite);;

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new EmptyType(), Access.ReadWrite);

            var tempKey = new NameKey("temp");
            var temp    = MemberDefinition.CreateAndBuild(tempKey, new AnyType(), Access.ReadWrite);

            var implementationScope = Scope.CreateAndBuild(
                new List <IsStatic> {
                new IsStatic(input, false),
                new IsStatic(temp, false)
            });

            var intermediateScope = Scope.CreateAndBuild(
                new List <IsStatic> {
                new IsStatic(context, false)
            });


            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic>()
            {
                new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), Access.ReadWrite), false)
            }),
                new[] {
                AssignOperation.CreateAndBuild(
                    ImplementationDefinition.CreateAndBuild(
                        new EmptyType(),
                        context,
                        input,
                        implementationScope,
                        new ICodeElement[] {
                    AssignOperation.CreateAndBuild(
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)),
                        MemberReference.CreateAndBuild(temp)
                        ),
                    AssignOperation.CreateAndBuild(
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)),
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX))
                        ),
                    AssignOperation.CreateAndBuild(
                        MemberReference.CreateAndBuild(temp),
                        PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY))
                        )
                },
                        Array.Empty <ICodeElement>(),
                        intermediateScope),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), Access.ReadWrite)))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }