コード例 #1
0
        public ISetUpResult <IBox <WeakEmptyInstance>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();
            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var value = context.TypeProblem.CreateValue(runtimeScope, new NameKey("empty"));

            return(new SetUpResult <IBox <WeakEmptyInstance>, Tpn.IValue>(new EmptyInstanceResolveReferance(), OrType.Make <Tpn.IValue, IError>(value)));
        }
コード例 #2
0
ファイル: ReturnOperation.cs プロジェクト: Prototypist1/Tac
        public ISetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // return should never be in an object init
            // but other trailing operations might
            if (intoInitScope)
            {
                scope = scope.EnterInitizaionScopeIfNessisary();
            }

            var nextLeft = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));

            return(new SetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue>(
                       new TrailingResolveReferance <TFrontendCodeElement, TCodeElement>(nextLeft.TransformInner(x => x.Resolve), make),
                       getReturnedValue(scope, context, nextLeft)));
        }
コード例 #3
0
        public ISetUpResult <IBox <WeakMethodDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();
            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }


            var box       = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();
            var converter = new WeakMethodDefinitionConverter(box);

            var(method, realizedInput, realizedOutput) = context.TypeProblem.CreateMethod(scope,
                                                                                          x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                                                                                          x => output.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                                                                                          parameterName,
                                                                                          converter);

            var nextElements = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            //var value = context.TypeProblem.CreateTransientMember(runtimeScope, new GenericNameKey(new NameKey("method"), new IOrType<IKey, IError>[] {
            //        realizedInput.TransformInner(x=>x.Key()),
            //        realizedOutput.TransformInner(x=>x.Key()),
            //    }), "result-of-" + method.DebugName);

            //// TODO write a test
            //// {C28BDF52-A848-4D0A-824A-7F2943BCFE53}
            //// follow throw methods should work now.
            ////
            //// x > method [infer; infer] input { input return; } =: chicken c
            ////
            //// chicken need to flow through the method to x,
            ////
            //// C28BDF52-A848-4D0A-824A-7F2943BCFE53
            //// ... I think with my new type problem changes were method's become nodes and enter the type probelm
            //// I can clean this up quite a bit
            ////
            //// I think I have cleaned this up, just leaning it here until I get all my tests fixed

            //var inputMember = context.TypeProblem.GetInput(value);
            //context.TypeProblem.IsAssignedTo(inputMember, method.Input.GetOrThrow()/*lazy GetOrThrow*/);

            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);


            return(new SetUpResult <IBox <WeakMethodDefinition>, Tpn.TypeProblem2.Method>(new MethodDefinitionResolveReferance(method, nextElements, box), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }
コード例 #4
0
        public ISetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            if (intoInitScope)
            {
                scope = scope.EnterInitizaionScopeIfNessisary();
            }

            var nextLeft  = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));
            var nextRight = right.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));
            var value     = keyMaker(scope, context.CreateChildContext(this), nextLeft, nextRight);

            return(new SetUpResult <IBox <TFrontendCodeElement>, Tpn.IValue>(new BinaryResolveReferance <TFrontendCodeElement, TCodeElement>(
                                                                                 nextLeft.TransformInner(x => x.Resolve),
                                                                                 nextRight.TransformInner(x => x.Resolve),
                                                                                 make), value));
        }
コード例 #5
0
        public ISetUpResult <IBox <WeakObjectDefinition>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var key = new ImplicitKey(Guid.NewGuid());

            var box     = new Box <IReadOnlyList <IOrType <IBox <WeakAssignOperation>, IError> > >();
            var myScope = context.TypeProblem.CreateObjectOrModule(scope, key, new WeakObjectConverter(box), new WeakScopeConverter());

            // {6B83A7F1-0E28-4D07-91C8-57E6878E97D9}
            // module has similar code
            //foreach (var element in elements)
            //{
            //    element.Switch(
            //        y =>
            //        {
            //            list.Add(OrType.Make<IResolve<IBox<IFrontendCodeElement>>, IError>(y.Run(myScope, context).Resolve));
            //        },
            //        y =>
            //        {
            //            // it is a bit weird that types are not used at all
            //            y.Run(myScope, context);
            //        },
            //        y =>
            //        {
            //            // this is also a bit wierd, these errors are anything that was not parsed
            //            // they are not really related to the assignments they are bing placed next to
            //            list.Add(OrType.Make<IResolve<IBox<IFrontendCodeElement>>, IError>(y));
            //        });
            //}


            var nextElements = elements.Select(x =>
                                               x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();

            var value = context.TypeProblem.CreateValue(runtimeScope, key);

            // ugh! an object is a type
            //

            return(new SetUpResult <IBox <WeakObjectDefinition>, Tpn.IValue>(new ResolveReferanceObjectDefinition(myScope, nextElements, box), OrType.Make <Tpn.IValue, IError>(value)));
        }
