codesimian
Class DefaultCS<CSGeneric>

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS<CSGeneric>
All Implemented Interfaces:
CodeSimian
Direct Known Subclasses:
Above, AbsoluteValue, AccelerateAt, Add, AddP, AddParam, AddressShape, ArcSin, Ask, AudioBuffers.MicBufSiz, AudioBuffers.MicBufSpeed, AudioBuffers.MicCdqSiz, AudioBuffers.SoundBufSiz, AverageOf3DObjects, BayesNet, BayesNode, BayesNode.VerifyCountP, BayesNodeDependence, BayesNodePredictError, BayesNodeUpdate, Binary, ButtonCS, Chaos.NextFreeChaosInt, ChaosBit, CharIsInWhichString, CharTree.CharTreeNode, ClassObject, CodesimianOptions, ColorCS, CommandLine, CompareNumbers, Compile, CompileAndExecInnerCsFile, Const, CopyParams, CopyParamToParam, Count, DecayAve, DecayAveAndDev, DeepCopy, DefaultLetterLevelChatbot, DefaultWordLevelChatbot, Delay, DeleteParam, DieSpam, DieSpam.ButtonClicked, Distance, Divide, Do, DoNatLang, EqualP, EqualRecurse2, EvolveCode, EvolveNumbers, Exec, Exec.ChaosBit, ExecParam, FileOfShorts, Files.DefaultDownloader, Files.LoadCSFromFile, Files.SaveBytesP1IntoFileP0, Files.SaveCSToFile, Files.TextFileWriter, FileSaveBytesOptionalHumanChooseLocation, FixTypos, FloatBufferCurvesToAvoidEmpty, Function, GetCSReflectingInnerFile.DefaultCSReflecting, GetJavaCompiler, GetResource, GetSortedSubsetOfStrListByStrToBoolFuncs, GraphSeq, HardCodedCommonControls, HardCodedSelfReplicatingWindow, HumanTypesCommand, IfElse, ImageCS, IndentCode, InnerFiles, InnerFiles.DeleteInternalFile, InnerFiles.GetInnerFile, InnerFiles.GetInternalFile, InnerFiles.InnerFileExists, InnerFiles.SetInnerFile, InnerFiles.SetInternalFile, Interpolate, InterpretText, InvokeMethod, Jars.JarTest, Jars.SaveUpdatedSelf, JavaCodeForNewSubclassOfCS, JavaCompilerWindowsOpSys, JavaCompilerWindowsOpSys.DownloadAndInstall, JavaField, JavaFunctionSimple, JavaObject, JavaOutSimple, JavaType, JudgeTextByGoodAndBadExamples, Keyboard.IsKeyDown, Keyboard.KeyDown, Keyboard.KeyLocationX, Keyboard.KeyLocationY, Keyboard.KeyUp, Keyboard.TypeThisStringOnKeyboard, KeyListenerOnComponent, Layout, LearnSelfDFromSelfListD, LearnSelfDFromSelfListD.Test, List16BitSignedIntegersFromListNumbersRangePlusMinus1, ListNumbersRangePlusMinus1FromList16BitSignedIntegers, ListOfStringsGUI, Log, Logic, LongListOfStrings, Loop, Max, Median, Microphone, MicrophonePredictsBufferSize, MillisecondsSince1970, Min, Modulo, MostCommonSubstrings, MouseNumberList, MousePanel, MoveMouse, MoveMouse.MouseXPosition, MoveMouse.MouseYPosition, MP3, MP3.DefaultMP3Decoder, Multiply, N, NatLangType, NaturalLanguage.RemoveEverythingExceptLetters, Network, New, Num, Object3d, OneChatbotForEachWord, OpenSystemCommandWindow, OverlappingPages, ParamCount, Pixels2d, Pow, Predict, Primes, Primes.DoesItKnowPrimesByIndex, PrimitiveArray, Ptr, RandGaussian, RandomlyCombineCode, RandomNeuron, RandRange, RecurseP, Reflect6, ReflectedFunctions.addB, ReflectedFunctions.addC, ReflectedFunctions.addD, ReflectedFunctions.addF, ReflectedFunctions.addI, ReflectedFunctions.addJ, ReflectedFunctions.addL, ReflectedFunctions.addP, ReflectedFunctions.addPx, ReflectedFunctions.addPxx, ReflectedFunctions.addPxxx, ReflectedFunctions.addPxxxx, ReflectedFunctions.addS, ReflectedFunctions.addZ, ReflectedFunctions.B, ReflectedFunctions.BForProxy, ReflectedFunctions.C, ReflectedFunctions.CForProxy, ReflectedFunctions.clone, ReflectedFunctions.cost, ReflectedFunctions.countP, ReflectedFunctions.D, ReflectedFunctions.decrementMyFuel, ReflectedFunctions.deleteP, ReflectedFunctions.deletePx, ReflectedFunctions.description, ReflectedFunctions.DForProxy, ReflectedFunctions.equals, ReflectedFunctions.F, ReflectedFunctions.FForProxy, ReflectedFunctions.fuel, ReflectedFunctions.getClass, ReflectedFunctions.getExec, ReflectedFunctions.getObject, ReflectedFunctions.hashCode, ReflectedFunctions.heap, ReflectedFunctions.I, ReflectedFunctions.IForProxy, ReflectedFunctions.indexP, ReflectedFunctions.indexPName, ReflectedFunctions.insertB, ReflectedFunctions.insertC, ReflectedFunctions.insertD, ReflectedFunctions.insertF, ReflectedFunctions.insertI, ReflectedFunctions.insertJ, ReflectedFunctions.insertL, ReflectedFunctions.insertL1, ReflectedFunctions.insertLx, ReflectedFunctions.insertP, ReflectedFunctions.insertS, ReflectedFunctions.insertZ, ReflectedFunctions.isIllusion, ReflectedFunctions.J, ReflectedFunctions.JForProxy, ReflectedFunctions.keyword, ReflectedFunctions.L, ReflectedFunctions.LForProxy, ReflectedFunctions.LForProxyx, ReflectedFunctions.Lx, ReflectedFunctions.Lxx, ReflectedFunctions.Lxxx, ReflectedFunctions.Lxxxx, ReflectedFunctions.maxD, ReflectedFunctions.maxP, ReflectedFunctions.minD, ReflectedFunctions.minP, ReflectedFunctions.myFuel, ReflectedFunctions.name, ReflectedFunctions.newInstance, ReflectedFunctions.notify, ReflectedFunctions.notifyAll, ReflectedFunctions.overwrites, ReflectedFunctions.P, ReflectedFunctions.parent, ReflectedFunctions.parsePriority, ReflectedFunctions.PB, ReflectedFunctions.PC, ReflectedFunctions.PD, ReflectedFunctions.PF, ReflectedFunctions.PI, ReflectedFunctions.PJ, ReflectedFunctions.PL, ReflectedFunctions.prevB, ReflectedFunctions.prevC, ReflectedFunctions.prevD, ReflectedFunctions.prevF, ReflectedFunctions.prevI, ReflectedFunctions.prevJ, ReflectedFunctions.prevL, ReflectedFunctions.prevS, ReflectedFunctions.prevZ, ReflectedFunctions.proxyOf, ReflectedFunctions.PS, ReflectedFunctions.PType, ReflectedFunctions.PZ, ReflectedFunctions.reflect, ReflectedFunctions.reflect6, ReflectedFunctions.reflectx, ReflectedFunctions.S, ReflectedFunctions.setB, ReflectedFunctions.setBx, ReflectedFunctions.setC, ReflectedFunctions.setCost, ReflectedFunctions.setCx, ReflectedFunctions.setD, ReflectedFunctions.setDescription, ReflectedFunctions.setDx, ReflectedFunctions.setExec, ReflectedFunctions.setF, ReflectedFunctions.setFuel, ReflectedFunctions.setFx, ReflectedFunctions.setHeap, ReflectedFunctions.setI, ReflectedFunctions.setIx, ReflectedFunctions.setJ, ReflectedFunctions.setJx, ReflectedFunctions.setL, ReflectedFunctions.setL1, ReflectedFunctions.setLx, ReflectedFunctions.setLxx, ReflectedFunctions.setLxxx, ReflectedFunctions.setLxxxx, ReflectedFunctions.setMyFuel, ReflectedFunctions.setName, ReflectedFunctions.setObject, ReflectedFunctions.setP, ReflectedFunctions.setParent, ReflectedFunctions.setParsePriority, ReflectedFunctions.setPrevExec, ReflectedFunctions.setProxyOf, ReflectedFunctions.setPType, ReflectedFunctions.setS, ReflectedFunctions.setSx, ReflectedFunctions.setTester, ReflectedFunctions.setZ, ReflectedFunctions.setZx, ReflectedFunctions.SForProxy, ReflectedFunctions.tester, ReflectedFunctions.toJavaCode, ReflectedFunctions.toString, ReflectedFunctions.V, ReflectedFunctions.VForProxy, ReflectedFunctions.voidReflect, ReflectedFunctions.wait, ReflectedFunctions.waitx, ReflectedFunctions.waitxx, ReflectedFunctions.Z, ReflectedFunctions.ZForProxy, ReflectJavaClass, RegExpInclExcl, Reverse, RoundToInt, S, ScreenPixels, Scroll, SelfPredictingPrimeHashingNumberList, SetEqual, SetParam, Sets.UnionOfSets, SimpleBayesNet, SimpleBayesNet.BayesNodeIndependentChildsDependentParent, SimpleBayesNet.Test, SimpleFileExecutorOrEditor, SimpleList, SimpleNeuralNode, SimpleNeuralNode.ChainSimpleNeuralNodesTogether, SimpleNeuralNode.WordStringsToNodes, SimpleTextFileEditor, SimpleTextInTextOutRepeaterGUI, Sine, Slidebar, SlowMP3, SortByD, Sound, SoundQuality, SoundSyncMic, SoundSyncMic.MicrophoneSync, SpamData, SplitPane, Squares, Stacks.Peek, Stacks.Pop, Stacks.Push, Stacks.StackSize, StartCodesimian.LateInit.Hooker, Static.AddDefaultCommand, StrangeMicrophone, Strings.PrintCS, Strings.PrintNumber, Strings.PrintString, Strings.ReadChar, Strings.Similarity, Strings.StringSplit, Strings.TokenizeAllCharPairs, SubstringsOfInnerFilesWithRegExpPathNames, Subtract, TabbedPaneCS, TextAreaCS, ThisComputersScreen, Throw, TimerCS, ToJavaCode, ToStr, TradeCalcExec, TreeList, TreeOfCodeGUI, TreeType, Try, UpdatePositionBySpeed, Valid, Verify3DObject, View2d, Wait, WeightedAverage, WindowCS

