codesimian
Class CS<CSGeneric>

java.lang.Object
  extended by codesimian.CS<CSGeneric>
All Implemented Interfaces:
CodeSimian
Direct Known Subclasses:
DefaultCS, IndependentCS

public abstract class CS<CSGeneric>
extends java.lang.Object
implements CodeSimian

CS is the root of all other classes! Its the top of the CodeSimian heirarchy. Most of what you need to know to add new Java code To CodeSimian is in this file.

Using class JavaOutSimple, which uses class GetJavaCompiler, some parts of CodeSimian code (created at runtime) can be converted to Strings of Java code for a subclass of CS.java. The generated classes go into package codesimian.javaout. The existing subclasses of CS (in many combinations) generate new unique and useful subclasses of CS, and theoretically (or should I say theoryly) those subclasses will build even smarter subclasses... or at least efficient replacements for common combinations of codesimian code, and should search for and replace those codes with the new class at runtime. This changes the shape of the network (a group of nodes becomes 1 node) therefore it changes the behavior of code that depends on the shape (instead of the return value) of other code. For a large code, converting it to a new java class could speed it up 10 times or more.

/ * Free, Open-Source: GNU General Public License 2+ (GPL) ** \ LEGAL: U agree to GPL if U modify or distribute CodeSimian GPL version 2 or higher (your choice) in file doc/license.txt NO WARRANTY! Use this self-modifying-software AT OWN RISK CodeSimian is RECURSIVELY **FREE** to use modify & distribute and is Copyright 2006 and 2007, Benjamin F Rayfield Websites: www.codesimian.com codesimian.sourceforge.net \ ******************************************************* /

All functions in CS are public and some are also abstract. There are no variables, only functions.

Each CS is a list of other CSs, and each subclass of CS uses the contents of the list differently.

List size, countP(), must be between minP() and maxP() when the CS is EXECUTED. All functions whose names contain a capital P (except "Proxy" and "Parent") are about PARAMS (CSs inside this CS). Examples: P(int), PD(), setP(int,CS). Params are the contents of the list: Each CS is a list of other CSs.

Each CS has 1 main action: EXECUTE this CS. All of these functions can EXECUTE a CS: V() L(Class) L(int,Class,int) Z() B() C() S() I() J() F() and D(). Each does approximately the same thing, but with a different return-type. All types of primitive and array can be returned, and many object types. Different CSs can return different object types, many types per CS.

CS objects should try to use other CS objects only as type CS instead of their runtime-type, to avoid tangling CodeSimian with hard-code. Example: CS mult = new Multiply(); instead of: Multiply mult = new Multiply(); That allows me to later write: mult = new AntiDivide(); //AntiDivide does not extend Multiply In codesimian code, 2 times (3 plus 4 plus 5) times 6 is written as: *(2 +(3 4 5) 6) Any type-specific functions you need to call can be called dynamicly with a JavaFunctionSimple.

Functions whose names start with "set" return boolean. Most of them are allowed to ALWAYS RETURN FALSE, which would mean that feature is not available in the CS it is called from, but may be available in other CSs.

A TYPE is any primitive, Object, primitive[] array, Object[] array, or a CS containing any of those.
In addition to that, CodeSimian uses a more advanced idea of TYPE:
A TYPE is a CS whose maxP() is at least 1. A TYPE measures its 1 parameter (the CS returned by theType.P(0)), and returns a more positive number if the parameter is more like that type, or 0 or less if it is not that type. Of course, the more negative, the less like that type it is. A TYPE is like an anonymous fitness-function in a genetic-algorithm.

Some functions (that usually do the same thing) come in groups of 10-12, each for a different TYPE. Example: the EXECUTE functions above. Example: the PREV functions. Example: the setX functions where X is any EXECUTE function.


WHY SO MANY FUNCTIONS?
These 100+ functions seem confusing, but they are ordered on 3 dimensions+++
+ There are 4 main actions: SET, GET, INSERT, and DELETE.
+ There are 3 main targets: 1 CS in params, multiple adjacent CSs in params, the value of this CS.
+ TYPES. Multiply 3 x 4 x all the TYPES, and you get a 3D block of functions, where the location tells what the function does.
There is a hole in the cube at INSERT or DELETE x VALUE OF THIS CS.

Some functions like heap() and setHeap(CS) are not included in that cube. They're simply the GET and SET for variables that a CS should have, but are not copied for each TYPE. Theres only 1 get and 1 set. But these functions (like heap() and parsePriority()) are complicating CS.java, so they should eventually be changed to only be accessed by L("heap") setL("heap",someObject) etc. Only important functions, like myFuel() and name(), will remain hard-coded into CS.java.

