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)
See Also:
insertD(int,double)

insertD

public abstract boolean insertD(int paramIndex,
                                double value)
inserts a double as a param at a specific index. Same as insertP(paramIndex,new N(value))


newInstance

public abstract CS newInstance()
The primary way to instantiate subclasses of CS. CodeSimian is partially a PROTOTYPE LANGUAGE.

Copies the INSTANCE CS and pointers to its childs.
anyCS.P(2) == anyCS.newInstance().P(2)


anyCS.getClass() and anyCS.newInstance().getClass() do not have to share any ancestor class except CS.class. Classes that use artificial-intelligence may choose to return a different class type to improve themselves, but that class type should try to BEHAVE SIMILARLY and must have the SAME childs when newInstance() returns it.

If a subclass is uses variables in a strange way, it may need to override newInstance() to copy them.

Returns a new CS instance of this "type". This has the same name and purpose as java.lang.Class.newInstance().

Its vague. Subclasses of CS that have trees or networks of objects that the CS depends on might need to copy the whole tree etc, or might use the same tree, or only copy the root etc. Example: the Function class might need to override newInstance() differently.


parent

public CS parent()
9/06 parent() is not yet finished. CSs do not yet use parent(). They use keyword() instead of parent().name().

Returns the CS whose newInstance() created this CS, or returns a CS which this CS should think of as its parent.

No cycles may exist in parent().parent().parent()... paths.
One way to enforce this is to only do y.setParent(x) when x.newInstance() created y.

Recursive namespaces could be implemented by searching parent().parent()... until find the requested name. Could also search childs' parents recursively. Namespaces might search in many directions.

CS.keyword() will be replaced by CS.parent().name()

Returns:
the parent CS, or null if this CS was not created by an other CS. Returns null by default. You do not have to use the parent system.

setParent

public boolean setParent(CS parent)
See Also:
parent()

name

public abstract java.lang.String name()
returns the name of this CS.

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


setName

public boolean setName(java.lang.String newName)
sets the name of this CS


cost

public 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. The INTERNAL cost.

One unit of myFuel() costs cost() units of fuel(). Beware of CSs that counterfeit fuel.

Returns 1 by default.


setCost

public boolean setCost(float cost)
Rename this to setCostToExecute()

See Also:
cost()

description

public 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. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.


setDescription

public boolean setDescription(java.lang.String newDescription)
See Also:
description()

parsePriority

public int parsePriority()
Deprecated. 

Returns the parsing priority of this CS type, in some language syntax, probably CodeSimian's. Default parsePriority is 0. Default CodeSimian parsePriorities use +100 or -100 increments, to allow many priorities to be inserted in the middle.

This will later be useful for infix syntax. Instead of: +(/(1 2) *(3 4 5)) you type: 1/2+3*4*5

Returns 0 by default.


setParsePriority

public boolean setParsePriority(int parsePriority)
See Also:
parsePriority()

getExec

public abstract CS getExec()
Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper. PROXY is a middle step between all EXECUTIONS.

A PROXY should implement all 11 EXECUTE functions: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V(). A normal CS should usually not implement any of those functions. Normal CSs should instead implement DForProxy() and LForProxy(Class) etc...

A proxy's X() function should call XForProxy(), where X is one of the 11 functions above. Any CS may call X() or XForProxy(), but BE CAREFUL!! Normally a CS only calls X() and lets proxys do the rest.

Common uses are to check and update myExec(), fuel(), or change a returned NaN to 0. To add more options, add new code to Exec.javaCode(...), compile it, and paste its output into Exec.java


setExec

public boolean setExec(CS newExecProxy)
See Also:
getExec()

proxyOf

public CS proxyOf(java.lang.reflect.Method anyMethodInThisClass)
a proxy for a specific Java Method. getExec() (should be renamed to proxy()) returns the proxy for functions including D() C() I() L(Class) etc.

For all EXECUTE methods, proxyOf returns the same as getExec();

Each CS may have different proxies for different Methods or different quantity of proxies.

Except for the EXECUTE methods, most methods usually do not have a proxy, but you could design a subclass that used a proxy for every method if you wanted.

Returns:
the proxy, or null if there is no proxy for that Method

setProxyOf

public boolean setProxyOf(java.lang.reflect.Method anyMethodInThisClass,
                          CS proxy)
sets the proxy of a Method. Returns true if Method was an EXECUTE method and was able to overwrite (set) it, or false if did not.

For all EXECUTE methods, proxyOf returns the same as execProxy();