public abstract class DefaultCS<CSGeneric>
extends CS<CSGeneric>

CS has no variables, but DefaultCS does. Most classes extend DefaultCS. CS is a "skeleton" that you can use to add new Java files to CodeSimian in the most flexible way, but DefaultCS is usually flexible 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, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
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()
          Execute this CS and cast to double.
 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 (if one exists).
 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, which is true for all ?ForProxy vs ? functions.
 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 or List.
 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 (need to write some more code), 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 setPType(int index, CS value)
          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 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
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultCS

public DefaultCS()
CSs created with this constructor might throw NullPointerExceptions if anything is done to these CSs before Static.pushOptions(CS) is called. StartCodesimian.init() does that.

Method Detail

V

public void V()
Overrides:
V in class CS<CSGeneric>
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.

Z

public boolean Z()
Overrides:
Z in class CS<CSGeneric>
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();

B

public byte B()
Overrides:
B in class CS<CSGeneric>
See Also:
Execute this CS and cast to byte

C

public char C()
Overrides:
C in class CS<CSGeneric>
See Also:
Execute this CS and cast to char

S

public short S()
Overrides:
S in class CS<CSGeneric>
See Also:
Execute this CS and cast to short

I

public int I()
Overrides:
I in class CS<CSGeneric>
See Also:
Execute this CS and cast to int