Functions whose name contains a capital L allow Java Object types to be converted to and from CSs. L functions with 1 or more int parameters allow OPTIMIZATIONS for specific Object types.
Example: if some CS's params are represented as chars in a String (instead of a CS[] array) then that CS should override L(int i,Class c,int j) to return new S(String.substring(i,i+j)) if c == String.class; else return super.L(i,c,j); //S is a type of CS that is stored as a String in memory

WHY IS CS A CLASS INSTEAD OF AN INTERFACE?
I would have liked to make CS be an interface instead of an abstract class, for more flexibility in extending it, but I found that as a class it is approximately 30% faster than as an interface (in the very limited tests I did). Thats probably because as a class its functions are in known indexs in the JVM's array of functions, but as an interface, its functions could be at any index since the CLASS determines position, and functions must be looked up more DYNAMICLY which is slower. Not much has been lost: Since this class has approximately 100 functions, its unlikely anybody would use it as an interface except by automatic generation of Java code (by JavaOutSimple.java), and then it would be too hard to rename any function or field name collisions. Class is faster than interface, but interface is more flexible.

Many functions use this CS as a list of CSs. The default implementations are lazy and dont always throw IndexOutOfBoundsException's when they should.

TODO: remove the "heap" functions of this class??? Heap used negative indexs. It will still use negative indexs, but only hard-coded indexs like these...

public static final int NULL = -1;
public static final int EXECPROXY = -2;
public static final int PREV = -3;
public static final int FUEL = -4;
public static final int MYFUEL = -5;
public static final int NAME = -6;
public static final int NEWINSTANCE = -7;
public static final int PARENT = -8;
public static final int DESCRIPTION = -9;
public static final int PARSEPRIORITY = -10;
public static final int JAVACODE = -11;
public static final int HEAP = -12;


Field Summary
static int DESCRIPTION
           
static int END
          This is the lowest negative index reserved for CS reflection MINUS ONE.
static int EXECPROXY
          someCS.P(CS.EXECPROXY) should return someCS.getExec(),
and optionally someCS.setP(CS.EXECPROXY,x) (or other SET functions) should call someCS.setExec(x), but if the SET functions dont do that, they should return false in that case.
static int HEAP
           
static int JAVACODE
           
static int MYFUEL
           
static int NAME
           
static int NEWINSTANCE
           
static int NULL
          NULL is returned, for example, by indexP(CS) when the CS cant be found.
static int PARENT
           
static int PARSEPRIORITY
           
static int PREV
          important if myFuel==0, but may be replaced (for all primitives, this is Double) by prevD(double howFarBack) or prevL prevC etc.
static int TESTER
           
static int THIS
           
 
Constructor Summary
CS()
           
 
Method Summary
 CS addB(byte x)
           
 CS addC(char x)
           
 CS addD(double x)
           
 CS addF(float x)
           
 CS addI(int x)
           
 CS addJ(long x)
           
 CS addL(java.lang.Object add0)
          same as setL1(countP(),add0) except returns this if setL1 succeeds else returns throwFromAdd('P')
 CS addP(CS param)
          Adds a new param at the end of the list.
 CS addP(CS add0, CS add1)
          Deprecated. 
 CS addP(CS add0, CS add1, CS add2)
          Deprecated. 
 CS addP(CS add0, CS add1, CS add2, CS add3)
          Deprecated. 
 CS addP(CS add0, CS add1, CS add2, CS add3, CS add4)
          Deprecated. 
 CS addS(short x)
           
 CS addZ(boolean x)
           
 byte B()
           
 byte BForProxy()
           
 char C()
           
 char CForProxy()
           
 java.lang.Object clone()
          returns newInstance(), but if thats null then throws a CloneNotSupportedException This function overrides java.lang.Object.clone();
 double cost()
          cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively.
abstract  int countP()
          Quantity of params.
 double D()
          Execute this CS and cast to double.
abstract  boolean decrementMyFuel()
          Try to use 1 fuel credit.
abstract  boolean deleteP(int index)
          Deletes a Param at specified index, and slides the higher params down 1 index.
 boolean deleteP(int startIndex, int quantity)
          deletes a range of Params
abstract  java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
abstract  double DForProxy()
          Execute this CS and cast to double.
 float F()
           
 float FForProxy()
           
abstract  CS fuel()
          Fuel limits EXECUTION of CSs, to make sure none execute too much more than the others.
 byte GETB()
           
 char GETC()
           
 double GETD()
           
abstract  CS getExec()
          Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper.
 float GETF()
           
 int GETI()
           
 long GETJ()
           
 java.lang.Object GETL(java.lang.Class type)
           
 java.lang.Object getObject()
          Deprecated. 
 short GETS()
           
 boolean GETZ()
           
abstract  CS heap()
          HEAP is a place to put CSs that are not directly related to the CS that contains them.
 int I()
           
 int IForProxy()
           
 int indexP(CS myParam)
          Opposite of P(int).
