static void parseInterpretSurrogateTest0() { FunctionalInterpreter functionalInterpreter = new FunctionalInterpreter(); functionalInterpreter.tracer = new NullFunctionalInterpreterTracer(); FunctionalInterpretationContext functionalInterpretationContext = new FunctionalInterpretationContext(); dispatch.FunctionalInterpreterSurrogate interpreterSurrogate = new dispatch.FunctionalInterpreterSurrogate(functionalInterpreter, functionalInterpretationContext); // dispatcher which dispatches hidden function calls to the interpreter dispatch.SurrogateProvider surrogateProvider = new dispatch.SurrogateProvider(); // dispatcher which can shadow calls (to the surrogate provider) dispatch.ShadowableHiddenDispatcher shadowableHiddenDispatcher = new dispatch.ShadowableHiddenDispatcher(surrogateProvider); // dispatcher which calls another dispatcher and a number of observers, // which is in this case our instrumentation observer dispatch.InstrumentationHiddenDispatcher instrHiddenDispatcher = new dispatch.InstrumentationHiddenDispatcher(shadowableHiddenDispatcher); dispatch.TimingAndCountHiddenDispatchObserver instrObserver = new dispatch.TimingAndCountHiddenDispatchObserver(); instrObserver.resetCountersAndSetEnableTimingInstrumentation(true); instrHiddenDispatcher.dispatchObservers.Add(instrObserver); dispatch.ArgumentBasedDispatcher publicDispatcherByArguments = new dispatch.ArgumentBasedDispatcher(instrHiddenDispatcher); // dispatcher which accepts function names dispatch.PublicCallDispatcher callDispatcher = new dispatch.PublicCallDispatcher(publicDispatcherByArguments); Functional.ParseTreeElement parseTree = Functional.parseRecursive("(let [value 4 i 1 read2 (bAnd (shl value (+ i 1)) 1)] read2)"); NodeRefererEntry rootNode = FunctionalToParseTreeTranslator.translateRecursive(parseTree); { // set descriptor to route all public function id's 0 to hidden function id 0 dispatch.ArgumentBasedDispatcher.FunctionDescriptor fnDescriptor = new dispatch.ArgumentBasedDispatcher.FunctionDescriptor(); fnDescriptor.wildcardHiddenFunctionId = dispatch.HiddenFunctionId.make(0); publicDispatcherByArguments.setFunctionDescriptor(dispatch.PublicFunctionId.make(0), fnDescriptor); } surrogateProvider.updateSurrogateByFunctionId(dispatch.HiddenFunctionId.make(0), interpreterSurrogate); interpreterSurrogate.updateFunctionBody(dispatch.HiddenFunctionId.make(0), rootNode.entry); interpreterSurrogate.updateParameterNames(dispatch.HiddenFunctionId.make(0), new List <string>()); callDispatcher.setFunctionId("test", dispatch.PublicFunctionId.make(0)); for (int i = 0; i < 100; i++) { callDispatcher.dispatchCallByFunctionName("test", new List <Variant>()); } System.Console.WriteLine(instrObserver.getInstrumentation(dispatch.HiddenFunctionId.make(0)).calltimeMaxInNs); System.Console.WriteLine(instrObserver.getInstrumentation(dispatch.HiddenFunctionId.make(0)).calltimeMinInNs); System.Console.WriteLine(instrObserver.getInstrumentation(dispatch.HiddenFunctionId.make(0)).calltimeSumInNs); //Statistics statistics = new Statistics(instrObserver); //statistics.doIt(); int debugMe = 0; }
public ImmutableNodeReferer dispatchCall(string publicFunctionName, IList <ImmutableNodeReferer> parameters) { return(callDispatcher.dispatchCallByFunctionName(publicFunctionName, parameters)); }