J

public long J()
Description copied from class: CS
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.

Overrides:
J in class CS<CSGeneric>
See Also:
CS.L(Class), java.lang.Double.doubleToLongBits(double)

F

public float F()
Overrides:
F in class CS<CSGeneric>
See Also:
Execute this CS and cast to float

DForProxy

public abstract double DForProxy()
Description copied from class: CS
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()

Specified by:
DForProxy in class CS<CSGeneric>

LForProxy

public java.lang.Object LForProxy(java.lang.Class castToThisType)
                           throws CSCastException
the default implementation can use many Class parameters. If you override but do not know what to return, return super.LForProxy(Class). All EXEC objects must override L(Class) the same way they override D(), reversed.

TODO: add ability to return List, or should I make every CS be a list?

Specified by:
LForProxy in class CS<CSGeneric>
Throws:
CSCastException
See Also:
execProxy(), setExecProxy(CS)

LForProxy

public java.lang.Object LForProxy(int startIndex,
                                  java.lang.Class castToThisType,
                                  int indexQuantity)
by default, only works if castToThisType==CS[].class or is a String or List. TODO: add more types, including all types L(Class) can use.

Specified by:
LForProxy in class CS<CSGeneric>
See Also:
CS.L(int,Class,int)

name

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

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

Specified by:
name in class CS<CSGeneric>

setName

public boolean setName(java.lang.String newName)
Description copied from class: CS
sets the name of this CS

Overrides:
setName in class CS<CSGeneric>

setD

public boolean setD(double setToThisValue)
all setX functions return setD by default. setD returns false by default. Override in subclass. For example, class N has a public variable value, and N.value is set to setToThisValue.