Returns the index of the specified param, or -1 if its not a param of this CS.
 int indexPName(java.lang.String paramName)
          returns the index of the Param with specified Name, or -1 if no Param has that Name.
 boolean insertB(int paramIndex, byte value)
           
 boolean insertC(int paramIndex, char value)
           
abstract  boolean insertD(int paramIndex, double value)
          inserts a double as a param at a specific index.
 boolean insertF(int paramIndex, float value)
           
 boolean insertI(int paramIndex, int value)
           
 boolean insertJ(int paramIndex, long value)
           
abstract  boolean insertL(int startIndex, java.lang.Object insertMe)
          Inserts an Object into MULTIPLE param indexs.
abstract  boolean insertL(int startIndex, java.lang.Object insertMe, int indexQuantity)
          Inserts an Object into a specific subset of param indexs.
abstract  boolean insertL1(int singleIndex, java.lang.Object value)
          inserts an Object into 1 param index.
abstract  boolean insertP(int index, CS insertMe)
          same as setP(int,CS) but inserts instead of overwriting.
 boolean insertS(int paramIndex, short value)
           
 boolean insertZ(int paramIndex, boolean value)
           
 byte isIllusion(int index)
          Describes if the CS in an index is an illusion or not.
 long J()
          Execute this CS and cast to long.
Most subclasses should override JForProxy() instead of J(), or neither, which is true for all ?ForProxy vs ? functions.
 long JForProxy()
           
abstract  java.lang.String keyword()
          Deprecated.  
 java.lang.Object L(java.lang.Class castToThisType)
          Optionally execute this CS, and definitely try to CAST it to the specified Java type.
 java.lang.Object L(int startIndex, java.lang.Class castToThisType, int indexQuantity)
          same as L(Class) except only uses a subset of param indexs.
Like many other L functions, allows converting CSs to specific Object types.
Example: new S("abcdefg").L(2,String.class,3) returns "cde".
 java.lang.Object L(int startIndex, java.lang.Object castToThisType, int indexQuantity)
           
 java.lang.Object L(java.lang.Object key)
          The 3 most common key types are: Class, Integer, and Number.
 java.lang.Object L(java.lang.String varName)
          Deprecated. replace me with L(Object) and setL(Object,Object)
abstract  java.lang.Object LForProxy(java.lang.Class castToThisType)
          The "?ForProxy" functions should only be called by a PROXY CS.
abstract  java.lang.Object LForProxy(int startIndex, java.lang.Class castToThisType, int indexQuantity)
           
 double maxD()
          maximum value D() can ever return (or any of the other primitive EXECUTE functions).
 int maxP()
          Maximum quantity of Params
 double minD()
          minimum value D() can ever return (or any of the other primitive EXECUTE functions).
abstract  int minP()
          Minimum quantity of Params.
abstract  int myFuel()
          Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel.
abstract  java.lang.String name()
          returns the name of this CS.
abstract  CS newInstance()
          The primary way to instantiate subclasses of CS.
 byte overwrites(int index)
          Describes when (if ever) this CS overwrites one of its own childs.
abstract  CS P(int index)
          Returns a CS from this list with specific index.
 CS parent()
          9/06 parent() is not yet finished.
 int parsePriority()
          Deprecated.  
 byte PB(int paramIndex)
           
 char PC(int paramIndex)
           
 double PD(int paramIndex)
          Returns a param as a double.
 float PF(int paramIndex)
           
 int PI(int paramIndex)
           
 long PJ(int paramIndex)
           
 java.lang.Object PL(int paramIndex, java.lang.Class castParamToThisType)
          PL PD PF PJ PI PS PC PB and PZ are only for convenience and optimization.
 byte prevB()
           
 char prevC()
           
abstract  double prevD()
          Returns the value of the last EXECUTION of this CS
 float prevF()
           
 int prevI()
           
 long prevJ()
           
abstract  java.lang.Object prevL()
          returns the previous execute value as an Object.
 short prevS()
           
 boolean prevZ()
          Returns true if the PREVIOUS EXECUTION of this CS was a positive number (or true).
 CS proxyOf(java.lang.reflect.Method anyMethodInThisClass)
          a proxy for a specific Java Method.
 short PS(int paramIndex)
           
abstract  CS PType(int index)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 boolean PZ(int paramIndex)
           
 java.lang.Object reflect(java.lang.Object[] nameAndParameters)
          Calls any function by reflection, including reflective functions on higher levels, reflection of reflection of reflection...
 java.lang.Object reflect(java.lang.String name, java.lang.Object[] parameters)
          same as reflect(Object[]) except the array is 1 smaller, and all indexs are 1 lower, and the first element which was taken out is String name,

