Package caltrop.interpreter.ast

Examples of caltrop.interpreter.ast.Action


            throw new InterpreterException(
                    "DataflowActorInterpreter: Must call actionSetup() "
                            + "before calling actionEvaluatePrecondition().");
        }

        final Action action = envAction;
        final InputPattern[] inputPatterns = action.getInputPatterns();

        for (int i = 0; i < inputPatterns.length; i++) {
            final InputPattern inputPattern = inputPatterns[i];

            // FIXME: handle multiports
            final InputChannel channel = ((InputPort) (inputPortMap
                    .get(inputPattern.getPortname()))).getChannel(0);

            if (inputPattern.getRepeatExpr() == null) {
                if (!channel.hasAvailable(inputPattern.getVariables().length)) {
                    // System.out.println("Not enough inputs:" + inputPattern.getVariables().length);
                    return false;
                }
            } else {
                int repeatVal = context.intValue(env.get(new EnvironmentKey(
                        inputPattern.getPortname())));

                if (!channel.hasAvailable(inputPattern.getVariables().length
                        * repeatVal)) {
                    // System.out.println("Not enough repeated inputs:" + inputPattern.getVariables().length * repeatVal);
                    return false;
                }
            }
        }

        final ExprEvaluator eval = new ExprEvaluator(context, env);
        final Expression[] guards = action.getGuards();

        for (int i = 0; i < guards.length; i++) {
            final Object g = eval.evaluate(guards[i]);

            if (!context.booleanValue(g)) {
View Full Code Here


        // First evaluate the action-level thunks, so that their value
        // will not be affected by subsequent assignments to action
        // or actor variables.
        env.freezeLocal();

        final Action action = envAction;
        final StmtEvaluator eval = new StmtEvaluator(context, env);
        final Statement[] body = action.getBody();

        for (int i = 0; i < body.length; i++) {
            eval.evaluate(body[i]);
        }
    }
View Full Code Here

            throw new InterpreterException(
                    "DataflowActorInterpreter: Must call actionSetup() "
                            + "before calling actionComputeOutputs().");
        }

        final Action action = envAction;
        final ExprEvaluator eval = new ExprEvaluator(context, env);
        final OutputExpression[] outputExpressions = action
                .getOutputExpressions();

        for (int i = 0; i < outputExpressions.length; i++) {
            final OutputExpression outputExpression = outputExpressions[i];
            final Expression[] expressions = outputExpression.getExpressions();
View Full Code Here

            throw new InterpreterException(
                    "DataflowActorInterpreter: Must call actionSetup() "
                            + "before calling actionEvaluatePrecondition().");
        }

        final Action action = envAction;

        final ExprEvaluator eval = new ExprEvaluator(context, env);
        final Expression[] guards = action.getGuards();

        for (int i = 0; i < guards.length; i++) {
            final Object g = eval.evaluate(guards[i]);

            if (!context.booleanValue(g)) {
View Full Code Here

        // First evaluate the action-level thunks, so that their value
        // will not be affected by subsequent assignments to action
        // or actor variables.
        env.freezeLocal();

        final Action action = envAction;

        final InputPattern[] inputPatterns = action.getInputPatterns();

        for (int i = 0; i < inputPatterns.length; i++) {
            final InputPattern inputPattern = inputPatterns[i];

            // FIXME: handle multiports
            final InputChannel channel = ((InputPort) (inputPortMap
                    .get(inputPattern.getPortname()))).getChannel(0);

            if (inputPattern.getRepeatExpr() == null) {
                if (!channel.hasAvailable(inputPattern.getVariables().length)) {
                    throw new InterpreterException("Not enough inputs:"
                            + inputPattern.getVariables().length);
                }
            } else {
                int repeatVal = context.intValue(env.get(new EnvironmentKey(
                        inputPattern.getPortname())));

                if (!channel.hasAvailable(inputPattern.getVariables().length
                        * repeatVal)) {
                    throw new InterpreterException(
                            "Not enough repeated inputs:"
                                    + (inputPattern.getVariables().length * repeatVal));
                }
            }
        }

        final StmtEvaluator eval = new StmtEvaluator(context, env);
        final Statement[] body = action.getBody();

        for (int i = 0; i < body.length; i++) {
            eval.evaluate(body[i]);
        }
    }
View Full Code Here

    // the data we've read so far. if any of the guards evaluates to false, eliminate that action from the set.
    private Action[] filterActions(Action[] actions, Map dataSoFar) {
        List result = new LinkedList();

        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];
            Expression[] guardExprs = action.getGuards();
            boolean guardVal = true;

            if (guardExprs.length > 0) {
                InputPattern[] inputPatterns = action.getInputPatterns();
                Environment env = new DataMapEnvironment(inputPatterns,
                        dataSoFar, _env, _context);
                ExprEvaluator eval = new ExprEvaluator(_context, env);

                for (int j = 0; j < guardExprs.length; j++) {
View Full Code Here

    private Map computeRemainingTokens(Action[] actions, Map dataSoFar) {
        Map profile = new HashMap();

        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];

            for (int j = 0; j < action.getInputPatterns().length; j++) {
                InputPattern inputPattern = action.getInputPatterns()[j];
                ChannelID chID = new ChannelID(inputPattern.getPortname(), 0);
                int numNeeded = numTokensNeeded(inputPattern);
                int numHave = 0;
                List data = (List) dataSoFar.get(chID);
View Full Code Here

    }

    // for the last "burst" of reads, we can only read at most one token from each channel.
    private boolean isRemainingProfileValid(Map inputProfile, Action[] actions) {
        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];
            InputPattern[] inputPatterns = action.getInputPatterns();
            boolean encountered = false;

            for (int j = 0; j < inputPatterns.length; j++) {
                InputPattern inputPattern = inputPatterns[j];
                String name = inputPattern.getPortname();
View Full Code Here

        return false;
    }

    private void fireMatchingAction(Action[] actions, Map dataSoFar) {
        Action action = selectAction(actions, dataSoFar);
        fireAction(action, dataSoFar);
    }
View Full Code Here

        tokenWriter.put(outputData);
    }

    private Action selectAction(Action[] actions, Map dataSoFar) {
        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];

            if (isFirable(action, dataSoFar)) {
                return action;
            }
        }
View Full Code Here

TOP

Related Classes of caltrop.interpreter.ast.Action

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.