package ptolemy; /* Generated by Ptolemy II (http://ptolemy.eecs.berkeley.edu) Copyright (c) 2005-2009 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ public class Simple { /* Generate type resolution code for .Simple */ // ConstantsBlock from codegen/java/kernel/SharedCode.j private final short TYPE_Token = -1; // #define PTCG_TYPE_Boolean 5 private final short TYPE_Boolean = 5; // #define FUNC_new 0 // #define FUNC_isCloseTo 1 // #define FUNC_delete 2 // #define FUNC_convert 3 Token emptyToken; /* Used by *_delete() and others. */ // Token Boolean_new (Token thisToken, Token... tokens); From codegen/java/kernel/SharedCode.j // Token Boolean_equals (Token thisToken, Token... tokens); From codegen/java/kernel/SharedCode.j // Token Boolean_isCloseTo (Token thisToken, Token... tokens); From codegen/java/kernel/SharedCode.j // Token Boolean_convert (Token thisToken, Token... tokens); From codegen/java/kernel/SharedCode.j /* We share one method between all scalar types so as to reduce code size. */ Token scalarDelete(Token token, Token... tokens) { /* We need to return something here because all the methods are declared * as returning a Token so we can use them in a table of functions. */ return emptyToken; } Integer StringtoInteger(String string) { return Integer.valueOf(string); } Long StringtoLong(String string) { return Long.valueOf(string); } Integer DoubletoInteger(Double d) { return Integer.valueOf((int)Math.floor(d.doubleValue())); } Double IntegertoDouble(Integer i) { return Double.valueOf(i.doubleValue()); } Long IntegertoLong(int i) { return Long.valueOf(i); } String IntegertoString(int i) { return Integer.toString(i); } String LongtoString(long l) { return Long.toString(l); } String DoubletoString(double d) { return Double.toString(d); } String BooleantoString(boolean b) { return Boolean.toString(b); } String UnsignedBytetoString(byte b) { return Byte.toString(b); } private final int NUM_TYPE = 1; private final int NUM_FUNC = 4; //Token (*functionTable[NUM_TYPE][NUM_FUNC])(Token, ...)= { // {Boolean_new, Boolean_equals, scalarDelete, Boolean_convert} //}; int convert_Integer_Integer(int a) { return a; } int multiply_Integer_Integer(int a1, int a2) { return a1 * a2; } int add_Integer_Integer(int a1, int a2) { return a1 + a2; } // make a new integer token from the given value. Token Boolean_new(boolean b) { Token result = new Token(); result.type = TYPE_Boolean; result.payload = Boolean.valueOf(b); return result; } Token Boolean_equals(Token thisToken, Token... tokens) { Token otherToken; otherToken = tokens[0]; return Boolean_new( ( (Boolean)thisToken.payload && (Boolean)otherToken.payload ) || ( !(Boolean)thisToken.payload && !(Boolean)otherToken.payload )); } /* Instead of Boolean_delete(), we call scalarDelete(). */ Token Boolean_convert(Token token, Token... tokens) { switch (token.type) { case TYPE_Boolean: return token; default: throw new RuntimeException("Boolean_convert(): Conversion from an unsupported type.: " + token.type); } } /* Generate shared code for Simple */ /* max and min may be used by the Expression actor. */ // #ifndef max // #define max(a,b) ((a)>(b)?(a):(b)) // #endif // #ifndef min // #define min(a,b) ((a)<(b)?(a):(b)) // #endif /* Finished generating shared code for Simple */ /* end shared code */ /* Simple_Ramp's referenced parameter declarations. */ static int Simple_Ramp_step_; /* Simple_JopWritePort's referenced parameter declarations. */ static int Simple_JopWritePort_portAddress_; /* Simple_JopWritePort's input variable declarations. */ static int Simple_JopWritePort_input; /* Simple_Expression's input variable declarations. */ static int Simple_Expression_input; /* Director has a period attribute, so we track current time. */ double _currentTime = 0; /* Provide the period attribute as constant. */ public final static double PERIOD = 0.5; /* The preinitialization of the director. */ /* preinitRamp */ static int Simple_Ramp__state; /* preinitJopWritePort */ int Simple_JopWritePort__val = 0; int Simple_JopWritePort__lastVal; /* preinitExpression */ static int Simple_Expression__iterationCount = 1; /* end preinitialize code */ public void initialize() { /* Ramp's parameter initialization */ Simple_Ramp_step_ = 1; /* JopWritePort's parameter initialization */ Simple_JopWritePort_portAddress_ = -79; /* The initialization of the director. */ /* initialize Ramp */ Simple_Ramp__state = 0; } public void wrapup() { /* The wrapup of the director. */ } public static void main(String [] args) throws Exception { Simple model = new Simple(); model.initialize(); model.execute(); model.doWrapup(); System.exit(0); } // Don't call initialize() here, it is called in main. public void execute() throws Exception { int iteration; for (iteration = 0; iteration < 20; iteration ++) { run(); } } public void run() throws Exception { /* The firing of the StaticSchedulingDirector */ /* Fire Simple_Ramp */ Simple_Expression_input=Simple_Ramp__state; ; ; if (false) { Simple_Ramp_step_ = convert_Integer_Integer(0); } Simple_Ramp__state += (Integer)Simple_Ramp_step_; /* ....Begin updateOffset....Simple_Ramp_trigger */ /* ....Begin updateOffset....Simple_Ramp_step */ /* ....Begin updateConnectedPortsOffset....Simple_Ramp_output */ /* ....End updateConnectedPortsOffset....Simple_Ramp_output */ /* Fire Simple_Expression */ Simple_JopWritePort_input=(add_Integer_Integer(convert_Integer_Integer((multiply_Integer_Integer(Simple_Expression_input, 256))), 1)); ; ; /* ....Begin updateOffset....Simple_Expression_input */ /* ....End updateOffset....Simple_Expression_input */ /* ....Begin updateConnectedPortsOffset....Simple_Expression_output */ /* ....End updateConnectedPortsOffset....Simple_Expression_output */ /* Fire Simple_JopWritePort */ Simple_JopWritePort__lastVal = Simple_JopWritePort__val; // no check on available input token here - so above assignment is useless Simple_JopWritePort__lastVal = Simple_JopWritePort_input; /* ....Begin updateOffset....Simple_JopWritePort_input */ /* ....End updateOffset....Simple_JopWritePort_input */ /* The postfire of the director. */ /* postfireJopWritePort */ Simple_JopWritePort__val = Simple_JopWritePort__lastVal; com.jopdesign.sys.Native.wrMem(Simple_JopWritePort__val, Simple_JopWritePort_portAddress_); /* postfireExpression */ Simple_Expression__iterationCount++; _currentTime += 0.5; } public void doWrapup() throws Exception { } }