This function is useful because it can use the same array as java.lang.reflect.Method.invoke(Object[]); Name should equal java.lang.reflect.Method.getName() of some Java function (Method).
 CodeSimian reflect6(java.lang.Class returnType, java.lang.Class instanceType, byte getSetInsertOrDelete, java.lang.Class locationType, byte quantityType, java.lang.Class valueType)
          Returns a CS with countP()==6, that reflects almost any possible action in codesimian language.
 short S()
           
 boolean setB(byte setToThisValue)
           
 void SETB(byte b)
           
 boolean setB(int paramIndex, byte value)
           
 boolean setC(char setToThisValue)
           
 void SETC(char c)
           
 boolean setC(int paramIndex, char value)
           
 boolean setCost(float cost)
          Rename this to setCostToExecute()
abstract  boolean setD(double setToThisValue)
           
 void SETD(double d)
           
abstract  boolean setD(int paramIndex, double value)
          sets a param to a double value.
 boolean setDescription(java.lang.String newDescription)
           
 boolean setExec(CS newExecProxy)
           
 boolean setF(float setToThisValue)
           
 void SETF(float f)
           
 boolean setF(int paramIndex, float value)
           
abstract  boolean setFuel(CS newFuel)
           
 boolean setHeap(CS newHeap)
           
 boolean setI(int setToThisValue)
           
 void SETI(int i)
           
 boolean setI(int paramIndex, int value)
           
 boolean setJ(int paramIndex, long value)
           
 boolean setJ(long setToThisValue)
           
 void SETJ(long j)
           
abstract  boolean setL(int startIndex, java.lang.Object setToThisValue)
          Overwrites a range of params with some interpretation of the Object.
Like setL(int,Object,int) but the Object determines the quantity of indexs.
abstract  boolean setL(int startIndex, java.lang.Object setToThisValue, int indexQuantity)
          like setL(Object) but sets exactly the indexs between startIndex and startIndex+indexQuantity-1 inclusive
abstract  boolean setL(java.lang.Object setToThisValue)
          setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.
 void SETL(java.lang.Object l)
           
 boolean setL(java.lang.Object key, java.lang.Object value)
          Sets the value of something.
 boolean setL(java.lang.String varName, java.lang.Object value)
          Deprecated. replace me with L(Object) and setL(Object,Object)
abstract  boolean setL1(int singleIndex, java.lang.Object value)
          overwrites 1 param with an Object.
abstract  boolean setMyFuel(int newValue)
           
 boolean setName(java.lang.String newName)
          sets the name of this CS
 boolean setObject(java.lang.Object setTo)
          Deprecated.  
abstract  boolean setP(int index, CS setTo)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 boolean setParent(CS parent)
           
 boolean setParsePriority(int parsePriority)
           
abstract  void setPrevExec(double d)
          Deprecated.  
 boolean setProxyOf(java.lang.reflect.Method anyMethodInThisClass, CS proxy)
          sets the proxy of a Method.
 boolean setPType(int indexP, CS newTypeOfThatParam)
          Since only a small fraction of CSs use types other than the default type, setPType(int,CS) returns false by default.
 boolean setS(int paramIndex, short value)
           
 boolean setS(short setToThisValue)
           
 void SETS(short s)
           
 boolean setTester(CS tester)
          default: false
 boolean setZ(boolean setToThisValue)
           
 void SETZ(boolean z)
           
 boolean setZ(int paramIndex, boolean value)
           
 short SForProxy()
           
 CS tester()
          Returns a CS that can test if this CS works correctly, or null if dont know how to test.
 java.lang.String toJavaCode(CSCallOptions options, JavaCodeWritingState state)
          returns the code for a new subclass of CS that does the same thing as this network of code.
 void V()
           
 void VForProxy()
           
 void voidReflect(java.lang.Object[] returnAndNameAndParameters)
          Same as reflect(Object[]) except the array is 1 bigger, and returnAndNameAndParameters[0] is replaced by the return-value of the reflected function being called, and all indexs are 1 higher.
 boolean Z()
           
 boolean ZForProxy()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final int NULL
NULL is returned, for example, by indexP(CS) when the CS cant be found.

See Also:
Constant Field Values

THIS

public static final int THIS
See Also:
Constant Field Values

NEWINSTANCE

public static final int NEWINSTANCE
See Also:
Constant Field Values

NAME

public static final int NAME
See Also:
Constant Field Values

MYFUEL

public static final int MYFUEL
See Also:
Constant Field Values

EXECPROXY

public static final int EXECPROXY
someCS.P(CS.EXECPROXY) should return someCS.getExec(),
and optionally someCS.setP(CS.EXECPROXY,x) (or other SET functions) should call someCS.setExec(x), but if the SET functions dont do that, they should return false in that case.

There are others that work similarly: PREV, FUEL, NEWINSTANCE, PARENT, HEAP, NAME, DESCRIPTION, AND PARSEPRIORITY

See Also:
Constant Field Values

PREV

public static final int PREV
important if myFuel==0, but may be replaced (for all primitives, this is Double) by prevD(double howFarBack) or prevL prevC etc.

See Also:
Constant Field Values

JAVACODE