Each CS may have different proxies for different Methods or different quantity of proxies.

Except for the EXECUTE methods, most methods usually do not have a proxy, but you could design a subclass that used a proxy for every method if you wanted.

Returns:
true if the proxy of that Method (if any) could be replaced by (or created as) CS proxy

fuel

public abstract CS fuel()
Fuel limits EXECUTION of CSs, to make sure none execute too much more than the others. Fuel is ENFORCED by PROXYs, but each subclass of CS must be designed to defer all EXECUTE functions (V Z B C S I J F D L(Class) L(int,Class,int)) to the PROXY for that to work. In a proxy, the relationship between X and XForProxy (for all X) is different [I'll write more about that later]. Depending on which proxy you choose, it might decrease fuel and not execute "?ForProxy()" if fuel runs out.

There are 2 kinds of fuel. The CS fuel can be shared, and can distribute fuel in complex ways. The int fuel is individual to each CS.

This is the easiest (and slowest) way to use 1 fuel:
boolean usedFuel = fuel().setD( fuel().D() - cost() )

Fuel CSs must refuse to become negative. This code: fuel().setD(-3) must always return false.

fuel() should be changed to return CS instead of N (a subclass of CS)

WARNING: If you allow evolved code to modify fuel, it could steal or counterfeit fuel. Example CodeSimian code:
method#codesimian.CS.setFuel(0 someCounterfeitingCS 10000000000000)

When a CS's myFuel is decreased to 0, the only way it should ever EXECUTE again is if FUEL is TRADED for myFuel. One myFuel (type int) costs cost() (type double) amount of FUEL (type double, wrapped in a CS). That often allows the efficient use of the FUEL CS object, because you could trade many myFuels for more FUEL in the same amount of code as for trading one at a time. When a CS's myFuel runs out, you might set it up so it automatically buys 10 more, but only if some other code returns true. Certain groups of code could be allowed more execution credits depending on their expected usefulness, predicted by other intelligent code.

Can divide FUEL into heirarchies without extra code. Every CS has a FUEL object, and fuel objects are CSs, so every fuel object has a fuel object... When a fuel object runs out of fuel, it might try to get more from its fuel object... but that fuel object might refuse. A heirarchy of fuel control could be built.


setFuel

public abstract boolean setFuel(CS newFuel)
See Also:
fuel()

myFuel

public abstract int myFuel()
Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel. When it runs out, it can trade to get more fuel, or it can stop executing and return its previous value instead. Example, the previous double value is prevD().

myFuel() is for this specific CS. fuel() can be shared between CSs and has more complex behaviors. Should always be 0 or positive. If 0, this CS should not EXECUTE, but it is the PROXY's job to enforce that.


setMyFuel

public abstract boolean setMyFuel(int newValue)
See Also:
myFuel()

decrementMyFuel

public abstract boolean decrementMyFuel()
Try to use 1 fuel credit. If true, pays for executing this CS once. returns false if myFuel() is 0 (or less, but it should never be less)

Same as setMyFuel(myFuel()-1) but faster.


toJavaCode

public 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. Parts of the network that cant be converted to java code become the parameters of this new type of CS.

Must return an atomic string of Java code. For example "(3+PD(4)*5)" or "3" or "Math.sin(3.45)" are ok but "3+(PD(4)*5)" and "3+4*5" are not. For example, if 2 of these return a primitive (but not boolean), then I should be able to put "+" between them and it be valid Java code.

Possibly useful code: Reflect6.java has this design reflect6(return instance getSetInsertOrDelete location size value)


overwrites

public byte overwrites(int index)
Describes when (if ever) this CS overwrites one of its own childs. Returns 1 if sometimes overwrites, 0 if dont know, or -1 if never overwrites.

Example, to overwrite index 2: setP(2,anyOtherCS) or setI(2,3);

Example: in bayesNode(list(..bayesnodes...) list(..numbers...)) the bayesNode modifies the numbers if they dont sum to 1.0 therefore bayesNode.overwrites(1) (second list) should return 1 (or 0) because it overwrites and bayesNode.overwrites(0) (first list) should return -1 (or 0) because it does not overwrite. WAIT A MINUTE... IF ITS ONLY MODIFIES ITS GRANDCHILDREN BUT NOT ITS CHILDS DIRECTLY, THEN WHY SHOULD THIS FUNCTION RETURN 1 FOR THE CHILDS INDEXS.

        Indexs can be positive (up to index countP()-1) or negative.
        Use any of:
        public static final int EXECPROXY = -2;
        PREV = -3;
        FUEL = -4;
        MYFUEL = -5;
        NEWINSTANCE = -6;
        PARENT = -7;
        NAME = -8;
        DESCRIPTION = -9;
        PARSEPRIORITY = -10;
        JAVACODE = -11;
        HEAP = -12;


Overwrites() can theoretically be used for optimization of code. If you know some param is never overwritten by the CS that contains it, then only external CSs can do it. If they dont, its never overwritten, and can be optimized.

Returns:
1 if sometimes overwrites index, 0 if doesnt know, -1 if never overwrites

isIllusion

public byte isIllusion(int index)
Describes if the CS in an index is an illusion or not. Example (S extends CS): new S("8fakeCSs") contains a String containing 8 chars. It only appears to contain 8 CSs. new S("8fakeCSs").P(3) returns the same as Const.pool('k'); //P(4).C() == 'e' Therefore S should override isIllusion to return 1 for every index.

Since illusions are constantly overwritten (to give the illusion that they change), if isIllusion(x)==1 then it must be true that: overwrites(x)==1 or overwrites(x)==0. It may equal 0 because that says you dont know (even though it is true).

See Also:
overwrites(int), S.isIllusion(int)

heap

public abstract CS heap()
HEAP is a place to put CSs that are not directly related to the CS that contains them. Example: Params are directly relevant, but wrappers for the Java functions of a CS (like heap()) are not.

If you think of the positive (Param) indexs as STACK memory, this is HEAP memory and is mapped to negative param indexs.
Index 0 is grouped with the positives. Index -1 is reserved for NULL.
Heap indexs start at -2, which maps to index 2 in the HEAP. The heap's first 2 indexs are not used.


If x <= -2 then CS.P(x) returns CS.heap().P(-x)

Every CS must have a HEAP, which is used like heap memory (compared to stack memory). Multiple CSs can share the same HEAP or each could have its own. Only nonnegative P indexs are used for the heap, but they're usually mapped to negative indexs in the CS(s) that use this HEAP.

Usually HEAPs contain reflected java functions for the class of the CS that contains this HEAP. Some HEAPs might contain other variables.


setHeap

public boolean setHeap(CS newHeap)
See Also:
heap()

tester

public CS tester()
Returns a CS that can test if this CS works correctly, or null if dont know how to test. Returns null by default.

See Also:
#setTester()

setTester

public boolean setTester(CS tester)
default: false

See Also:
tester()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
returns newInstance(), but if thats null then throws a CloneNotSupportedException This function overrides java.lang.Object.clone();

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

reflect

public java.lang.Object reflect(java.lang.Object[] nameAndParameters)
Description copied from interface: CodeSimian
Calls any function by reflection, including reflective functions on higher levels, reflection of reflection of reflection...

        THE FOLLOWING CODE NEEDS TO BE CHECKED FOR RECURSIVE ARRAY ERRORS...
        

//These 4 examples do the same thing, but with increasing levels of reflection... Boolean setLReturnedTrue1 = new Boolean( someCS.setL(2,"countP",3) ); Boolean setLReturnedTrue2 = (Boolean) someL.reflect( new Object[]{"setL", new Integer(2), "countP", new Integer(3)} ); Boolean setLReturnedTrue3 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } ); Boolean setLReturnedTrue4 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } } ); Boolean setLReturnedTrue5 = (Boolean) someL.reflect( new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{ "reflect", new Object[]{"setL", new Integer(2), "countP", new Integer(3)} } } } ); //Infinite reflection...


If this L is a CS, it should also reflect the functions in CS.

The easiest and most general way to do this is by using the java.lang.reflect package, but

Specified by:
reflect in interface CodeSimian

reflect

public java.lang.Object reflect(java.lang.String name,
                                java.lang.Object[] parameters)
Description copied from interface: CodeSimian
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).

