Exemplo n.º 1
0
        public override VisitorEnterResult Visit(EquationSyntaxNode node)
        {
            var type = _solving.GetVariableType(node.Id);

            node.OutputType = _tiToLangTypeConverter.Convert(type);
            return(VisitorEnterResult.Continue);
        }
Exemplo n.º 2
0
        public static GenericUserFunction Create(
            TypeInferenceResults typeInferenceResults,
            UserFunctionDefinitionSyntaxNode syntaxNode,
            IFunctionDictionary dictionary)
        {
            var ticGenerics    = typeInferenceResults.Generics;
            var langConstrains = new GenericConstrains[ticGenerics.Length];

            for (int i = 0; i < ticGenerics.Length; i++)
            {
                var ticConstrains = ticGenerics[i];
                langConstrains[i] = GenericConstrains.FromTicConstrains(ticConstrains);
            }
            var ticFunName         = syntaxNode.Id + "'" + syntaxNode.Args.Count;
            var ticSignature       = (StateFun)typeInferenceResults.GetVariableType(ticFunName);
            var signatureConverter = TicTypesConverter.GenericSignatureConverter(ticGenerics);

            var argTypes = new FunnyType[ticSignature.ArgNodes.Length];

            for (var i = 0; i < ticSignature.ArgNodes.Length; i++)
            {
                argTypes[i] = signatureConverter.Convert(ticSignature.ArgNodes[i].State);
            }
            var retType = signatureConverter.Convert(ticSignature.ReturnType);

#if DEBUG
            TraceLog.WriteLine($"CREATE GENERIC FUN {syntaxNode.Id}({string.Join(",",argTypes)}):{retType}");
            TraceLog.WriteLine($"    ...where {string.Join(", ", langConstrains)}");
#endif
            var function = new GenericUserFunction(typeInferenceResults, syntaxNode, dictionary, langConstrains, retType, argTypes);
            return(function);
        }
Exemplo n.º 3
0
        public override IConcreteFunction CreateConcrete(FunnyType[] concreteTypes)
        {
            BuiltCount++;

            var id = string.Join(",", concreteTypes);

            if (_concreteFunctionsCache.TryGetValue(id, out var alreadyExists))
            {
                return(alreadyExists);
            }
            //set types to nodes
            var converter    = TicTypesConverter.ReplaceGenericTypesConverter(_constrainsMap, concreteTypes);
            var ticSignature = _typeInferenceResults.GetVariableType(_syntaxNode.Id + "'" + _syntaxNode.Args.Count);
            var funType      = converter.Convert(ticSignature);

            var returnType = funType.FunTypeSpecification.Output;
            var argTypes   = funType.FunTypeSpecification.Inputs;

            // Create a function prototype and put it to cache for recursive cases
            // If the function is recursive - function will take recursive prototype from cache
            var concretePrototype = new ConcreteUserFunctionPrototype(Name, returnType, argTypes);

            _concreteFunctionsCache.Add(id, concretePrototype);

            _syntaxNode.ComeOver(
                enterVisitor: new ApplyTiResultEnterVisitor(
                    solving: _typeInferenceResults,
                    tiToLangTypeConverter: converter),
                exitVisitor: new ApplyTiResultsExitVisitor());

            var function = _syntaxNode.BuildConcrete(
                argTypes:   argTypes,
                returnType: returnType,
                functionsDictionary: _dictionary,
                results:    _typeInferenceResults,
                converter:  converter);

            concretePrototype.SetActual(function, _syntaxNode.Interval);
            return(function);
        }