示例#1
0
        public ISetUpResult <IBox <WeakEntryPointDefinition>, Tpn.TypeProblem2.Method> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            //var box = new Box<IOrType<IResolve<IBox<IFrontendCodeElement>>, IError>[]>();

            //var inputBox = new Box<IResolve<IBox<WeakMemberReference>>>();
            //var outputBox = new Box<IResolve<IBox<IFrontendType<IVerifiableType>>>>();

            //var innerScope = context.TypeProblem.CreateScope(scope, new WeakEntryPointConverter(box, inputBox, outputBox));
            //context.TypeProblem.HasEntryPoint(scope, innerScope);

            //inputBox.Fill(parameterDefinition.Run(innerScope, context.CreateChildContext(this)).Resolve);
            //outputBox.Fill(output.Run(innerScope, context.CreateChildContext(this)).Resolve);

            //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 WeakEntryPointConverter(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 converted = elements.Select(x => x.TransformInner(y => y.Run(method, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakEntryPointDefinition>, Tpn.TypeProblem2.Method> (new EntryPointDefinitionResolveReferance(method, box, converted), OrType.Make <Tpn.TypeProblem2.Method, IError>(method)));
        }
示例#2
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)));
        }
示例#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 <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)));
        }