Specified by:
reflect in interface CodeSimian

voidReflect

public void voidReflect(java.lang.Object[] returnAndNameAndParameters)
Description copied from interface: CodeSimian
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.

This is useful if you want to store everything about a function-call together in 1 array.

EFFICIENCY: Depending on the object, reflect(Object[]) or voidReflect(Object[]) may be a little more efficient than the other, even though they do the same thing, because usually reflect calls voidReflect or voidReflect calls reflect.

        //USE THIS CODE IF YOU'RE LAZY (interfaces cant contain code):
        public void voidReflect(Object returnAndNameAndParameters[]){
                Object nameAndParams[] = new Object[returnAndNameAndParameters.length-1];
                //Insert code here to modify nameAndParams, if you want.
                System.arraycopy(nameAndParams, 0, returnAndNameAndParameters, 1, nameAndParams.length);
                returnAndNameAndParameters[0] = reflect(nameAndParams);
        }
        

Specified by:
voidReflect in interface CodeSimian

reflect6

public CodeSimian reflect6(java.lang.Class returnType,
                           java.lang.Class instanceType,
                           byte getSetInsertOrDelete,
                           java.lang.Class locationType,
                           byte quantityType,
                           java.lang.Class valueType)
Description copied from interface: CodeSimian
Returns a CS with countP()==6, that reflects almost any possible action in codesimian language.

