Пример #1
0
 public void informCompleteFallThroughWithResult(HiddenFunctionId hiddenFunctionId, IList <ImmutableNodeReferer> arguments, ImmutableNodeReferer result)
 {
     if (hiddenFunctionId != functionId)
     {
         return;
     }
     lookup.memoize(arguments, result);
 }
Пример #2
0
        // tests if a functioncall to an defined function can be made
        //
        // creates providers and surrogates, then an callee and called function
        public void InterpreterFunctioninvocation1()
        {
            FunctionalInterpretationContext functionalContext = new FunctionalInterpretationContext();


            FunctionalInterpreter functionalInterpreter = new FunctionalInterpreter();

            functionalInterpreter.tracer = new NullFunctionalInterpreterTracer();

            FunctionalInterpreterSurrogate interpreterSurrogate = new FunctionalInterpreterSurrogate(functionalInterpreter, functionalContext);

            // dispatcher which dispatches hidden function calls to the interpreter
            SurrogateProvider surrogateProvider = new SurrogateProvider();

            // dispatcher which can shadow calls (to the surrogate provider)
            ShadowableHiddenDispatcher shadowableHiddenDispatcher = new ShadowableHiddenDispatcher(surrogateProvider);


            // dispatcher which calls another dispatcher and a number of observers,
            // which is in this case our instrumentation observer
            InstrumentationHiddenDispatcher instrHiddenDispatcher = new InstrumentationHiddenDispatcher(shadowableHiddenDispatcher);


            ArgumentBasedDispatcher publicDispatcherByArguments = new ArgumentBasedDispatcher(instrHiddenDispatcher);

            PublicCallDispatcher callDispatcher = new PublicCallDispatcher(publicDispatcherByArguments);

            // all calls the functional interpreter makes to an user defined function are dispatched with this
            functionalContext.publicFnRegistryAndDispatcher = new PublicFunctionRegistryAndDispatcher(callDispatcher);


            Functional.ParseTreeElement parseTree      = Functional.parseRecursive("3");
            NodeRefererEntry            rootnodeCalled = FunctionalToParseTreeTranslator.translateRecursive(parseTree);

            { // set descriptor to route all public function id's 0 to hidden function id 0
                ArgumentBasedDispatcher.FunctionDescriptor fnDescriptor = new ArgumentBasedDispatcher.FunctionDescriptor();
                fnDescriptor.wildcardHiddenFunctionId = HiddenFunctionId.make(0);
                publicDispatcherByArguments.setFunctionDescriptor(PublicFunctionId.make(0), fnDescriptor);
            }

            surrogateProvider.updateSurrogateByFunctionId(HiddenFunctionId.make(0), interpreterSurrogate);
            interpreterSurrogate.updateFunctionBody(HiddenFunctionId.make(0), rootnodeCalled.entry);
            interpreterSurrogate.updateParameterNames(HiddenFunctionId.make(0), new List <string>());

            callDispatcher.setFunctionId("a", PublicFunctionId.make(0));      // bind function name "a" to public function id 0
            functionalContext.publicFnRegistryAndDispatcher.addFunction("a"); // register so the dispatcher used by the interpreter knows that the function exists

            Functional.ParseTreeElement parseTree2     = Functional.parseRecursive("(a)");
            NodeRefererEntry            rootnodeCallee = FunctionalToParseTreeTranslator.translateRecursive(parseTree2);


            functionalInterpreter.interpret(functionalContext, rootnodeCallee.entry, new List <ImmutableNodeReferer>(), new List <string>());
            ImmutableNodeReferer result = rootnodeCallee.entry.interpretationResult;

            Assert.AreEqual(result.valueInt, 3);
        }
Пример #3
0
        public ImmutableNodeReferer tryDispatch(HiddenFunctionId hiddenFunctionId, IList <ImmutableNodeReferer> arguments, out bool wasShadowed)
        {
            wasShadowed = false;
            if (hiddenFunctionId != functionId)
            {
                return(null);
            }

            ImmutableNodeReferer lookupResult = lookup.tryLookup(arguments);

            if (lookupResult == null)
            {
                return(null);
            }

            wasShadowed = true;
            return(lookupResult);
        }