コード例 #6
0
        public ISetUpResult <IBox <WeakPathOperation>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            var nextLeft = left.TransformInner(x => x.Run(scope, context.CreateChildContext(this)));

            var member = nextLeft.SwitchReturns(
                good =>
                name.SwitchReturns(
                    actualName =>
            {
                if (good.SetUpSideNode.Is1(out var nodeLeft) && nodeLeft is Tpn.IValue value)
                {
                    return(OrType.Make <Tpn.TypeProblem2.Member, IError>(context.TypeProblem.CreateHopefulMember(
                                                                             value,
                                                                             new NameKey(actualName))));
                }
コード例 #7
0
        public ISetUpResult <IBox <WeakConstantBool>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            // PlaceholderValueConverter is a little weird
            // I kind of think it should make the WeakConstantBool
            // yeah it totally should
            // TODO
            // this applies to my other constants
            var value = context.TypeProblem.CreateValue(runtimeScope, new NameKey("bool"));

            return(new SetUpResult <IBox <WeakConstantBool>, Tpn.IValue>(new ConstantBoolResolveReferance(dub), OrType.Make <Tpn.IValue, IError>(value)));
        }
コード例 #8
0
        public ISetUpResult <IBox <WeakImplementationDefinition>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();

            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            // TODO this is so painful, I think I need to look in to implementations having special treatment...
            // maybe they need to be a generic on the tpn
            // altho to the tpn they really are not special
            // but here they might maybe convert to an implementation not a method that returns a method
            // idk! 🤷‍😭

            IIsPossibly <(IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>)> pair =
                Possibly.IsNot <(IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>, IOrType <TypeProblem2.TypeReference, IError>)>();

            var innerBox = new Box <Tpn.TypeProblem2.Method>();

            Tpn.TypeProblem2.Method?myInner = null;

            var linesBox = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            IOrType <IKey, IError>?realizedInputKey  = null;
            IOrType <IKey, IError>?realizedOutputKey = null;

            IOrType <IResolve <IBox <IFrontendCodeElement> >, IError>[]? nextElements = null;

            var(outer, realizeContext, _) = context.TypeProblem.CreateMethod(
                scope,
                x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                x => {
                var(inner, realizedInput, realizedOutput) = context.TypeProblem.CreateMethod(
                    x,
                    y => parameterDefinition.Run(y, context.CreateChildContext(this)).SetUpSideNode,
                    y => output.Run(y, context.CreateChildContext(this)).SetUpSideNode,
                    parameterName,
                    new WeakMethodDefinitionConverter(
                        linesBox));
                myInner = inner;
                innerBox.Fill(inner);
                nextElements = elements.Select(z => z.TransformInner(w => w.Run(inner, context.CreateChildContext(this)).Resolve)).ToArray();

                realizedInputKey  = realizedInput.TransformInner(y => y.Key());
                realizedOutputKey = realizedOutput.TransformInner(y => y.Key());

                var outputTypeRef = context.TypeProblem.CreateTypeReference(scope, new GenericNameKey(new NameKey("method"), new[] {
                    realizedInputKey,
                    realizedOutputKey,
                }), new WeakTypeReferenceConverter());

                return(OrType.Make <TypeProblem2.TypeReference, IError>(outputTypeRef));
            },
                contextName,
                new WeakImplementationDefinitionConverter(
                    new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >(Array.Empty <IOrType <IBox <IFrontendCodeElement>, IError> >()),
                    innerBox));

            if (realizedInputKey == null)
            {
                throw new NullReferenceException(nameof(realizedInputKey));
            }
            if (realizedOutputKey == null)
            {
                throw new NullReferenceException(nameof(realizedOutputKey));
            }
            if (nextElements == null)
            {
                throw new NullReferenceException(nameof(nextElements));
            }
            if (myInner == null)
            {
                throw new NullReferenceException(nameof(myInner));
            }

            var innerValue = context.TypeProblem.CreateValue(outer,
                                                             new GenericNameKey(new NameKey("method"), new[] {
                realizedInputKey,
                realizedOutputKey,
            }));

            innerValue.AssignTo(outer.Returns());


            var value = context.TypeProblem.CreateValue(runtimeScope, new GenericNameKey(new NameKey("method"), new[] {
                realizeContext.TransformInner(x => x.Key()),
                OrType.Make <IKey, IError>(new GenericNameKey(new NameKey("method"), new[] {
                    realizedInputKey,
                    realizedOutputKey,
                })),
            }));

            return(new SetUpResult <IBox <WeakImplementationDefinition>, Tpn.IValue>(new ImplementationDefinitionResolveReferance(
                                                                                         outer, myInner, nextElements, linesBox), OrType.Make <Tpn.IValue, IError>(value)));
        }
コード例 #9
0
ファイル: GenericMethod.cs プロジェクト: Prototypist1/Tac
        public ISetUpResult <IBox <WeakGenericMethodDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            scope = scope.EnterInitizaionScopeIfNessisary();
            if (!(scope is Tpn.IScope runtimeScope))
            {
                throw new NotImplementedException("this should be an IError");
            }

            var box = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            var(method, realizedInput, realizedOutput) = context.TypeProblem.CreateGenericMethod(
                scope,
                x => parameterDefinition.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                x => output.Run(x, context.CreateChildContext(this)).SetUpSideNode,
                parameterName,
                new WeakMethodDefinitionConverter(box),
                genericParameters.Select(x => new Tpn.TypeAndConverter(x, new WeakTypeDefinitionConverter())).ToArray());

            var nextElements = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            // I think for the type I return a method type
            // they already have generic parameters

            // the question is how does look up work?
            // we aren't looking up something with a fix number of generic parameters...
            // I can't throw a bunch of stuff in the primitive scope
            // it's not just about how many parameters they have but also how those parameters turn into output
            // so we have to end up with a factory behind a cache

            // there is also a problem with how you name our type parameters
            // generic-method [T] [T,T] is the same as generic-method [T1] [T1,T1]
            // stituations like: generic-method [T1] [T1,generic-method [T] [T1,T]] make this makes this more complex
            // type combining is common is tac
            // generic types can do it type [T1] X {T1 t} and type [T] X{T t} are the same
            // types can do it too type X {int a} and type Y {int a}
            // for types, they just end up being assignable to each other
            // I don't think generic types really work... in the example above those would both be registered under NameKey("X") and the second one you try to add would throw

            // if I can count on them to combine later maybe I should just make the type here
            // there will still be look up tho, members


            // {8E138F8D-53AA-4D6A-B337-64CAFED23391}
            //var value = context.TypeProblem.CreateValue(method, new DoubleGenericNameKey(
            //    new NameKey("method"),
            //    genericParameters,
            //    new IOrType<IKey, IError>[] {
            //        realizedInput.TransformInner(x=>x.Key()),
            //        realizedOutput.TransformInner(x=>x.Key()),
            //    })); ;


            //// {C28BDF52-A848-4D0A-824A-7F2943BCFE53}
            //var inputMember = context.TypeProblem.GetInput(value);
            //context.TypeProblem.IsAssignedTo(inputMember, method.Input.GetOrThrow()/*lazy GetOrThrow*/);

            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);

            //var dict =context.TypeProblem.HasGenerics(value, genericParameters);
            //foreach (var key in genericParameters)
            //{
            //    context.TypeProblem.AssertIs(dict[key], method.Generics[key]/*lazy GetOrThrow*/);
            //}


            //var returnsMember = context.TypeProblem.GetReturns(value);
            //context.TypeProblem.IsAssignedTo(method.Returns.GetOrThrow()/*lazy GetOrThrow*/, returnsMember);

            return(new SetUpResult <IBox <WeakGenericMethodDefinition>, Tpn.TypeProblem2.Method>(new GenericMethodDefinitionResolveReferance(method, nextElements, box), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }