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>())); }
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")); }
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>())); }
public Closoure() { var xKey = new NameKey("x"); var x = MemberDefinition.CreateAndBuild(xKey, new NumberType(), false); var yKey = new NameKey("y"); var y = MemberDefinition.CreateAndBuild(yKey, new NumberType(), false); var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { new Scope.IsStatic(x, false) }); var innerMethodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { new Scope.IsStatic(y, false) }, methodScope); Module = ModuleDefinition.CreateAndBuild( Scope.CreateAndBuild( new List <Scope.IsStatic>() { new Scope.IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false), false) }), new[] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), MethodType.CreateAndBuild( new NumberType(), new NumberType()), x, methodScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), new NumberType(), y, innerMethodScope, new ICodeElement[] { AssignOperation.CreateAndBuild( AddOperation.CreateAndBuild( MemberReference.CreateAndBuild(x), MemberReference.CreateAndBuild(y)), MemberReference.CreateAndBuild(x)), ReturnOperation.CreateAndBuild( MemberReference.CreateAndBuild(x)) }, new ICodeElement[0], false) ) }, new ICodeElement[0], false), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false))) }, new NameKey("closoure")); }
public Closoure() { var xKey = new NameKey("x"); var x = MemberDefinition.CreateAndBuild(xKey, new NumberType(), Access.ReadWrite); var yKey = new NameKey("y"); var y = MemberDefinition.CreateAndBuild(yKey, new NumberType(), Access.ReadWrite); var methodScope = Scope.CreateAndBuild(new List <IsStatic> { new IsStatic(x, false) }); var innerMethodScope = Scope.CreateAndBuild(new List <IsStatic> { new IsStatic(y, false) }); RootScope = Model.Instantiated.RootScope.CreateAndBuild( Scope.CreateAndBuild( new List <IsStatic>() { new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), Access.ReadWrite), false) }), new [] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( MethodType.CreateAndBuild( new NumberType(), new NumberType()), x, methodScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), y, innerMethodScope, new ICodeElement[] { AssignOperation.CreateAndBuild( AddOperation.CreateAndBuild( MemberReference.CreateAndBuild(x), MemberReference.CreateAndBuild(y)), MemberReference.CreateAndBuild(x)), ReturnOperation.CreateAndBuild(MemberReference.CreateAndBuild(x)) }, Array.Empty <ICodeElement>()) ) }, Array.Empty <ICodeElement>()), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), 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>())); }
public Factorial() { var ifBlockScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { }); var elseBlock = Scope.CreateAndBuild(new List <Scope.IsStatic> { }); var inputKey = new NameKey("input"); var input = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), false); var facKey = new NameKey("fac"); var fac = MemberDefinition.CreateAndBuild(facKey, MethodType.CreateAndBuild(new NumberType(), new NumberType()), false); var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> { new Scope.IsStatic(input, false) }); Module = ModuleDefinition.CreateAndBuild( Scope.CreateAndBuild( new List <Scope.IsStatic> { new Scope.IsStatic(MemberDefinition.CreateAndBuild(facKey, MethodType.CreateAndBuild(new NumberType(), new NumberType()), false), false) }), new ICodeElement[] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), new NumberType(), input, methodScope, new ICodeElement[] { ElseOperation.CreateAndBuild( IfOperation.CreateAndBuild( LessThanOperation.CreateAndBuild( MemberReference.CreateAndBuild(input), ConstantNumber.CreateAndBuild(2)), BlockDefinition.CreateAndBuild( ifBlockScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( ConstantNumber.CreateAndBuild(1)) }, new ICodeElement[0])), BlockDefinition.CreateAndBuild( elseBlock, new ICodeElement[] { ReturnOperation.CreateAndBuild( MultiplyOperation.CreateAndBuild( NextCallOperation.CreateAndBuild( SubtractOperation.CreateAndBuild( MemberReference.CreateAndBuild(input), ConstantNumber.CreateAndBuild(1)), MemberReference.CreateAndBuild(fac)), MemberReference.CreateAndBuild(input))) }, new ICodeElement[0])) }, new ICodeElement[0], false), MemberReference.CreateAndBuild(fac) ) }, new NameKey("factorial") ); }
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")); }
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; }
public Factorial() { var ifBlockScope = Scope.CreateAndBuild(new List <IsStatic> { }); var elseBlock = Scope.CreateAndBuild(new List <IsStatic> { }); var inputKey = new NameKey("input"); var input = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), Access.ReadWrite); var facKey = new NameKey("fac"); var fac = MemberDefinition.CreateAndBuild(facKey, MethodType.CreateAndBuild(new NumberType(), new NumberType()), Access.ReadWrite); var methodScope = Scope.CreateAndBuild(new List <IsStatic> { new IsStatic(input, false) }); RootScope = Model.Instantiated.RootScope.CreateAndBuild( Scope.CreateAndBuild( new List <IsStatic> { new IsStatic(MemberDefinition.CreateAndBuild(facKey, MethodType.CreateAndBuild( new NumberType(), new NumberType()), Access.ReadWrite), false) }), new [] { AssignOperation.CreateAndBuild( MethodDefinition.CreateAndBuild( new NumberType(), input, methodScope, new ICodeElement[] { ElseOperation.CreateAndBuild( IfOperation.CreateAndBuild( LessThanOperation.CreateAndBuild( MemberReference.CreateAndBuild(input), ConstantNumber.CreateAndBuild(2)), BlockDefinition.CreateAndBuild( ifBlockScope, new ICodeElement[] { ReturnOperation.CreateAndBuild( ConstantNumber.CreateAndBuild(1)) }, Array.Empty <ICodeElement>())), BlockDefinition.CreateAndBuild( elseBlock, new ICodeElement[] { ReturnOperation.CreateAndBuild( MultiplyOperation.CreateAndBuild( NextCallOperation.CreateAndBuild( SubtractOperation.CreateAndBuild( MemberReference.CreateAndBuild(input), ConstantNumber.CreateAndBuild(1)), MemberReference.CreateAndBuild(fac)), MemberReference.CreateAndBuild(input))) }, Array.Empty <ICodeElement>())) }, Array.Empty <ICodeElement>()), MemberReference.CreateAndBuild(fac) ) }, EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()) ); }
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>())); }