Пример #1
0
        // do these really need to be IBox? they seeme to generally be filled...
        // mayble IPossibly...
        public IBox <WeakObjectDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack)
        {
            var finalElements = nextElements.Select(x => x.SwitchReturns <IOrType <IBox <WeakAssignOperation>, IError> >(
                                                        y => {
                var res = y.Run(context, stack.Add(myScope)).GetValue();
                if (res is WeakAssignOperation weakAssign)
                {
                    return(OrType.Make <IBox <WeakAssignOperation>, IError>(new Box <WeakAssignOperation>(weakAssign)));
                }
                else
                {
                    return(OrType.Make <IBox <WeakAssignOperation>, IError>(Error.Other("lines in an object must me assignments")));
                }
            },
                                                        y => OrType.Make <IBox <WeakAssignOperation>, IError>(y))).ToArray();

            box.Fill(finalElements);

            var objectOr = myScope.Converter.Convert(context, myScope, stack);//;  context.GetObject(myScope);

            if (objectOr.Is1(out var v1))
            {
                return(new Box <WeakObjectDefinition>(v1));
            }
            throw new Exception("wrong or");
        }
Пример #2
0
        public IBox <WeakImplementationDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack)
        {
            linesBox.Fill(nextElements.Select(x => x.TransformInner(y => y.Run(context, stack.Add(outer).Add(inner)))).ToArray());
            var res = outer.Converter.Convert(context, outer, stack);

            if (res.Is2(out var v2))
            {
                return(new Box <WeakImplementationDefinition>(v2));
            }
            throw new Exception("wrong!");
        }
Пример #3
0
        public IBox <WeakMethodDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack)
        {
            box.Fill(nextElements.Select(x => x.TransformInner(y => y.Run(context, stack.Add(method)))).ToArray());
            var res = method.Converter.Convert(context, method, stack);

            if (res.Is1(out var v1))
            {
                return(new Box <WeakMethodDefinition>(v1));
            }
            throw new Exception("wrong!");
        }
Пример #4
0
        public IBox <WeakEntryPointDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack)
        {
            var finalForm = converted.Select(x => x.TransformInner(y => y.Run(context, stack.Add(scope)))).ToArray();

            box.Fill(finalForm);
            var res = scope.Converter.Convert(context, scope, stack);

            if (res.Is3(out var v3))
            {
                return(new Box <WeakEntryPointDefinition>(v3));
            }
            throw new Exception("wrong!");
        }
Пример #5
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)));
        }
Пример #6
0
        public IBox <WeakBlockDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack)
        {
            box.Fill(nextElements.Select(x => x.TransformInner(y => y.Run(context, stack.Add(myScope)))).ToArray());

            return(new Box <WeakBlockDefinition>(myScope.Converter.Convert(context, myScope, stack).Is1OrThrow()));
        }