Package ptolemy.data

Examples of ptolemy.data.FunctionToken


        super.fire();

        // Update the function parameterPort.
        function.update();

        FunctionToken functionValue = (FunctionToken) function.getToken();
        Token[] arguments = new Token[inputPortList().size() - 1];
        int i = 0;
        Iterator ports = inputPortList().iterator();

        // Skip the function port.
        ports.next();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();
            arguments[i++] = port.get(0);
        }

        Token t = functionValue.apply(arguments);
        output.broadcast(t);
    }
View Full Code Here


        super.fire();

        // Update the function parameterPort.
        function.update();

        FunctionToken functionValue = (FunctionToken) function.getToken();
        Token[] arguments = new Token[inputPortList().size() - 1];
        int i = 0;
        Iterator ports = inputPortList().iterator();

        // Skip the function port.
        ports.next();

        while (ports.hasNext()) {
            TypedIOPort port = (TypedIOPort) ports.next();

            if (_rate[i] == -1) {
                arguments[i] = port.get(0);
            } else {
                Token[] tokens = port.get(0, _rate[i]);
                arguments[i] = new ArrayToken(port.getType(), tokens);
            }

            i++;
        }

        Token result = functionValue.apply(arguments);

        if (_outputRate == -1) {
            output.broadcast(result);
        } else {
            // FIXME: Check size.
View Full Code Here

                    throw new IllegalActionException("Wrong number of indices "
                            + "when referencing " + node.getFunctionName());
                }
            } else if (type instanceof FunctionType) {
                //FIXME :todo
                FunctionToken function = (FunctionToken) value;

                // check number of children against number of arguments of
                // function
                if (function.getNumberOfArguments() != argCount) {
                    throw new IllegalActionException("Wrong number of "
                            + "arguments when applying function "
                            + value.toString());
                }
View Full Code Here

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);

        String functionCode = new String();

        /*
 
View Full Code Here

                    // is, say, a matrix expression
                    throw new IllegalActionException("Wrong number of indices "
                            + "when referencing " + node.getFunctionName());
                }
            } else if (value instanceof FunctionToken) {
                FunctionToken function = (FunctionToken) value;

                // check number of children against number of arguments of
                // function
                if (function.getNumberOfArguments() != argCount) {
                    throw new IllegalActionException("Wrong number of "
                            + "arguments when applying function "
                            + value.toString());
                }

                result = function.apply(argValues);
            } else {
                // FIXME: It might be the a parameter is
                // shadowing a built-in function, in which
                // case, thrown an exception seems bogus.
View Full Code Here

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);
        return;
    }
View Full Code Here

                    throw new IllegalActionException("Wrong number of indices "
                            + "when referencing " + node.getFunctionName());
                }
            } else if (type instanceof FunctionType) {
                //FIXME :todo
                FunctionToken function = (FunctionToken) value;

                // check number of children against number of arguments of
                // function
                if (function.getNumberOfArguments() != argCount) {
                    throw new IllegalActionException("Wrong number of "
                            + "arguments when applying function "
                            + value.toString());
                }
View Full Code Here

        _typeInference.inferTypes(node, _scope);

        FunctionType type = (FunctionType) node.getType();
        ExpressionFunction definedFunction = new ExpressionFunction(node
                .getArgumentNameList(), node.getArgumentTypes(), cloneTree);
        FunctionToken result = new FunctionToken(definedFunction, type);
        _evaluatedChildToken = (result);

        String functionCode = new String();

        /*
 
View Full Code Here

            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    List res = new ArrayList();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();

                        Object listFragment = _theContext.applyFunction(f,
                                argument);
                        res.addAll(_theContext.getCollection(listFragment));
                    }

                    return _theContext.createList(res);
                } catch (Exception ex) {
                    throw new FunctionCallException("Failed to create list.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$createSet", _theContext.createFunction(new Function() {
            // Create a set that contains the results of applying
            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    Set res = new HashSet();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();

                        Object setFragment = _theContext.applyFunction(f,
                                argument);
                        res.addAll(_theContext.getCollection(setFragment));
                    }

                    return _theContext.createSet(res);
                } catch (Exception ex) {
                    throw new FunctionCallException("Failed to create set.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$createMap", _theContext.createFunction(new Function() {
            // Create a map that contains the results of applying
            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    Map res = new HashMap();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();
View Full Code Here

                Function function = new LoopFunction(_pattern, _matchResult,
                        current, startValue, boundVariable, collection);
                FunctionType functionType = new FunctionType(
                        new Type[] { BaseType.OBJECT }, BaseType.GENERAL);
                _evaluatedChildToken =
                    new FunctionToken(function, functionType);
            } else if (functionName == null) {
                Token token = null;
                try {
                    token = _evaluateChild(node, 0);
                } catch (IllegalActionException e) {
                    super.visitFunctionApplicationNode(node);
                    return;
                }

                if (token instanceof FunctionToken) {
                    FunctionToken functionToken = (FunctionToken) token;
                    int argCount = node.jjtGetNumChildren() - 1;
                    if (functionToken.getNumberOfArguments() != argCount) {
                        throw new IllegalActionException("Wrong number of "
                                + "arguments when applying function "
                                + token.toString());
                    }

                    if (functionToken.getFunction() instanceof LoopFunction) {
                        _evaluatedChildToken = functionToken.apply(new Token[] {
                                new ObjectToken(node.jjtGetChild(1)) });
                        return;
                    }
                }
                super.visitFunctionApplicationNode(node);
View Full Code Here

TOP

Related Classes of ptolemy.data.FunctionToken

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.