예제 #1
0
        private static IValue ResolveCall(ICompilableFunction function, IScope callScope, TypeAnnotation returnType, CompilationContext compilationContext)
        {
            if (compilationContext.ContainsFunction(function.Definition))
            {
                return(compilationContext.LogError(11, $"Multiple references to {function} in same call stack - Recursion is disallowed"));
            }
            compilationContext.PushFunction(function.Definition);

            try
            {
                var result           = function.Compile(callScope, compilationContext);
                var resultConstraint = returnType?.ResolveConstraint(callScope, compilationContext) ?? AnyConstraint.Instance;
                return(!resultConstraint.MatchesConstraint(result, compilationContext)
                           ? compilationContext.LogError(8, $"Result '{result}' for function '{function.Definition}' does not match '{returnType}' constraint")
                           : result);
            }
            finally
            {
                compilationContext.PopFunction();
            }
        }
예제 #2
0
 public Port(string identifier, TypeAnnotation type)
 {
     _identifier = new Identifier(identifier);
     _type       = type;
 }
예제 #3
0
 public static IValue ApplyArguments(this ICompilableFunction function, IValue[] arguments, Port[] inputs, TypeAnnotation returnType, object body, IScope callScope, CompilationContext compilationContext) =>
 !(arguments.Length > 0) || arguments.ValidateArguments(inputs, callScope, compilationContext)
         ? arguments.Length > 0
               ? new AppliedFunction(arguments, function, callScope, body).ResolveNullaryFunction(compilationContext)
               : ResolveCall(function, callScope, returnType, compilationContext)
         : CompilationErr.Instance;