Specified by:
setD in class CS<CSGeneric>

setL

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

Specified by:
setL in class CS<CSGeneric>

setL1

public boolean setL1(int index,
                     java.lang.Object setToThisValue)
needs to be tested

Specified by:
setL1 in interface CodeSimian
Specified by:
setL1 in class CS<CSGeneric>

setL

public boolean setL(int startIndex,
                    java.lang.Object setToThisValue)
needs to be tested

Specified by:
setL in interface CodeSimian
Specified by:
setL in class CS<CSGeneric>
See Also:
CS.setL(int,Object,int)

setL

public boolean setL(int startIndex,
                    java.lang.Object setToThisValue,
                    int indexQuantity)
needs to be tested

Specified by:
setL in interface CodeSimian
Specified by:
setL in class CS<CSGeneric>

setP

public boolean setP(int index,
                    CS setTo)
Description copied from class: CS
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.

Specified by:
setP in class CS<CSGeneric>

myFuel

public int myFuel()
Description copied from class: CS
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.

Specified by:
myFuel in class CS<CSGeneric>

setMyFuel

public boolean setMyFuel(int newCalculateExec)
Specified by:
setMyFuel in class CS<CSGeneric>
See Also:
CS.myFuel()

description

public java.lang.String description()
Description copied from class: CS
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.

Specified by:
description in class CS<CSGeneric>

insertP

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

Specified by:
insertP in class CS<CSGeneric>

indexP

public int indexP(CS myParam)
Returns the param index of 'myParam' in this CS or -1 if it is not this CS's param. If 'myParam' is in the param list more than once, returns the highest index.

Does not search the HEAP for the specified param. Fix it...

WARNING: Uses LINEAR SEARCH. Override and make faster if your CS has more than a few params.

Overrides:
indexP in class CS<CSGeneric>

indexPName

public int indexPName(java.lang.String pName)
Returns the index of the PARAM with name pName, or -1 if nothing is found. Returns an index less than -1 if the HEAP contains it (heap() and setHeap()).

(returns int) indexPName(String) ...is the inverse of... (returns String) P(int).name().

Overrides:
indexPName in class CS<CSGeneric>
See Also:
CS.name(), CS.setName(String), CS.indexP(CS)

deleteP

public 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.

Specified by:
deleteP in class CS<CSGeneric>

fuel

public CS fuel()
need to change return type from N to CS

Specified by:
fuel in class CS<CSGeneric>

setFuel

public boolean setFuel(CS setTo)
Specified by:
setFuel in class CS<CSGeneric>
See Also:
CS.fuel()

decrementMyFuel

public 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(). Should change this to not check "myFuel == ALWAYS_CALCULATE" because the specific subclass of Exec controls if myFuel is used to limit execution.

Specified by:
decrementMyFuel in class CS<CSGeneric>

setExec

public boolean setExec(CS e)
Overrides:
setExec in class CS<CSGeneric>
See Also:
CS.getExec()

getExec

public CS getExec()
Description copied from class: CS
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

Specified by:
getExec in class CS<CSGeneric>

countP

public int countP()
Description copied from class: CS
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.

Specified by:
countP in class CS<CSGeneric>

minP

public 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.

Specified by:
minP in class CS<CSGeneric>

newInstance

public CS newInstance()
temporarily (need to write some more code), uses Class objects to instantiate the default constructor

Specified by:
newInstance in class CS<CSGeneric>

PType

public CS PType(int index)
Description copied from class: CS
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.

Specified by:
PType in class CS<CSGeneric>

setPType

public boolean setPType(int index,
                        CS value)
Description copied from class: CS
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.

Overrides:
setPType in class CS<CSGeneric>

P

public 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().

Specified by:
P in class CS<CSGeneric>
Parameters:
index - range 0 (or neg?) to countP()-1 inclusive
See Also:
CS.heap()

heap

public CS heap()
returns 'this' by default. Should change that to return some external CS but share it between CSs to avoid using double the memory. 9/06 HEAP should become a virtual variable, only accessed by L("heap") and setL("heap",someObject) etc. Many other functions should be removed and only accessed that way also.

Specified by:
heap in class CS<CSGeneric>

insertL1

public boolean insertL1(int index,
                        java.lang.Object setToThisValue)
Description copied from class: CS
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
Specified by:
insertL1 in class CS<CSGeneric>

insertL

public boolean insertL(int startIndex,
                       java.lang.Object insertMe)
Description copied from class: CS
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
Specified by:
insertL in class CS<CSGeneric>
See Also:
CS.insertL(int,Object,int)

insertL

