コード例 #1
0
 public ISetUpResult <IBox <WeakRealizeMethodOperation>, Tpn.IValue> Run(Tpn.IStaticScope scope, ISetUpContext context)
 {
     throw new NotImplementedException();
     //return new SetUpResult<IBox<WeakRealizeMethodOperation>, Tpn.IValue>(
     //    new RealizeMethodOperationResolveReferance(),
     //    getReturnedValue(scope, context, nextLeft));
 }
コード例 #2
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}");
                }
            }
コード例 #3
0
        private static Tpn.TypeProblem2.Member GetMember(Tpn.IStaticScope scope, ISetUpContext context, Tpn.IHavePossibleMembers possibleScope, NameKey nameKey)
        {
            // TODO
            // there needs to be a case about being directly in a type

            // this handles this case
            // type example{
            // x;
            // type inner { x;} y;
            //}
            // and this case
            // 1 =: x;
            // object {x =: x; 2 =: y;}
            // in object the LHS x is resolves up
            // the RHS x resolves to create a new member
            if ((context.EnclosingSetUp is WeakAssignOperationPopulateScope &&
                 context.Parent.Is(out var parent) &&
                 (parent is ObjectDefinitionPopulateScope)) || context.EnclosingSetUp is TypeDefinitionPopulateScope)
            {
                if (!(scope is Tpn.IHavePublicMembers havePublicMember))
                {
                    // this should only be used in object and type definitions
                    throw new NotImplementedException("this should be an ierror");
                }

                return(context.TypeProblem.CreatePublicMember(scope, havePublicMember, nameKey));;
            }
コード例 #4
0
ファイル: BlockDefinition.cs プロジェクト: Prototypist1/Tac
        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)));
        }
コード例 #5
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)));
        }
コード例 #6
0
ファイル: RootScope.cs プロジェクト: Prototypist1/Tac
        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)));
        }
コード例 #7
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)));
        }
コード例 #8
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));
        }
コード例 #9
0
 public static Tpn.IStaticScope EnterInitizaionScopeIfNessisary(this Tpn.IStaticScope staticScope)
 {
     // this is for this:
     // y := 5
     // object { x := y + 1 }
     // x is on the obect
     // but the RHS is run in the initization scope
     // y := 5
     // object { z := x := y + 1 }
     // operations exculding := push us in to the InitizationScope
     if (staticScope is Tpn.TypeProblem2.Object objectScope)
     {
         return(objectScope.InitizationScope);
     }
     return(staticScope);
 }
コード例 #10
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))));
                }
コード例 #11
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)));
        }
コード例 #12
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)));
        }
コード例 #13
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)));
        }
コード例 #14
0
        public ISetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            // this is a bit werid
            // it creates member possibly on parent for code like
            // type {x;y;}
            // or
            // object {1 =: x; 2 =: y;}
            // the second is really bad tho, if you had:
            // 1 =: x;
            // object {1 =: x; 2 =: y;}
            // the possible member for x in the object would not result in a real member

            // {48146F3A-6D75-4F24-B857-BED24CE846EA}
            // here is a painful situaltion
            // 1 =: x;
            // object {x =: x; 2 =: y;}
            // in object the LHS x is resolves up
            // the RHS x resolves to create a new member

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

            var nameKey = new NameKey(memberName);
            var member  = GetMember(scope, context, possibleScope, nameKey);

            return(new SetUpResult <IBox <WeakMemberReference>, Tpn.TypeProblem2.Member>(new MemberResolveReferance(nameKey), OrType.Make <Tpn.TypeProblem2.Member, IError>(member)));
        }
コード例 #15
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)));
        }
コード例 #16
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)));
        }
コード例 #17
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)));
        }
コード例 #18
0
        private OrType <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> > ConvertType(
            Tpn.TypeProblem2.Builder problem,
            Tpn.IStaticScope scope,
            IOrType <IVerifiableType, IError> typeOrError)
        {
            return(typeOrError.SwitchReturns(type =>
            {
                if (type is NumberType numberType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("number"));
                }
                else if (type is EmptyType emptyType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("empty"));
                }
                else if (type is BooleanType booleanTyp)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("bool"));
                }
                else if (type is BlockType blockType)
                {
                    throw new Exception("can't be asked");
                }
                else if (type is StringType stringType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("string"));
                }
                else if (type is AnyType anyType)
                {
                    throw new Exception("can't be asked");
                }

                if (type is InterfaceType interfaceType)
                {
                    if (!typeCache.TryGetValue(type, out var res))
                    {
                        return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(OrType.Make <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError>(res !));
                    }

                    // we don't know the type key...
                    var tpnType = problem.CreateTypeExternalType(scope, new WeakTypeDefinitionConverter(), interfaceType);
                    typeCache[type] = tpnType;
                    var orType = OrType.Make <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError>(tpnType);
                    foreach (var memberPair in interfaceType.Members)
                    {
                        var innerType = ConvertType(problem, tpnType, OrType.Make <IVerifiableType, IError>(memberPair.Type));
                        innerType.Switch(x =>
                        {
                            problem.CreatePublicMember(tpnType, tpnType, memberPair.Key, OrType.Make <IKey, IError>(x));
                        }, y =>
                        {
                            problem.CreatePublicMember(tpnType, memberPair.Key, y);
                        });
                    }
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(orType);
                }
                else if (type is TypeOr typeOr)
                {
                    throw new Exception("i don't want to think about it");
                }
                else if (type is TypeAnd typeAnd)
                {
                    throw new Exception("i don't want to think about it");
                }
                else if (type is MethodType methodType)
                {
                    var input = ConvertType(problem, scope, OrType.Make <IVerifiableType, IError>(methodType.InputType));
                    var output = ConvertType(problem, scope, OrType.Make <IVerifiableType, IError>(methodType.OutputType));
                    if (input.Is2(out var i2) && output.Is2(out var o2))
                    {
                        problem.GetMethod(i2, o2);
                    }
                    else if (input.Is1(out var i1) && output.Is1(out var o1))
                    {
                        return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new GenericNameKey(new NameKey("method"), new IOrType <IKey, IError>[] {
                            OrType.Make <IKey, IError>(i1), OrType.Make <IKey, IError>(o1)
                        }));
                    }
コード例 #19
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)));
        }
コード例 #20
0
        public ISetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference> Run(Tpn.IStaticScope scope, ISetUpContext context)
        {
            var type = context.TypeProblem.CreateTypeReference(scope, key, new WeakTypeReferenceConverter());

            return(new SetUpResult <IBox <IFrontendType <IVerifiableType> >, Tpn.TypeProblem2.TypeReference>(new TypeReferanceResolveReference(
                                                                                                                 type), OrType.Make <Tpn.TypeProblem2.TypeReference, IError>(type)));
        }
コード例 #21
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)));
        }