codesimian
Class Compile

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.Compile
All Implemented Interfaces:
CodeSimian
Direct Known Subclasses:
Compile.CompileDefaultCommand, Compile.CompileLiteral, Compile.CompilerPipeline, Compile.FirstCompilerThatWorks, Compile.ParseObjects, Compile.ParseObjectsByPriority, Compile.SimpleCompiler, Compile.TokenizeCode, Compile.TokensToObjects

public abstract class Compile
extends DefaultCS

NEED TO MODIFY COMPILER SO THAT A STRING LITERAL CAN BE A NAME, LIKE THIS: if#"the if"(ask("repeat this question?") "the if")

IT WOULD BE MORE POWERFUL IF THE STRING LITERAL NAME COULD BE A REGULAR EXPRESSION AUTOMATICALLY IF IT CONTAINS CERTAIN CHARACTERS NORMALLY FOUND IN REGULAR EXPRESSIONS, LIKE THIS: if#"(the if)* and this are part of the name"(slidebar the if the if and this too are part of the name) BUT ITS PROBABLY BETTER TO MERGE CODESIMIAN WITH A JAVA VERSION OF PERL THAN TO IMPLEMENT THAT.

Contains inner subclasses for compiling CodeSimian language.

There can be many types of COMPILERs, but they all share this...

% 2 <= minP()
% param0's param(s) are the compiled output. 1 <= param0.countP().
% param1's param(s) are the input objects. They can be interpreted as their literal char values (in a string of code), a sequence of CS objects, or anything you want.
% DForProxy() returns a positive value if compiled ok, else a negative value or 0.
% if DForProxy() returns 0 or negative, param0 is interpreted as a string error message (or other type of CS describing an error).

Multiple COMPILERS at once are usually executed as a pipeline - the output of one is the input to the next. It could be a lexer followed by a parser, but the standard CodeSimian compiler uses 3 compilers: TokenizeCode, TokensToObjects, and ParseObjects. You dont have to use that simple default compiler. Example: You could make a very complex compiler that takes other compilers as input and outputs new compilers.

This is a SimpleCompiler as CodeSimian code:
compilerPipeline( 0 '+(2 3)' tokenizeCode(0 0) tokensToObjects(0 0) parseObjects(0 0) )
...becomes...
compilerPipeline(
     +(2 3)
     '+(2 3)'
     tokenizeCode( list('+' '(' '2' '3' ')') '+(2 3)' )
     tokensToObjects( list(+ LPARAN 2 3 RPARAN) list('+' '(' '2' '3' ')') )
     parseObjects( +(2 3) list(+ LPARAN 2 3 RPARAN) )
)


Nested Class Summary
static class Compile.CompileDefaultCommand
          wraps CSFactory.
static class Compile.CompileLiteral
          for example, input "-2.4" into P(1) and it outputs new N(-2.4) into P(0).
static class Compile.CompilerPipeline
          A pipeline/sequence of COMPILERs.
static class Compile.FirstCompilerThatWorks
          Contains compilers at index 2 and above.
static class Compile.LParenSymbol
           
static class Compile.MyFuelSymbol
           
static class Compile.NameSymbol
           
static class Compile.ParseObjects
          Converts a sequence
(that often has duplicate objects)
of CS objects
(that probably do not have enough params)
to a tree or graph-shape of CS objects,
where each CS object has a valid quantity of params,
assuming your parenthesis (example: Compile.LPAREN) allow that.
static class Compile.ParseObjectsByPriority
          Infix-syntax for CodeSimian language.
static class Compile.RParenSymbol
           
static class Compile.SimpleCompiler
          wrapper-class for a standard CompilerPipeline made of 3 smaller compilers
static class Compile.SmallSymbol
          a symbol that uses very little memory and has only 1 variable (a byte) specifying how many semicolons that precede the symbol.
static class Compile.Symbol
          Deprecated.  
static class Compile.TokenizeCode
           Converts a STRING of CodeSimian code to a list of STRINGs - tokens of code.
static class Compile.TokensToObjects
          Converts a sequence of string tokens to a sequence of CS objects with no params.
static class Compile.WhitespaceSymbol
           
 
Field Summary
static CS LPAREN
          4/06 OBSOLETE JAVADOC, BUT STILL A LITTLE USEFUL...