public boolean insertL(int startIndex,
                       java.lang.Object insertMe,
                       int indexQuantity)
Description copied from class: CS
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.

Specified by:
insertL in class CS<CSGeneric>

prevL

public java.lang.Object prevL()
Description copied from class: CS
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.

Specified by:
prevL in class CS<CSGeneric>

prevD

public double prevD()
previous value of D(). This function is set by setPrevExec(double) which should be renamed to setPrevD(double)

Specified by:
prevD in class CS<CSGeneric>

setZ

public boolean setZ(int paramIndex,
                    boolean value)
Overrides:
setZ in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setB

public boolean setB(int paramIndex,
                    byte value)
Overrides:
setB in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setC

public boolean setC(int paramIndex,
                    char value)
Overrides:
setC in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setS

public boolean setS(int paramIndex,
                    short value)
Overrides:
setS in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setI

public boolean setI(int paramIndex,
                    int value)
Overrides:
setI in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setJ

public boolean setJ(int paramIndex,
                    long value)
Overrides:
setJ in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setF

public boolean setF(int paramIndex,
                    float value)
Overrides:
setF in class CS<CSGeneric>
See Also:
CS.setD(int,double)

setD

public boolean setD(int paramIndex,
                    double value)
Description copied from class: CS
sets a param to a double value. Same as P(paramIndex).setD(value)

Specified by:
setD in class CS<CSGeneric>

insertZ

public boolean insertZ(int paramIndex,
                       boolean value)
Overrides:
insertZ in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertB

public boolean insertB(int paramIndex,
                       byte value)
Overrides:
insertB in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertC

public boolean insertC(int paramIndex,
                       char value)
Overrides:
insertC in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertS

public boolean insertS(int paramIndex,
                       short value)
Overrides:
insertS in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertI

public boolean insertI(int paramIndex,
                       int value)
Overrides:
insertI in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertJ

public boolean insertJ(int paramIndex,
                       long value)
Overrides:
insertJ in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertF

public boolean insertF(int paramIndex,
                       float value)
Overrides:
insertF in class CS<CSGeneric>
See Also:
CS.insertD(int,double)

insertD

public boolean insertD(int paramIndex,
                       double value)
Description copied from class: CS
inserts a double as a param at a specific index. Same as insertP(paramIndex,new N(value))

Specified by:
insertD in class CS<CSGeneric>

toString

public java.lang.String toString()
problem: toString() does not return the same as L(String.class). toString returns code and L returns params as char values. Maybe only decompile() should be used for code instead.

Overrides:
toString in class java.lang.Object

javaCode

public 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.

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


setCountP

protected void setCountP(int newParamQuantity)

objectToCSArray

protected CS[] objectToCSArray(java.lang.Object o)
The default way to interpret an Object as a sequence of CSs.

All arrays are also Objects. This is mostly used for primitive-arrays, but its also useful for classes like String which is a sequence of char values.

Used in the default implementations of insertL and setL.

Returns null if doesnt know how to convert the Object to a CS[] array.

Currently does not work with Objects that are MULTI-DIMENSIONAL ARRAYS. One dimension or single Object.

If you have a more efficient way to set or insert certain param ranges without first converting to CS[] array, override insertL and/or setL to do that (else return super).


objectToCSArray

protected CS[] objectToCSArray(java.lang.Object o,
                               int arraySize)
Like objectToCSArray(Object) but requires the array be a certain size. If cant convert it to CS[] array, returns null.

By default, calls simply calls objectToCSArray(Object) and cuts off the end of the array if its too big and wraps around if its too small.


objectToCS

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. Like objectToCSArray(Object) and objectToCSArray(Object,int) except only returns 1 CS. Returns null if cant convert to CS.


start

protected void start()
called by the default CS constructor (which has no parameters). Sets the options of this new CS, including root and addressShape.

start() might be moved into the default constructor, and a new constructor created that does nothing (for if subclass not want to call start).


setPrevExec

public void setPrevExec(double p)
Description copied from class: CS
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?).

Specified by:
setPrevExec in class CS<CSGeneric>
See Also:
CS.prevD()

getObject

public java.lang.Object getObject()
Description copied from class: CS
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.

Overrides:
getObject in class CS<CSGeneric>
See Also:
anyObject

setObject

public boolean setObject(java.lang.Object setTo)
Description copied from class: CS
Sets the main Object that this CS wraps. This function is deprecated and should be replaced with set setL(setTo)

Overrides:
setObject in class CS<CSGeneric>
See Also:
anyObject

keyword

public 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()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

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

Specified by:
keyword in class CS<CSGeneric>
See Also:
CS.parent(), CS.newInstance(), CS.name()