public static final int JAVACODE
See Also:
Constant Field Values

DESCRIPTION

public static final int DESCRIPTION
See Also:
Constant Field Values

HEAP

public static final int HEAP
See Also:
Constant Field Values

PARENT

public static final int PARENT
See Also:
Constant Field Values

TESTER

public static final int TESTER
See Also:
Constant Field Values

PARSEPRIORITY

public static final int PARSEPRIORITY
See Also:
Constant Field Values

END

public static final int END
This is the lowest negative index reserved for CS reflection MINUS ONE. This is the maximum possibly usable index for nonstandard purposes.

If you call P(x) or setP(x,someCS) and CS.END <= x < 0 then it calls a get or set function. Example: setI(CS.MYFUEL,20) and setP(CS.MYFUEL,new N(20)) both call setMyFuel(20).

You may use any indexs at or lower than CS.END for anything.

Some CSs will allow you to call setP(END-1,someCS) then P(END-1) == someCS.
The default way this is implemented is by using HEAP's params with positive indexs as negative indexs here. HEAP is any CS that can be a list of CSs, but thats not set-in-stone.

See Also:
Constant Field Values
Constructor Detail

CS

public CS()
Method Detail

P

public abstract CS P(int index)
Returns a CS from this list with specific index. Every CS is a list of other CSs, each with an index between 0 and countP()-1. The quantity of CSs in the list is countP(), which should be between minP() and maxP() inclusive. Errors could occur if quantity is outside that range when this CS is EXECUTED.

There can also be CSs at negative indexs. Maps some negative indexs to the HEAP:
If x <= -2 then CS.P(x) returns CS.heap().P(-x). Index -1 returns NULL.

Parameters:
index - range 0 (or neg?) to countP()-1 inclusive
See Also:
heap()

setP

public abstract boolean setP(int index,
                             CS setTo)
Every CS is a list of other CSs, between size minP() and maxP() inclusive. setP overwrites one of those CSs or adds a new one at the end, depending on the index. If index is between 0 and countP()-1, overwrites. If it equals countP(), adds at end.


insertP

public abstract boolean insertP(int index,
                                CS insertMe)
same as setP(int,CS) but inserts instead of overwriting. All higher params slide up 1 index.


deleteP

public abstract boolean deleteP(int index)
Deletes a Param at specified index, and slides the higher params down 1 index.


deleteP

public boolean deleteP(int startIndex,
                       int quantity)
deletes a range of Params

Specified by:
deleteP in interface CodeSimian

minP

public abstract int minP()
Minimum quantity of Params. countP() may be below minP() only a short time during compiling, and you must not EXECUTE this CS during that time or you risk an error. TODO: 9/07 that has become a problem with some classes like S, which calls x.C() when x is added, but x may have been added during compiling when x.countP() < x.minP().


countP

public abstract int countP()
Quantity of params. Should be between minP() and maxP() inclusive when you EXECUTE this CS. Can be below minP() for a short time during compiling, but you must not EXECUTE this CS during that time.


maxP

public int maxP()
Maximum quantity of Params


indexP

public int indexP(CS myParam)
Opposite of P(int).
Returns the index of the specified param, or -1 if its not a param of this CS.

This is needed for efficiency of finding params in CSs whose countP() is very large. For most CSs, countP() < 10, and a linear search is fast enough, but for CSs that are used like huge arrays, indexP should use a CS-to-int hashtable.

This default implementation uses LINEAR SEARCH and does not search the HEAP.


indexPName

public int indexPName(java.lang.String paramName)
returns the index of the Param with specified Name, or -1 if no Param has that Name.

This default implementation does not search the HEAP.

See Also:
name(), setName(String), indexP(CS)

PType

public abstract CS PType(int index)
There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1. When a TYPE executes, it MEASURES THE TYPE OF its first param CS. It returns a positive number if it is that type, else 0 or negative. Some TYPEs use only 2 numbers, while others can return any number in a continuous range.

Types are optional. To not use types, return the default type: Static.defaultType(). The default type returns true for any CS. Most CSs do not need types therefore they use the default type.


setPType

public boolean setPType(int indexP,
                        CS newTypeOfThatParam)
Since only a small fraction of CSs use types other than the default type, setPType(int,CS) returns false by default. The same is true of many other functions of CS, which may choose not to cooperate.


addP

public CS addP(CS param)
Adds a new param at the end of the list. Same as setP(countP(),param).

P means param. getP setP insertP and deleteP are the primary way to access params. addP must ALWAYS use those to access params. You should not set it up so any of those 4 use addP.

Returns 'this' CS so code like this works:
int ten = new Multiply().addP(new N(2),new N(5)).I();

Returns:
'this' CS if added param, or throwFromAdd('P') if did not add.

addP

@Deprecated
public CS addP(CS add0,
                          CS add1)
Deprecated. 

same as addP(add0) then addP(add1)


addP

