Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 3
0
        public static ImmutableNodeReferer translateRecursiveInternal(Functional.ParseTreeElement entry, ImmutableNodeReferer parent)
        {
            if (entry.type == Functional.ParseTreeElement.EnumType.SCOPE)
            {
                ImmutableNodeReferer resultNode = ImmutableNodeReferer.makeBranch();

                Functional.ScopeParseTreeElement castedEntry = (Functional.ScopeParseTreeElement)entry;
                foreach (Functional.ParseTreeElement iterationChildren in castedEntry.children)
                {
                    ImmutableNodeReferer translatedNode = translateRecursiveInternal(iterationChildren, resultNode);
                    resultNode.children = resultNode.children.Add(translatedNode);
                }

                return(resultNode);
            }
            else if (entry.type == Functional.ParseTreeElement.EnumType.IDENTIFIER)
            {
                Functional.IdentifierParseTreeElement castedEntry = (Functional.IdentifierParseTreeElement)entry;
                return(ImmutableNodeRefererManipulatorHelper.makeString(castedEntry.identifier));
            }
            else if (entry.type == Functional.ParseTreeElement.EnumType.NUMBER)
            {
                Functional.NumberParseTreeElement castedEntry = (Functional.NumberParseTreeElement)entry;
                switch (castedEntry.numberType)
                {
                case Functional.NumberParseTreeElement.EnumNumberType.FLOAT:
                    return(ImmutableNodeReferer.makeNonbranch(ValueNode.makeAtomic(Variant.makeFloat(castedEntry.valueFloat))));

                case Functional.NumberParseTreeElement.EnumNumberType.INTEGER:
                    return(ImmutableNodeReferer.makeNonbranch(ValueNode.makeAtomic(Variant.makeInt(castedEntry.valueInt))));
                }
                throw new Exception("Internal error!"); // hard internal error
            }
            else if (entry.type == Functional.ParseTreeElement.EnumType.ARRAY)
            {
                // an array gets transated to an branch with array as the operation

                ImmutableNodeReferer resultNode = ImmutableNodeReferer.makeBranch();

                resultNode.children = resultNode.children.Add(ImmutableNodeRefererManipulatorHelper.makeString("array")); // pseudo operation "array" which indicates an array


                Functional.ArrayParseTreeElement castedEntry = (Functional.ArrayParseTreeElement)entry;
                foreach (Functional.ParseTreeElement iterationChildren in castedEntry.children)
                {
                    ImmutableNodeReferer translatedNode = translateRecursiveInternal(iterationChildren, resultNode);
                    resultNode.children = resultNode.children.Add(translatedNode);
                }

                return(resultNode);
            }
            else
            {
                throw new Exception("Not supported parse node!");
            }
        }
Esempio n. 4
0
 public static NodeRefererEntry translateRecursive(Functional.ParseTreeElement entry)
 {
     return(new NodeRefererEntry(translateRecursiveInternal(entry, null)));
 }