Package caltrop.interpreter.ast

Examples of caltrop.interpreter.ast.InputPattern


    ////                         private methods                   ////
    private Map _createNameToPortVarInfoMap(InputPattern[] inputPatterns) {
        Map result = new HashMap();

        for (int i = 0; i < inputPatterns.length; i++) {
            InputPattern inputPattern = inputPatterns[i];
            int repeatVal = -1; // no repeat expression.
            Expression repeatExpr = inputPattern.getRepeatExpr();
            boolean isList = ((repeatExpr == null) ? false : true);

            if (isList) {
                repeatVal = _context.intValue(_eval.evaluate(repeatExpr));

                if (repeatVal < 0) {
                    throw new InterpreterException("Repeat expressions "
                            + "must evaluate to nonnegative values.");
                }
            }

            String[] variables = inputPattern.getVariables();

            for (int j = 0; j < variables.length; j++) {
                String variable = variables[j];
                result.put(variable, new PortVarInfo(
                        inputPattern.getPortname(), j, variables.length,
                        isList, repeatVal));
            }
        }

        return result;
View Full Code Here


        final Environment local = actorEnv.newFrame();

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

        for (int i = 0; i < inputPatterns.length; i++) {
            final InputPattern inputPattern = inputPatterns[i];
            final String[] vars = inputPattern.getVariables();
            final Expression repExpr = inputPattern.getRepeatExpr();

            if (repExpr == null) {
                for (int j = 0; j < vars.length; j++) {
                    final InputChannel channel = ((InputPort) (inputPortMap
                            .get(inputPattern.getPortname()))).getChannel(0); // FIXME
                    local.bind(vars[j], new SingleTokenReaderThunk(channel, j));
                }
            } else {
                SimpleThunk repExprThunk = new SimpleThunk(repExpr, context,
                        local);
                local.bind(new EnvironmentKey(inputPattern.getPortname()),
                        repExprThunk);

                for (int j = 0; j < vars.length; j++) {
                    final InputChannel channel = ((InputPort) (inputPortMap
                            .get(inputPattern.getPortname()))).getChannel(0); // FIXME
                    local.bind(vars[j], new MultipleTokenReaderThunk(channel,
                            j, vars.length, repExprThunk, context));
                }
            }
        }
View Full Code Here

        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;
                }
            }
View Full Code Here

        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);
View Full Code Here

    }

    private Environment _bindInputPatternVars(InputPattern[] inputPatterns,
            Map inputData, Environment env) {
        for (int i = 0; i < inputPatterns.length; i++) {
            InputPattern inputPattern = inputPatterns[i];
            ChannelID chID = new ChannelID(inputPattern.getPortname(), 0);
            List data = (List) inputData.get(chID);
            Expression repeatExpr = inputPattern.getRepeatExpr();

            if (repeatExpr == null) {
                String[] vars = inputPattern.getVariables();

                for (int j = 0; j < vars.length; j++) {
                    String varName = vars[j];
                    env.bind(varName, data.get(j));
                }
            } else {
                String[] vars = inputPattern.getVariables();
                List[] l = new List[vars.length];

                for (int j = 0; j < l.length; j++) {
                    l[j] = new ArrayList();
                }
View Full Code Here

        if (actions.length == 1) {
            InputPattern[] inputPatterns = actions[0].getInputPatterns();

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

                List data = (List) dataSoFar.get(new ChannelID(inputPattern
                        .getPortname(), 0));

                if (data != null) {
                    numNeeded = numNeeded - data.size();
                }

                if (numNeeded > 0) {
                    inputProfile.put(new ChannelID(inputPattern.getPortname(),
                            0), Integer.valueOf(numNeeded));
                }
            }

            return inputProfile;
        }

        InputPattern[] inputPatterns = actions[0].getInputPatterns();

        if (inputPatterns.length == 0) {
            // if the first action has no input patterns,
            // then the "intersection" will be empty.
            return inputProfile;
        }

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

            for (int j = 1; j < actions.length; j++) {
                InputPattern ip = getInputPattern(inputPattern.getPortname(),
                        actions[j]);

                if (ip == null) {
                    numNeeded = 0;
                    break;
View Full Code Here

    private InputPattern getInputPattern(String name, Action action) {
        InputPattern[] inputPatterns = action.getInputPatterns();

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

            if (inputPattern.getPortname().equals(name)) {
                return inputPattern;
            }
        }

        return null;
View Full Code Here

        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);

                if (data != null) {
View Full Code Here

            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();
                ChannelID chID = new ChannelID(name, 0);

                if (inputProfile.containsKey(chID)) {
                    if (!encountered) {
                        encountered = true;
View Full Code Here

    private boolean isFirable(Action action, Map dataSoFar) {
        InputPattern[] inputPatterns = action.getInputPatterns();

        for (int i = 0; i < inputPatterns.length; i++) {
            InputPattern inputPattern = inputPatterns[i];
            int numNeeded = numTokensNeeded(inputPattern);
            List data = (List) dataSoFar.get(new ChannelID(inputPattern
                    .getPortname(), 0));
            int numHave = (data == null) ? 0 : data.size();

            if (numNeeded > numHave) {
                return false;
View Full Code Here

TOP

Related Classes of caltrop.interpreter.ast.InputPattern

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.