@Deprecated
public CS addP(CS add0,
                          CS add1,
                          CS add2)
Deprecated. 


addP

@Deprecated
public CS addP(CS add0,
                          CS add1,
                          CS add2,
                          CS add3)
Deprecated. 


addP

@Deprecated
public CS addP(CS add0,
                          CS add1,
                          CS add2,
                          CS add3,
                          CS add4)
Deprecated. 


addL

public CS addL(java.lang.Object add0)
same as setL1(countP(),add0) except returns this if setL1 succeeds else returns throwFromAdd('P')


addD

public CS addD(double x)

addF

public CS addF(float x)

addJ

public CS addJ(long x)

addI

public CS addI(int x)

addS

public CS addS(short x)

addC

public CS addC(char x)

addB

public CS addB(byte x)

addZ

public CS addZ(boolean x)

PL

public java.lang.Object PL(int paramIndex,
                           java.lang.Class castParamToThisType)
                    throws CSCastException
PL PD PF PJ PI PS PC PB and PZ are only for convenience and optimization. Each gets P(int) then calls L(Class) D() F() etc on it, the second letter of that function's name.
PL(5,String.class) should return P(5).L(String.class) or something that gets the same result faster.

Throws:
CSCastException

PD

public double PD(int paramIndex)
Returns a param as a double. Same as P(paramIndex).D()

Why not just use P(paramIndex).D() instead? Its not just for convenience. Some CSs store their params as doubles or other primitives (or any type of Object, usually String or CS), and if you predict correctly how params are stored, PD(paramIndex) is much faster than P(paramIndex).D(), but BEWARE: if you predict incorrectly its a little slower. It calculates the same double either way.

For all paramIndex: P(paramIndex).D() == PD(paramIndex)


PF

public float PF(int paramIndex)
See Also:
PD(int)

PJ

public long PJ(int paramIndex)
See Also:
PD(int)

PI

public int PI(int paramIndex)
See Also:
PD(int)

PS

public short PS(int paramIndex)
See Also:
PD(int)

PC

public char PC(int paramIndex)
See Also:
PD(int)

PB

public byte PB(int paramIndex)
See Also:
PD(int)

PZ

public boolean PZ(int paramIndex)
See Also:
PD(int)

L

public java.lang.Object L(java.lang.Class castToThisType)
                   throws CSCastException
Optionally execute this CS, and definitely try to CAST it to the specified Java type. If fail, throw a ClassCastException.

It is preferred not to return CSs from this function. If you have a CS to return, the standard is to put it in param0... setP(0,returnValue), where the function caller should get the output from... P(0).

The functions: V Z B C S I J F D and L , usually EXECUTE this CS and CAST its value to the specified type.
L does not have to execute this CS, but all the others do. The other difference is L can throw a CSCastException (extends ClassCastException).

No pattern of L()'s behavior is guaranteed except for primitive wrappers and 1D arrays.
The L's of some some CSs are more predictable than others, often written about in javadoc of a class.
If it casts correctly, it could fail later. If it fails many times, and you try again, it could still succeed.

These 10 function names are also used by a core part of Java (but not as function names): java.lang.Class.name() . Example: new int[7][6][5].getClass().getName() returns "[[[I".

EXAMPLES:
JButton b = (JButton) new ButtonCS().L(Component.class); //JButton inherits from Component
int fiveFiftyFive = new N(555).I();
double charValues[] = (double[]) new S("arraySize11").L(double[].class);

Throws:
CSCastException
See Also:
Z(), B(), C(), S(), I(), J(), F(), D()

LForProxy

public abstract java.lang.Object LForProxy(java.lang.Class castToThisType)
                                    throws CSCastException
The "?ForProxy" functions should only be called by a PROXY CS. They skip the proxy. Example: B() calls the PROXY on this CS, then that PROXY calls thisCS.BForProxy(). Generally, subclasses of CS should implement the ?ForProxy functions but not the ? functions.

Throws:
CSCastException
See Also:
execProxy(), setExecProxy(CS)

L

public java.lang.Object L(int startIndex,
                          java.lang.Object castToThisType,
                          int indexQuantity)
Specified by:
L in interface CodeSimian

L

public java.lang.Object L(int startIndex,
                          java.lang.Class castToThisType,
                          int indexQuantity)
                   throws CSCastException
same as L(Class) except only uses a subset of param indexs.
Like many other L functions, allows converting CSs to specific Object types.
Example: new S("abcdefg").L(2,String.class,3) returns "cde".

Throws:
CSCastException

LForProxy

public abstract java.lang.Object LForProxy(int startIndex,
                                           java.lang.Class castToThisType,
                                           int indexQuantity)
                                    throws CSCastException
Throws:
CSCastException
See Also:
L(int,Class,int)

L

public java.lang.Object L(java.lang.String varName)
Deprecated. replace me with L(Object) and setL(Object,Object)

