All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----gnu.jel.Optimizer
The only optimization currently supported is the evaluation of the constant subexpressions. This class goes even further in its attempts to optimize, it evaluates not only arifmetic constant subexpressions, but also calls to the static methods of the constant arguments. Namely, expressions such as sin(1) will be evaluated at compile time.
Another function of this class is the error handling. If during evaluation of the constant subexpression a error occurs (Throwable is thrown) it is caught and compiled into the resulting class image to be rethrown at execution time. Example : 1/0 will not cause any exceptions to come out of the compiler, but will be compiled into { throw caughtArithmeticError; } if the optimization is turned on. When optimization is off the previous expression will be compiled to { return 1/0 }, which will throw exception at run time ( execution of the evaluate(...) method of the gnu.jel.CompiledExpression). Another thing to note, that Throwables caught at compile time are not recreated at compile time ( they are not compiled into {throw new ArithmeticError()}). Errors being thrown from evaluate(..) method are EXACTLY the same object as those caught during the constant subexpression eveluation. This approach should greatly simplify the error handling and applies not only to arithmetic expressions but also to any exceptions, thrown by interpretable methods.
For more information on how to specify static non interpretable method (as in the case of java.Math.random() see the documentation for gnu.jel.Library
public Optimizer(Library lib)
public void load(boolean c)
public void load(byte c)
public void load(char c)
public void load(short c)
public void load(int c)
public void load(long c)
public void load(float c)
public void load(double c)
public void convert(Class to) throws IllegalStateException
It has the sense to call this function only for narrowing conversions (see §5.1.3 and §5.1.5 of the Java Language Specification (JLS) ). Widening ( §5.1.2, §5.1.4 of JLS) type conversions are performed by this compiler automatically.
public void unary(int o)
The only unary operation for now is the negation (invert sign) operation.
public void function_start()
Example of the sequence of method calls to perform (compile) the function invocation is given in the description of gnu.jel.Optimizer.function_call(...) method.
public void binaryOP_param()
Example of the sequence of method calls to perform (compile) the binary operation is given in the description of gnu.jel.Optimizer.binaryOP() method.
public boolean function_param()
Example of the sequence of method calls to perform (compile) the function is given in the description of gnu.jel.Optimizer.function_call(...) method.
public void function_call(String name) throws IllegalStateException
optimizer.function_start(); optimizer.load(2L); optimizer.function_param(); optimizer.load(2.0); optimizer.function_param(); optimizer.function_call("name_in_the_library");The function name is searched in the library. If there are several applicable functions in the library with the same name (not necessary in the same object originally) the most specific one is called ( See § 15.11.2.2 in the Java Language Specification). Types conversion takes place automatically.
public void binaryOP(int o) throws IllegalStateException
The binary operation codes are defined in gnu.jel.ExpressionImage as constants BI_XX .
Example : "how to sum up two numbers with this optimizer"
optimizer.load(2L); optimizer.binaryOP_param(); optimizer.load(2.0); optimizer.binaryOP(ExpressionImage.BI_PL);Note different types of operands, conversion ( to double) will be performed automatically. Note also binaryOP_param() usage, its use is obligatory to denote that the parameter for subsequent binary operation is now ion stack.
public void finish() throws IllegalStateException
This method should be called exactly once before the attempt to compile is made.
If there was nothing in the stack before it's called this method generates the returning of the null pointer.
public void optimize(int of)
Currently only evaluation of constant subexpressions is performed.
protected boolean optimizeIteration()
public CompiledExpression compile()
public String toString()
public static void main(String args[])
This function works only if the Debugging is turned "ON".
public static void test(Tester t)
This function works only if the Debugging is turned "ON". Used if all package is being tested and not just this class alone.
All Packages Class Hierarchy This Package Previous Next Index