LPAREN and RPAREN should be part of output of Lex and part of input to Parse if you use paranthesis.
static CS MYFUEL
          Deprecated. $MYFUEL should be removed from CodeSimian syntax.
static CS NAME
          the string symbol preceding a name declaration.
static CS RPAREN
           
static CS TEMPORARY_PARAM
          Put Compile.TEMPORARY_PARAM in the params of newly instantiated CSs so they do not have an error caused by calling functions while countP() < minP().
static CS WHITESPACE
          a TOKEN representing spaces, tabs, and possibly newlines.
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Constructor Summary
Compile()
           
 
Method Summary
 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.
 java.lang.Class javaCompile(java.lang.String javaCodeFor1Class)
          compiles java code and returns the Class it compiles.
static byte[] javaCompileSelf()
           
static void javaCompileSelfSaveJar(java.lang.String pathNameOfJar)
           
static byte[] javaCompileZipBytes(byte[] jarOrZipFileBytes)
          Input bytes of ZIP file, to be compiled.
 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.
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, description, DForProxy, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, keyword, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setP, setPrevExec, setPType, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, 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
 

Field Detail

LPAREN

public static final CS LPAREN
4/06 OBSOLETE JAVADOC, BUT STILL A LITTLE USEFUL...
LPAREN and RPAREN should be part of output of Lex and part of input to Parse if you use paranthesis.

You can add your own tokens and syntax rules if you make your own lexer and parser, and they do not have to be subclasses of Compile, Compile.Lex, or Compile.Parse.

You only need static variables like this for parts of the language that do not directly translate to a CS. The Sin class does not need one because its name is included in "sine(1.57)". Class names or keyword()s are automatically found in the text.

Address of var = second parameter, is not important. Important: what the VarName.DForProxy()s return.

See Also:
RPAREN

RPAREN

public static final CS RPAREN
See Also:
LPAREN

NAME

public static final CS NAME
the string symbol preceding a name declaration. Example: "#" in "+#sumsTo9(2 3 4)".


MYFUEL

public static final CS MYFUEL
Deprecated. $MYFUEL should be removed from CodeSimian syntax.
a TOKEN preceding an integer specifying the myFuel() for some CS being compiled,
like +#fifteen$5(3 fifteen) which becomes +#fifteen$0(3 fifteen) after increasing its value to 15 by 3s.
Or it could be simpler: ask$3("I refuse to ask this more than 3 times" OK)


WHITESPACE

public static final CS WHITESPACE
a TOKEN representing spaces, tabs, and possibly newlines. Often ignored or not used.


TEMPORARY_PARAM

public static final CS TEMPORARY_PARAM
Put Compile.TEMPORARY_PARAM in the params of newly instantiated CSs so they do not have an error caused by calling functions while countP() < minP(). Later, go through all the new CS instances and replace all the CS.TEMPORARY_PARAM's.

This is the only instance of a private inner class in Compile...
The Compile.TEMPORARY_PARAM class was first created to solve a problem where some CS's setP(int index, CS setTo) executed setTo (because its params are the char values in a string), but setTo was instantiated after its parent, and its parent doesnt have enough (CS) params yet, so the child will have the same problem.

See Also:
TEMPORARY_PARAM
Constructor Detail

Compile

public Compile()
Method Detail

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

cost

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

Overrides:
cost in class CS

javaCompileZipBytes

public static byte[] javaCompileZipBytes(byte[] jarOrZipFileBytes)
Input bytes of ZIP file, to be compiled. Output bytes of executable JAR file (all JAR files are ZIP files).

Compiles the .java files inside a ZIP file and outputs a JAR file containing all files in the ZIP plus many .class files generated from the .java files in the ZIP. It compiles a ZIP (or JAR, which is a ZIP) and outputs a complete Java program as a JAR.

nhj WARNING: some implementations may use the local filesystem or other unreliable things. Applets usually can not use the local filesystem.


javaCompileSelf

public static byte[] javaCompileSelf()

javaCompileSelfSaveJar

public static void javaCompileSelfSaveJar(java.lang.String pathNameOfJar)

javaCompile

public java.lang.Class javaCompile(java.lang.String javaCodeFor1Class)
                            throws java.lang.Throwable
compiles java code and returns the Class it compiles. It may contain any number of static inner classes. Automaticly-generated java code is often written as many inner classes inside 1 file to keep the number of files down.

If it doesnt compile right, throws a Throwable.

Throws:
java.lang.Throwable