codesimian
Class Const

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.Const
All Implemented Interfaces:
CodeSimian
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.


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, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
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()
          temporarily (need to write some more code), uses Class objects to instantiate the default constructor
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, setPType, setS, setZ, start, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, 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, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, 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()
Description copied from class: DefaultCS
temporarily (need to write some more code), uses Class objects to instantiate the default constructor

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