Beispiel #1
0
        /* uncommented because we have to overhaul this and unify it with the other functional representation
         * and it must be an unittest
         * static void interpreterTest0() {
         *  PrimitiveInstructionInterpreter interpreter = new PrimitiveInstructionInterpreter();
         *
         *  PrimitiveInterpretationContext interpreterContext = new PrimitiveInterpretationContext();
         *  interpreterContext.registers = new Register[3];
         *  interpreterContext.registers[0] = new Register();
         *  interpreterContext.registers[1] = new Register();
         *  interpreterContext.registers[2] = new Register();
         *
         *  ImmutableNodeReferer rootnode0 = ImmutableNodeReferer.makeBranch();
         *  rootnode0.children = new ImmutableNodeReferer[4];
         *
         *  rootnode0.children[0] = ImmutableNodeReferer.makeBranch();
         *  rootnode0.children[0].children = new ImmutableNodeReferer[4];
         *  rootnode0.children[0].children[0] = Node.makeInstr(Node.EnumType.INSTR_ADD_INT);
         *  rootnode0.children[0].children[1] = Node.makeAtomic(Variant.makeInt(0));
         *  rootnode0.children[0].children[2] = Node.makeAtomic(Variant.makeInt(1));
         *  rootnode0.children[0].children[3] = Node.makeAtomic(Variant.makeInt(2));
         *
         *
         *  rootnode0.children[1] = ImmutableNodeReferer.makeBranch();
         *  rootnode0.children[1].children = new ImmutableNodeReferer[2];
         *  rootnode0.children[1].children[0] = Node.makeInstr(Node.EnumType.INSTR_GOTO);
         *  rootnode0.children[1].children[1] = Node.makeAtomic(Variant.makeInt(0));
         *
         *
         *
         *
         *  interpreter.interpret(interpreterContext, rootnode0.children[0], new List<ImmutableNodeReferer>(), new List<string>());
         * }
         **/


        static void parsedTest0()
        {
            Functional.ParseTreeElement parseTree = Functional.parseRecursive("(bAnd (shl value i) 1)");
            NodeRefererEntry            node      = FunctionalToParseTreeTranslator.translateRecursive(parseTree);

            int debugHere = 1;
        }
Beispiel #2
0
        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;
        }