Package caltrop.interpreter

Examples of caltrop.interpreter.ExprEvaluator


    // initial values.
    private void _initializeStateVariables(Environment env) {
        Decl[] decls = _actor.getStateVars();

        if (decls != null) {
            ExprEvaluator eval = new ExprEvaluator(_theContext, env);

            for (int i = 0; i < decls.length; i++) {
                String var = decls[i].getName();
                Expression valExpr = decls[i].getInitialValue();

                // Note: this assumes that declarations are
                // ordered by eager dependency
                Object value = (valExpr == null) ? _theContext.createNull()
                        : eval.evaluate(valExpr);
                env.bind(var, value);
            }
        }
    }
View Full Code Here


            Map dataFromInputPorts, Environment parentEnv, Context context) {
        _inputPatterns = inputPatterns;
        _dataFromInputPorts = dataFromInputPorts;
        _parentEnv = parentEnv;
        _context = context;
        _eval = new ExprEvaluator(_context, _parentEnv);
        _varNameToVarInfo = _createNameToPortVarInfoMap(_inputPatterns);
    }
View Full Code Here

                    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)) {
                // System.out.println("guard not satisfied:" + guards[i]);
                return false;
            }
View Full Code Here

                    "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();
            final Expression repeatExpr = outputExpression.getRepeatExpr();

            final OutputChannel channel = ((OutputPort) (outputPortMap
                    .get(outputExpression.getPortname()))).getChannel(0);

            // FIXME: handle multiports
            if (repeatExpr != null) {
                int repeatValue = context.intValue(eval.evaluate(repeatExpr));
                List[] lists = new List[expressions.length];

                for (int j = 0; j < lists.length; j++) {
                    lists[j] = context.getList(eval.evaluate(expressions[j]));
                }

                for (int j = 0; j < repeatValue; j++) {
                    for (int k = 0; k < expressions.length; k++) {
                        channel.put(lists[k].get(j));
                    }
                }
            } else {
                for (int j = 0; j < expressions.length; j++) {
                    channel.put(eval.evaluate(expressions[j]));
                }
            }
        }
    }
View Full Code Here

                            + "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)) {
                // System.out.println("guard not satisfied:" + guards[i]);
                return false;
            }
View Full Code Here

        _ptActor = ptActor;
        _actor = actor;
        _actions = PriorityUtil.prioritySortActions(_actor);
        _context = context;
        _env = env;
        _eval = new ExprEvaluator(_context, _env);
        _ioPorts = _createIOPortMap();
        _cbc = new ConditionalBranchController(_ptActor);
    }
View Full Code Here

            eval.evaluate(body[i]);
        }
    }

    private Environment _bindActionStateVars(Decl[] decls, Environment env) {
        ExprEvaluator eval = new ExprEvaluator(_context, env);

        for (int i = 0; i < decls.length; i++) {
            Expression v = decls[i].getInitialValue();

            if (v == null) {
                env.bind(decls[i].getName(), null);
            } else {
                env.bind(decls[i].getName(), eval.evaluate(v));
            }
        }

        return env;
    }
View Full Code Here

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

                int repeatVal = _context.intValue(new ExprEvaluator(_context,
                        env).evaluate(repeatExpr));

                for (int j = 0; j < repeatVal; j++) {
                    for (int k = 0; k < vars.length; k++) {
                        l[k].add(data.get((j * vars.length) + k));
View Full Code Here

    private Map _computeOutputData(OutputExpression[] outputExprs,
            Environment env) {
        // FIXME no multi.
        Map data = new HashMap();
        ExprEvaluator eval = new ExprEvaluator(_context, env);

        for (int i = 0; i < outputExprs.length; i++) {
            OutputExpression outputExpr = outputExprs[i];
            Expression repeatExpr = outputExpr.getRepeatExpr();
            List results = new ArrayList();
            Expression[] exprs = outputExpr.getExpressions();

            if (repeatExpr == null) {
                for (int j = 0; j < exprs.length; j++) {
                    Expression expr = exprs[j];
                    results.add(eval.evaluate(expr));
                }
            } else {
                int repeatVal = _context.intValue(eval.evaluate(repeatExpr));
                List[] values = new List[exprs.length];

                for (int j = 0; j < values.length; j++) {
                    values[j] = _context.getList(eval.evaluate(exprs[j]));
                }

                for (int j = 0; j < repeatVal; j++) {
                    for (int k = 0; k < exprs.length; k++) {
                        results.add(values[k].get(j));
View Full Code Here

            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++) {
                    Expression guardExpr = guardExprs[j];

                    try {
                        if (!_context.booleanValue(eval.evaluate(guardExpr))) {
                            guardVal = false;
                            break;
                        }
                    } catch (DataMapEnvironment.UnboundPortVarException e) {
                        continue; // don't know if it's true or false yet.
View Full Code Here

TOP

Related Classes of caltrop.interpreter.ExprEvaluator

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.