Esempio n. 1
0
        public ISetUpResult <IBox <WeakTryAssignOperation>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var box = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();

            // we create a new scope because the member we are assigning in to only exists in that scope
            // 5 is Cat c { ... }
            // is really
            // { 5 is Cat c { ... }}

            var myScope = context.TypeProblem.CreateScope(scope, new WeakBlockDefinitionConverter(box));

            var nextLeft  = left.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));
            var nextRight = right.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));
            var nextblock = block.TransformInner(x => x.Run(myScope, context.CreateChildContext(this)));

            if (nextLeft.Is1(out var nextLeft1) && nextLeft1.SetUpSideNode.Is1(out var node1) && nextRight.Is1(out var nextRight1) && nextRight1.SetUpSideNode.Is1(out var node2))
            {
                if (node1 is not Tpn.ICanAssignFromMe canAssignFromMe)
                {
                    // todo I need real error handling
                    // probably I need somewhere to stuff additional errors
                    throw new NotImplementedException($"can not assign from {nextLeft1.SetUpSideNode}");
                }

                if (node2 is not Tpn.ICanBeAssignedTo canBeAssignedTo)
                {
                    // todo I need real error handling
                    throw new NotImplementedException($"can not assign to {nextRight1.SetUpSideNode}");
                }
            }
Esempio n. 2
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)));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public ISetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type = this.type.Run(scope, context.CreateChildContext(this));


            var member = context.TypeProblem.CreateMember(scope, memberName, type.SetUpSideNode.TransformInner(x => x.Key()));


            return(new SetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member>(new MemberDefinitionResolveReferance(access, memberName), OrType.Make <Tpn.TypeProblem2.Member, IError>(member)));
        }
Esempio n. 5
0
        public ISetUpResult <IBox <WeakGenericTypeDefinition>, Tpn.IExplicitType> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // oh geez here is a mountain.
            // I generic types are erased
            // what on earth does this return?
            var myScope = context.TypeProblem.CreateGenericType(
                scope,
                OrType.Make <NameKey, ImplicitKey>(nameKey),
                genericParameters.Select(x => new Tpn.TypeAndConverter(x, new WeakTypeDefinitionConverter())).ToArray(),
                new WeakTypeDefinitionConverter());
            var nextLines = lines.Select(x => x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakGenericTypeDefinition>, Tpn.IExplicitType>(new GenericTypeDefinitionResolveReferance(myScope, nextLines), OrType.Make <Tpn.IExplicitType, IError>(myScope)));
        }
Esempio n. 6
0
        public ISetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type          = context.TypeProblem.CreateType(scope, key, new WeakTypeDefinitionConverter());
            var typeReference = context.TypeProblem.CreateTypeReference(scope, key.SwitchReturns <IKey>(x => x, x => x), new WeakTypeReferenceConverter());

            foreach (var element in elements)
            {
                if (element.Is1(out var setUp))
                {
                    setUp.Run(type, context.CreateChildContext(this));
                }
            }
            return(new SetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference>(new TypeReferanceResolveReference(typeReference), OrType.Make <Tpn.TypeProblem2.TypeReference, IError>(typeReference)));
        }
Esempio n. 7
0
        public ISetUpResult <IBox <WeakRootScope>, Tpn.TypeProblem2.Object> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            //scope = scope.EnterInitizaionScopeIfNessisary();

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


            //var assignmentsBox = new Box<IReadOnlyList<IOrType<IResolve<IBox<WeakAssignOperation>>, IError>>>();
            //var entryBox = new Box<IOrType<IResolve<IBox<WeakEntryPointDefinition>>, IError>>();
            //var myScope = context.TypeProblem.CreateObjectOrModule(context.TypeProblem.ModuleRoot, key, new WeakRootConverter(assignmentsBox, entryBox), 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 nextEntry    = entry.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve);


            var ranTypes        = types.Select(x => x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();
            var ranGenericTypes = genericTypes.Select(x => x.TransformInner(y => y.Run(myScope, context.CreateChildContext(this)).Resolve)).ToArray();

            //var value = context.TypeProblem.CreateValue(runtimeScope, key, new PlaceholderValueConverter());
            // ugh! an object is a type
            //

            return(new SetUpResult <IBox <WeakRootScope>, Tpn.TypeProblem2.Object>(new ResolveReferanceRootScope(myScope, ranTypes, ranGenericTypes, nextElements, nextEntry, assignmentsBox, entryBox), OrType.Make <Tpn.TypeProblem2.Object, IError>(myScope)));
        }
Esempio n. 8
0
        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)));
        }
Esempio n. 9
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))));
                }
Esempio n. 10
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)));
        }
Esempio n. 11
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)));
        }
Esempio n. 12
0
        public ISetUpResult <IBox <WeakBlockDefinition>, Tpn.IScope> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var box          = new Box <IReadOnlyList <IOrType <IBox <IFrontendCodeElement>, IError> > >();
            var myScope      = context.TypeProblem.CreateScope(scope, new WeakBlockDefinitionConverter(box));
            var nextElements = Elements.Select(or => or.TransformInner(y => y.Run(scope, context.CreateChildContext(this)).Resolve)).ToArray();

            return(new SetUpResult <IBox <WeakBlockDefinition>, Tpn.IScope>(new ResolveReferanceBlockDefinition(myScope, nextElements, box), OrType.Make <Tpn.IScope, IError>(myScope)));
        }
Esempio n. 13
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)));
        }