reflects some of my functions as named variables, and returns the value of a variable. Also returns CSs whose name you specify. Or returns null if that name means nothing to me.

Example: someCS.L("description") returns someCS.description(); Example: someCS.L("cost") returns someCS.cost();

STANDARD VARIABLE NAMES include name, cost, proxy, fuel, myFuel, description, newInstance, parent, parsePriority, heap, tester, prevD, etc. Returns the CS found by indexPName(varName) if varName is not a standard name.

FIX THE DESIGN OF CS.JAVA: Eventually description() and cost() should become protected or private (instead of public) and be completely replaced by L(String) and setL(String,Object), because class CS should have as few functions as possible. Its ok for CS to have lots of functions that interact with params, like PD(int), P(int), setD(int,double) etc, but some functions are best abstracted to a variable inside a CS instead of a required part of every CS. For efficiency, functions like getExec() and myFuel() etc will stay as functions, but can also be used by L("myFuel") or setL("getExec",someExecProxyCS);

See Also:
Static.defaultVarNames(), Static.defaultVarTypes()

L

public java.lang.Object L(java.lang.Object key)
The 3 most common key types are: Class, Integer, and Number. Some instances of all 3 work by default.

I have not yet decided if this function will replace L(String) and L(Class)
and can do the same things as P(int) if "key" is a Number (uses Number.intValue()).

Specified by:
L in interface CodeSimian

setL

public boolean setL(java.lang.Object key,
                    java.lang.Object value)
Sets the value of something. Which thing is described by the KEY.

Key can be any Number between 0 and countP()-1, some Strings, or some Classes. Not all Strings and Classes work. Key may be any other Object, but CSs probably will not understand it unless designed for that.

Specified by:
setL in interface CodeSimian
See Also:
L(Object)

V

public void V()
See Also:
Execute this CS. Do not return anything. V = Void. Some CSs have side-effects (most at least have side effects recursively), so void is not useless.

VForProxy

public void VForProxy()
See Also:
DForProxy()

Z

public boolean Z()
See Also:
execute this CS and cast to boolean. By default, all positive numbers are true, 0 & neg false. Its called Z because B is used by byte, and java.lang.Class.name() uses Z for boolean. All the functions that execute a CS have names equal to one of java.lang.Class.name();

ZForProxy

public boolean ZForProxy()
See Also:
DForProxy()

B

public byte B()
See Also:
Execute this CS and cast to byte

BForProxy

public byte BForProxy()
See Also:
DForProxy()

C

public char C()
See Also:
Execute this CS and cast to char

CForProxy

public char CForProxy()
See Also:
DForProxy()

S

public short S()
See Also:
Execute this CS and cast to short

SForProxy

public short SForProxy()
See Also:
DForProxy()

I

public int I()
See Also:
Execute this CS and cast to int

IForProxy

public int IForProxy()
See Also:
DForProxy()

J

public long J()
Execute this CS and cast to long.
Most subclasses should override JForProxy() instead of J(), or neither, which is true for all ?ForProxy vs ? functions.

WARNING: by default, like the other execute functions, J() calls D() and casts to J's type.
long is the only primitive type that double has problems with.
double maps to long correctly for all values between at least -2^51 and 2^51 - 1.
Past that, possible number values occur at bigger and bigger intervals, less than integer precision.

See Also:
L(Class), java.lang.Double.doubleToLongBits(double)

JForProxy

public long JForProxy()
See Also:
DForProxy()

F

public float F()
See Also:
Execute this CS and cast to float

FForProxy

public float FForProxy()
See Also:
DForProxy()

D

public double D()
Execute this CS and cast to double. All subclasses should override DForProxy() instead of D().

See Also:
L(java.lang.Class)

DForProxy

public abstract double DForProxy()
Execute this CS and cast to double.

D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, return DForProxy cast to their own type.

For example, J() calls the proxy which calls JForProxy() which calls DForProxy(). D() calls the proxy which calls DForProxy().

By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()


minD

public double minD()
minimum value D() can ever return (or any of the other primitive EXECUTE functions). Default is -Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return -1.


maxD

public double maxD()
maximum value D() can ever return (or any of the other primitive EXECUTE functions). Default is Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return 1.


prevL

public abstract java.lang.Object prevL()
returns the previous execute value as an Object.

The function prevL() does not fit well into this interface. If it had a Class parameter, it would take too much instance space and time. If it has no Class parameter, it might not match the Object you're comparing to.

The functions L(Class) Z B C S I J D and F should set the values that these PREV functions return.

Other PREV functions return every other type. There are 9 PREV functions. All 9 are about the same one variable, which can be ANY type. Any one of these functions reads or writes the value of the other 8 and itself.


prevZ

public boolean prevZ()
Returns true if the PREVIOUS EXECUTION of this CS was a positive number (or true).

See Also:
prevD()

prevB

public byte prevB()
See Also:
prevD()