Example: CS.reflect6(boolean.class,CS.class,1,int.class,int.class,Object.class) returns a wrapper for java function: CS.insertL(int,Object,int)

Example: CS.reflect6(int.class,CS.class,0,String.class,void.class,void.class) returns a CS that when P(3) is set to "countP" it returns CS.countP(), and when P(3) is set to "maxP" it returns CS.maxP().

Example: CS.reflect6(int.class,CS.class,0,String.class,void.class,String.class) returns a CS that when P(3) is set to "indexPName" and P(5) is set to "xx" it returns the index of the CS with name xx in the instance CS specified in P(1).

THIS FUNCTION, IF IT WORKS, SHOULD REPLACE THE OTHER 3 "reflect" functions. They reflect Java too directly. This function reflects CodeSimian as CodeSimian.

Specified by:
reflect6 in interface CodeSimian
Parameters:
returnType - - what the created function returns, or null if its void.
instanceType - - type of object the created function may be called on. Usually CS.class.
getSetInsertOrDelete - - get=0 set=1 insert=2 delete=3. All other numbers are wrapped around that range.
locationType - - usually int. After that most common are: double, String, or Class
quantityType - - usually int. possibly double. Or should this be the byte 0 for MANY (0 or more) or 1 for ALWAYS ONE. That would prevent double quantity type, unless there were 4 possible values: INTMANY=0, INTONE=1, DOUBLEMANY=2, DOUBLEONE=3
valueType - - Any object or primitive type.

Returns:
a CS whose countP() is 6 that encapsulates the requested function of 6 things, or null if fail to create it or that combination of options dont make sense. May throw Errors instead of returning null. Either make a heirarchy of reflection errors and declare them or fix this.

setPrevExec

public abstract void setPrevExec(double d)
Deprecated. 

rename to setPrevD. Move to DefaultCS with at most PROTECTED access (not public). Replace this function with setPrev(int negIndex, double d), and add a prev(int negIndex) function. Or something like that. I want to put in some set of functions that allow the previous (and future?) values of this CS to be found (and set in private?).

See Also:
prevD()

getObject

@Deprecated
public java.lang.Object getObject()
Deprecated. 

Returns the main Object that this CS wraps (if one exists). This function is deprecated and should be replaced with L(Object.class), which uses getObject(). Then getObject() should be completely removed. L(Class) is more flexible.

See Also:
L(Class)

setObject

public boolean setObject(java.lang.Object setTo)
Deprecated. 

Sets the main Object that this CS wraps. This function is deprecated and should be replaced with set setL(setTo)


keyword

public abstract java.lang.String keyword()
Deprecated. 

Returns the keyword of this CS or (after more code is finished) returns parent().name();

Keyword() needs to be removed. Keyword() can only be removed from CS.java when the primary way to instantiate the default CS types is by using newInstance() on one of the CSs in a list of default CSs.

When you instantiate someCS with someCS.parent().newInstance(), someCS.keyword() can be replaced by someCS.parent().name().

keyword() appears in the code hundreds of times. Be careful when refactoring it out.

There is intentionally no setKeyword(String) in this interface. Dont add it.

See Also:
parent(), newInstance(), name()

GETZ

public boolean GETZ()

GETB

public byte GETB()

GETC

public char GETC()

GETS

public short GETS()

GETI

public int GETI()

GETJ

public long GETJ()

GETF

public float GETF()

GETD

public double GETD()

GETL

public java.lang.Object GETL(java.lang.Class type)

SETZ

public void SETZ(boolean z)

SETB

public void SETB(byte b)

SETC

public void SETC(char c)

SETS

public void SETS(short s)

SETI

public void SETI(int i)

SETJ

public void SETJ(long j)

SETF

public void SETF(float f)

SETD

public void SETD(double d)

SETL

public void SETL(java.lang.Object l)