|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcodesimian.CS
codesimian.DefaultCS
public abstract class DefaultCS
CS has no variables, but DefaultCS does. DefaultCS is the main subclass of CS.
Most classes extend DefaultCS. DefaultCS adds more complex behaviors than CS.
CS is a "skeleton" that you can use to add new Java files to CodeSimian in the most flexible way,
but for most uses, DefaultCS should be enough.
There is 1 major inconsistency between CS and DefaultCS that needs to be fixed ASAP:
The EXECUTE functions (B() C() etc) all defer to D() in DefaultCS, then D defers to PROXY.
But CS (this is the way it should be but it doesnt work)
defers to the PROXY immediately from all EXECUTE functions.
However no CS EXECUTE functions remain after DefaultCS overrides.
Deferring immediately, causes infinite loops. Fix it...
(Exec.java needs to be modified to have all EXECUTE functions!)
Stop implementing Serializable in DefaultCS?... and only implement it in subclasses that are sure they can be serialized? If a subclass was sure it can not be serialized then DefaultCS would force it to claim its Serializable and when it tries to be serialized, an ERROR will occur. So dont force them.
To fix this, they can override private void writeObject(ObjectOutputStream) to THROW A NotSerializableException, which fools most parts of Java to think it doesnt implement Serializable, but some programs check to see if Serializable is an interface of the class and throwing a NotSerializableException wont fix that. The program will assume it is serializable because it implements the interface.
| Field Summary |
|---|
| Fields inherited from class codesimian.CS |
|---|
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER |
| Constructor Summary | |
|---|---|
DefaultCS()
CSs created with this constructor might throw NullPointerExceptions if anything is done to these CSs before Static.pushOptions(CS) is called. |
|
| Method Summary | |
|---|---|
byte |
B()
|
char |
C()
|
int |
countP()
Quantity of params. |
boolean |
decrementMyFuel()
Returns true if this CS has permission to execute, and consumes 1 exec permission. If myFuel is at least 1, decrements it and returns true. Or if myFuel == ALWAYS_CALCULATE, returns true but does not decrement. Else returns false. Does not call DForProxy(). |
boolean |
deleteP(int paramNumber)
WARNING: if returns false, could have deleted but not moved other params down 1 index. WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false. |
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()
D() and DForProxy() are the 2 most important functions in CS. |
float |
F()
|
CS |
fuel()
need to change return type from N to CS |
CS |
getExec()
Every CS must have an EXECPROXY (also called PROXY), even if its a trivial wrapper. |
java.lang.Object |
getObject()
Returns the main Object that this CS wraps. |
CS |
heap()
returns 'this' by default. |
int |
I()
|
int |
indexP(CS myParam)
Returns the param index of 'myParam' in this CS or -1 if it is not this CS's param. |
int |
indexPName(java.lang.String pName)
Returns the index of the PARAM with name pName, or -1 if nothing is found. |
boolean |
insertB(int paramIndex,
byte value)
|
boolean |
insertC(int paramIndex,
char value)
|
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)
|
boolean |
insertL(int startIndex,
java.lang.Object insertMe)
Inserts an Object into MULTIPLE param indexs. |
boolean |
insertL(int startIndex,
java.lang.Object insertMe,
int indexQuantity)
Inserts an Object into a specific subset of param indexs. |
boolean |
insertL1(int index,
java.lang.Object setToThisValue)
inserts an Object into 1 param index. |
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)
|
long |
J()
Execute this CS and cast to long. Most subclasses should override JForProxy() instead of J(), or neither. 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, accuracy is less than integer precision. |
java.lang.String |
javaCode(CS listOfCodeAlreadyTraversed)
This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs. |
java.lang.String |
keyword()
For the CodeSimian language as a String. CodeSimian language keyword, like "+" "*" "max" ">" etc. Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add. Some CSs might never be intended to be used in the language by their keyword. The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()". |
java.lang.Object |
LForProxy(java.lang.Class castToThisType)
the default implementation can use many Class parameters. |
java.lang.Object |
LForProxy(int startIndex,
java.lang.Class castToThisType,
int indexQuantity)
by default, only works if castToThisType==CS[].class or is a String |
int |
minP()
For DForProxy(). Minimum number of parameters in param[] needed to call DForProxy(). Defines which indexs of param[] DForProxy() can use. Functions with a different number of parameters must override this. OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS. Default is 1. |
int |
myFuel()
Returns how many times this CS may EXECUTE before it needs to trade some CS fuel for int fuel. |
java.lang.String |
name()
returns the name of this CS. |
CS |
newInstance()
temporarily, uses Class objects to instantiate the default constructor. |
protected CS |
objectToCS(java.lang.Object o)
Tries to convert an Object to a CS, to be used by insertL1(Object,int) or setL1(Object,int) etc. |
protected CS[] |
objectToCSArray(java.lang.Object o)
The default way to interpret an Object as a sequence of CSs. |
protected CS[] |
objectToCSArray(java.lang.Object o,
int arraySize)
Like objectToCSArray(Object) but requires the array be a certain size. |
CS |
P(int index)
WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP(). |
double |
prevD()
previous value of D(). |
java.lang.Object |
prevL()
returns the previous execute value as an Object. |
CS |
PType(int index)
There is a TYPE for each Param. A TYPE is a CS whose minP() is at least 1. |
short |
S()
|
boolean |
setB(int paramIndex,
byte value)
|
boolean |
setC(int paramIndex,
char value)
|
protected void |
setCountP(int newParamQuantity)
|
boolean |
setD(double setToThisValue)
all setX functions return setD by default. |
boolean |
setD(int paramIndex,
double value)
sets a param to a double value. |
boolean |
setExec(CS e)
|
boolean |
setF(int paramIndex,
float value)
|
boolean |
setFuel(CS setTo)
|
boolean |
setI(int paramIndex,
int value)
|
boolean |
setJ(int paramIndex,
long value)
|
boolean |
setL(int startIndex,
java.lang.Object setToThisValue)
needs to be tested |
boolean |
setL(int startIndex,
java.lang.Object setToThisValue,
int indexQuantity)
needs to be tested |
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. |
boolean |
setL1(int index,
java.lang.Object setToThisValue)
needs to be tested |
boolean |
setMyFuel(int newCalculateExec)
|
boolean |
setName(java.lang.String newName)
sets the name of this CS |
boolean |
setObject(java.lang.Object setTo)
Sets the main Object that this CS wraps. |
boolean |
setP(int index,
CS setTo)
Every CS is a list of other CSs, between size minP() and maxP() inclusive. |
void |
setPrevExec(double p)
rename to setPrevD. |
boolean |
setS(int paramIndex,
short value)
|
boolean |
setZ(int paramIndex,
boolean value)
|
protected void |
start()
called by the default CS constructor (which has no parameters). |
java.lang.String |
toString()
problem: toString() does not return the same as L(String.class). |
void |
V()
|
boolean |
Z()
|
| Methods inherited from class codesimian.CS |
|---|
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultCS()
| Method Detail |
|---|
public void V()
V in class CSExecute this CS. Do not return anything. V = Void.
Some CSs have side-effects, so void is not useless.public boolean Z()
Z in class CSexecute 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.java.lang.Class.name() uses Z for boolean.
All the functions that execute a CS have names equal to one of java.lang.java.lang.Class.name();\public byte B()
B in class CSExecute this CS and cast to bytepublic char C()
C in class CSExecute this CS and cast to charpublic short S()
S in class CSExecute this CS and cast to shortpublic int I()
I in class CSExecute this CS and cast to intpublic long J()
CS
J in class CSCS.L(Class),
java.lang.Double.doubleToLongBits(double)public float F()
F in class CSExecute this CS and cast to floatpublic abstract double DForProxy()
CS
DForProxy in class CS
public java.lang.Object LForProxy(java.lang.Class castToThisType)
throws CSCastException
LForProxy in class CSCSCastExceptionexecProxy(),
setExecProxy(CS)
public java.lang.Object LForProxy(int startIndex,
java.lang.Class castToThisType,
int indexQuantity)
LForProxy in class CSCS.L(int,Class,int)public java.lang.String name()
CS
name in class CSpublic boolean setName(java.lang.String newName)
CS
setName in class CSpublic boolean setD(double setToThisValue)
setD in class CSpublic boolean setL(java.lang.Object setToThisValue)
CS
setL in class CS
public boolean setL1(int index,
java.lang.Object setToThisValue)
setL1 in interface CodeSimiansetL1 in class CS
public boolean setL(int startIndex,
java.lang.Object setToThisValue)
setL in interface CodeSimiansetL in class CSCS.setL(int,Object,int)
public boolean setL(int startIndex,
java.lang.Object setToThisValue,
int indexQuantity)
setL in interface CodeSimiansetL in class CS
public boolean setP(int index,
CS setTo)
CS
setP in class CSpublic int myFuel()
CS
myFuel in class CSpublic boolean setMyFuel(int newCalculateExec)
setMyFuel in class CSCS.myFuel()public java.lang.String description()
CS
description in class CS
public boolean insertP(int index,
CS insertMe)
CS
insertP in class CSpublic int indexP(CS myParam)
indexP in class CSpublic int indexPName(java.lang.String pName)
indexPName in class CSCS.name(),
CS.setName(String),
CS.indexP(CS)public boolean deleteP(int paramNumber)
deleteP in class CSpublic CS fuel()
fuel in class CSpublic boolean setFuel(CS setTo)
setFuel in class CSCS.fuel()public boolean decrementMyFuel()
decrementMyFuel in class CSpublic boolean setExec(CS e)
setExec in class CSCS.getExec()public CS getExec()
CS
getExec in class CSpublic int countP()
CS
countP in class CSpublic int minP()
minP in class CSpublic CS newInstance()
newInstance in class CSpublic CS PType(int index)
CS
PType in class CSpublic CS P(int index)
P in class CSindex - range 0 to countP()-1 inclusiveCS.heap()public CS heap()
heap in class CS
public boolean insertL1(int index,
java.lang.Object setToThisValue)
CS
insertL1 in interface CodeSimianinsertL1 in class CS
public boolean insertL(int startIndex,
java.lang.Object insertMe)
CS
insertL in interface CodeSimianinsertL in class CSCS.insertL(int,Object,int)
public boolean insertL(int startIndex,
java.lang.Object insertMe,
int indexQuantity)
CS
insertL in class CSpublic java.lang.Object prevL()
CS
prevL in class CSpublic double prevD()
prevD in class CS
public boolean setZ(int paramIndex,
boolean value)
setZ in class CSCS.setD(int,double)
public boolean setB(int paramIndex,
byte value)
setB in class CSCS.setD(int,double)
public boolean setC(int paramIndex,
char value)
setC in class CSCS.setD(int,double)
public boolean setS(int paramIndex,
short value)
setS in class CSCS.setD(int,double)
public boolean setI(int paramIndex,
int value)
setI in class CSCS.setD(int,double)
public boolean setJ(int paramIndex,
long value)
setJ in class CSCS.setD(int,double)
public boolean setF(int paramIndex,
float value)
setF in class CSCS.setD(int,double)
public boolean setD(int paramIndex,
double value)
CS
setD in class CS
public boolean insertZ(int paramIndex,
boolean value)
insertZ in class CSCS.insertD(int,double)
public boolean insertB(int paramIndex,
byte value)
insertB in class CSCS.insertD(int,double)
public boolean insertC(int paramIndex,
char value)
insertC in class CSCS.insertD(int,double)
public boolean insertS(int paramIndex,
short value)
insertS in class CSCS.insertD(int,double)
public boolean insertI(int paramIndex,
int value)
insertI in class CSCS.insertD(int,double)
public boolean insertJ(int paramIndex,
long value)
insertJ in class CSCS.insertD(int,double)
public boolean insertF(int paramIndex,
float value)
insertF in class CSCS.insertD(int,double)
public boolean insertD(int paramIndex,
double value)
CS
insertD in class CSpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
javaCode in class CSprotected void setCountP(int newParamQuantity)
protected CS[] objectToCSArray(java.lang.Object o)
protected CS[] objectToCSArray(java.lang.Object o,
int arraySize)
protected CS objectToCS(java.lang.Object o)
protected void start()
public void setPrevExec(double p)
CS
setPrevExec in class CSCS.prevD()public java.lang.Object getObject()
CS
getObject in class CSanyObjectpublic boolean setObject(java.lang.Object setTo)
CS
setObject in class CSanyObjectpublic java.lang.String keyword()
keyword in class CSCS.parent(),
CS.newInstance(),
CS.name()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||