prevC

public char prevC()
See Also:
prevD()

prevS

public short prevS()
See Also:
prevD()

prevI

public int prevI()
See Also:
prevD()

prevJ

public long prevJ()
See Also:
prevD()

prevF

public float prevF()
See Also:
prevD()

prevD

public abstract double prevD()
Returns the value of the last EXECUTION of this CS


setL

public abstract boolean setL(java.lang.Object setToThisValue)
setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.


setD

public abstract boolean setD(double setToThisValue)

setF

public boolean setF(float setToThisValue)
See Also:
setD(double)

setJ

public boolean setJ(long setToThisValue)
See Also:
setD(double)

setI

public boolean setI(int setToThisValue)
See Also:
setD(double)

setS

public boolean setS(short setToThisValue)
See Also:
setD(double)

setC

public boolean setC(char setToThisValue)
See Also:
setD(double)

setB

public boolean setB(byte setToThisValue)
See Also:
setD(double)

setZ

public boolean setZ(boolean setToThisValue)
See Also:
setD(double)

setL1

public abstract boolean setL1(int singleIndex,
                              java.lang.Object value)
                       throws CSCastException
overwrites 1 param with an Object. Like setL(int,Object) but only uses 1 index. The easiest way to do this is put it in a CS and setP(singleIndex,that CS).

Specified by:
setL1 in interface CodeSimian
Throws:
CSCastException

setL

public abstract boolean setL(int startIndex,
                             java.lang.Object setToThisValue)
Overwrites a range of params with some interpretation of the Object.
Like setL(int,Object,int) but the Object determines the quantity of indexs.

Specified by:
setL in interface CodeSimian
See Also:
setL(int,Object,int)

setL

public boolean setL(java.lang.String varName,
                    java.lang.Object value)
Deprecated. replace me with L(Object) and setL(Object,Object)

Sets (overwrites) the variable with specified name. STANDARD VARIABLE NAMES include name, cost, proxy, fuel, myFuel, description, newInstance, parent, parsePriority, heap, prevD, etc. Replaces the CS found by indexPName(varName) if varName is not a standard name.

See Also:
Static.defaultVarNames(), Static.defaultVarTypes()

setL

public abstract boolean setL(int startIndex,
                             java.lang.Object setToThisValue,
                             int indexQuantity)
like setL(Object) but sets exactly the indexs between startIndex and startIndex+indexQuantity-1 inclusive

Specified by:
setL in interface CodeSimian

setZ

public boolean setZ(int paramIndex,
                    boolean value)
See Also:
setD(int,double)

setB

public boolean setB(int paramIndex,
                    byte value)
See Also:
setD(int,double)

setC

public boolean setC(int paramIndex,
                    char value)
See Also:
setD(int,double)

setS

public boolean setS(int paramIndex,
                    short value)
See Also:
setD(int,double)

setI

public boolean setI(int paramIndex,
                    int value)
See Also:
setD(int,double)

setJ

public boolean setJ(int paramIndex,
                    long value)
See Also:
setD(int,double)

setF

public boolean setF(int paramIndex,
                    float value)
See Also:
setD(int,double)

setD

public abstract boolean setD(int paramIndex,
                             double value)
sets a param to a double value. Same as P(paramIndex).setD(value)


insertL1

public abstract boolean insertL1(int singleIndex,
                                 java.lang.Object value)
inserts an Object into 1 param index. The easiest way to do this is put it in a CS and insert that CS with setP(int,CS)

Specified by:
insertL1 in interface CodeSimian

insertL

public abstract boolean insertL(int startIndex,
                                java.lang.Object insertMe)
Inserts an Object into MULTIPLE param indexs. Part of the object goes into each index.

Same as insertL(int,Object,int) but the Object determines the quantity of indexs.

Specified by:
insertL in interface CodeSimian
See Also:
insertL(int,Object,int)

insertL

public abstract boolean insertL(int startIndex,
                                java.lang.Object insertMe,
                                int indexQuantity)
Inserts an Object into a specific subset of param indexs. Part of the object goes into each index.

same as setL(int,Object,int) but INSERTS instead of REPLACES. The values in those indexs are pushed up to higher indexs.


insertZ

public boolean insertZ(int paramIndex,
                       boolean value)
See Also:
insertD(int,double)

insertB

public boolean insertB(int paramIndex,
                       byte value)
See Also:
insertD(int,double)

insertC

public boolean insertC(int paramIndex,
                       char value)
See Also:
insertD(int,double)

insertS

public boolean insertS(int paramIndex,
                       short value)
See Also:
insertD(int,double)

insertI

public boolean insertI(int paramIndex,
                       int value)
See Also:
insertD(int,double)

insertJ

public boolean insertJ(int paramIndex,
                       long value)
See Also:
insertD(int,double)

insertF

public boolean insertF(int paramIndex,
                       float value)