codesimian
Class Const

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.Const
All Implemented Interfaces:
CodeSimian, java.io.Serializable
Direct Known Subclasses:
Const.ConstByte, Const.ConstDouble, Const.ConstFalse, Const.ConstFloat, Const.ConstInt, Const.ConstShort, Const.ConstTrue, Const.ConstWithUselessParams

public abstract class Const
extends DefaultCS

A final constant number, selected at instantiation. Const.DForProxy() is faster than Num.DForProxy(), because Num's value can change. Java can optimize with Const better.

Contains (static final double) common constants, including the square-roots and cube-roots of all prime-numbers up to 19, PI, E, and the golden-ratio.

See Also:
Serialized Form

Nested Class Summary
static class Const.ConstByte
          My only instance var is a byte.
static class Const.ConstDouble
          My only instance var is a double.
static class Const.ConstFalse
          I have no instance vars.
static class Const.ConstFloat
          My only instance var is a float.
static class Const.ConstInt
          My only instance var is a int.
static class Const.ConstShort
          My only instance var is a short.
static class Const.ConstTrue
          I have no instance vars.
static class Const.ConstWithUselessParams
          A constant value that can contain any quantity of params, but it never executes or does anything to them.
 
Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
Const()
           
 
Method Summary
static int constPoolSize()
          quantity of Const's in the shared pool
 double cost()
          default 0.4
 double D()
          for efficiency, does not use EXEC.
 boolean isConstant()
           
 java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
          This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 java.lang.String name()
          returns the name of this CS.
 boolean needMoreInfo()
           
 CS newInstance()
          Fast access to small integers, like char values in a string.
static Const pool(boolean value)
           
static Const pool(byte value)
           
static Const pool(char value)
          Trys to return a Const from an array (value is index), very fast! Else uses pool(double).
static Const pool(double value)
          get a Const from the shared constant-pool, to save memory and cost of repeated instantiation of simple numbers.
static Const pool(float value)
           
static Const pool(int value)
           
static Const pool(long value)
           
static Const pool(java.lang.Number value)
          Same as the other pool()s.
static Const pool(short value)
           
 boolean setName(java.lang.String name)
          false, Consts should not have names, only number values
 java.lang.String toString()
          should i override decompile() also? or is that private? 8/06 I'm overriding toString() because I think Constants are getting printed in code as their name BEFORE they are given that name in that code.
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, description, DForProxy, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, LForProxy, LForProxy, myFuel, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setObject, setP, setPrevExec, setS, setZ, start, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Const

public Const()
Method Detail

D

public double D()
for efficiency, does not use EXEC.

Overrides:
D in class CS
See Also:
CS.L(java.lang.Class)

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

isConstant

public boolean isConstant()

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

needMoreInfo

public boolean needMoreInfo()

cost

public double cost()
default 0.4

Overrides:
cost in class CS

newInstance

public CS newInstance()
Fast access to small integers, like char values in a string. Range 0 to 7999. These are also in the constant-pool. private static final Const integers[] = new Const[8000]; static{ for(int i=0; i
Overrides:
newInstance in class DefaultCS

pool

public static Const pool(double value)
get a Const from the shared constant-pool, to save memory and cost of repeated instantiation of simple numbers.

If a Const with the requested value does not exist, create it and add it to the pool.

Const can not change value or have any other attributes so it is safe to share Consts.

Const.pool(x) is overloaded. x can be any primitive type or java.lang.Number. 5/05 it simply casts it to double, but it could be more efficient later. Without efficiency, its at least convenient.

//Example from DynamicForLoop. Each iteration, it sets
//the target of a pointer to a Const from the constant-pool...
public double DForProxy(){
CS iterationVarPtr = findAddress( P(0).D() );
//param1 is the dynamic end
CS loopBody = P(2);
double returnValue = 0;
for (double i=0; i < P(1).D(); i++){
iterationVarPtr.setP( 0, Const.pool(i) ); //set the pointer
returnValue = loopBody.D();
}
return returnValue;
}


pool

public static Const pool(float value)

pool

public static Const pool(long value)

pool

public static Const pool(short value)

pool

public static Const pool(byte value)

pool

public static Const pool(char value)
Trys to return a Const from an array (value is index), very fast! Else uses pool(double).


pool

public static Const pool(boolean value)

pool

public static Const pool(java.lang.Number value)
Same as the other pool()s. Dont forget that CS is a Number.


pool

public static Const pool(int value)

constPoolSize

public static int constPoolSize()
quantity of Const's in the shared pool


toString

public java.lang.String toString()
should i override decompile() also? or is that private? 8/06 I'm overriding toString() because I think Constants are getting printed in code as their name BEFORE they are given that name in that code.

Overrides:
toString in class DefaultCS

name

public java.lang.String name()
Description copied from class: CS
returns the name of this CS.

After keyword() is refactored out, parent().name() will replace keyword().

Overrides:
name in class DefaultCS

setName

public boolean setName(java.lang.String name)
false, Consts should not have names, only number values

Overrides:
setName in class DefaultCS

javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
Description copied from class: DefaultCS
This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.

Example:
CodeSimian code: *(+(2 3) /(4 5))
becomes this Java code: (2+3)*(4/5) There could be problems with Java's parsing order...

Overrides:
javaCode in class DefaultCS
Returns:
String of Java code, or null if this CS does not know how to convert itself to Java code.