|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jatha.dynatype.StandardLispValue org.jatha.compile.LispPrimitive
public abstract class LispPrimitive
The LispPrimitive class makes the transition from LISP code to Java code. There is a LispPrimitive for each builtin LISP function. 1) Create the new LISP primitive as an instance of this class. It must have several methods as described below. 2) Register the new primitive with the compiler. Each primitive must implement one method: public void Execute(SECDMachine machine)
LispCompiler
Field Summary | |
---|---|
protected String |
functionName
the functionName is part of the string that gets printed when the instruction appears in a printed list. |
protected LispValue |
functionNameSymbol
|
boolean |
inlineP
Set inlineP to true if the function effectively evaluates itself simply by compiling its argument list. |
protected long |
maxNumberOfArgs
|
protected long |
minNumberOfArgs
|
Fields inherited from class org.jatha.dynatype.StandardLispValue |
---|
f_lisp |
Constructor Summary | |
---|---|
LispPrimitive(Jatha lisp,
String fnName)
|
|
LispPrimitive(Jatha lisp,
String fnName,
long minArgs)
|
|
LispPrimitive(Jatha lisp,
String fnName,
long minArgs,
long maxArgs)
The constructor for the LispPrimitive class. |
Method Summary | |
---|---|
boolean |
basic_functionp()
Returns Java true if the object is a function. |
(package private) LispValue |
BuiltinFunctionCode(LispValue fn)
|
LispValue |
CompileArgs(LispCompiler compiler,
SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
The CompileArgs method turns the arguments of the function call into SECD abstract machine code. |
LispValue |
CompileArgs(LispCompiler compiler,
SECDMachine machine,
LispValue function,
LispValue args,
LispValue valueList,
LispValue code)
|
abstract void |
Execute(SECDMachine machine)
Execute performs the operation using the abstract machine registers. |
LispValue |
grindef(LispValue code,
int indentAmount)
|
void |
indent(int amount)
|
void |
internal_prin1(PrintStream os)
|
void |
internal_princ(PrintStream os)
|
void |
internal_print(PrintStream os)
|
String |
LispFunctionNameString()
|
LispValue |
LispFunctionNameSymbol()
|
String |
parameterCountString()
This method returns a Java string denoting the length of the expected argument list in some readable form. |
void |
printCode(LispValue code)
printCode prints a list of compiled code in a nice manner. |
void |
printCode(LispValue code,
int indentAmount)
|
String |
toString()
The output of this function is printed when the instruction needs to be printed. |
(package private) boolean |
validArgumentLength(LispValue numberOfArguments)
This method returns true if
the list of arguments satisfies the length restrictions
posed by the function, and false otherwise. |
boolean |
validArgumentList(LispValue args)
This method returns true if
the list of arguments satisfies the length and format restrictions
posed by the function, and false otherwise. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected long minNumberOfArgs
protected long maxNumberOfArgs
public boolean inlineP
LispPrimitive
protected String functionName
protected LispValue functionNameSymbol
Constructor Detail |
---|
public LispPrimitive(Jatha lisp, String fnName, long minArgs, long maxArgs)
fnName
- The LISP function name being implemented.minArgs
- The minimum number of Arguments to this function.maxArgs
- The maximum number of Arguments to this function.LispCompiler
public LispPrimitive(Jatha lisp, String fnName, long minArgs)
public LispPrimitive(Jatha lisp, String fnName)
Method Detail |
---|
public String toString()
toString
in interface LispValue
toString
in class StandardLispValue
public boolean basic_functionp()
LispValue
basic_functionp
in interface LispValue
basic_functionp
in class StandardLispValue
public void printCode(LispValue code)
printCode(compiled-function, 2);
code
- the code to be printed, with indent 2.LispPrimitive
public void printCode(LispValue code, int indentAmount)
public LispValue grindef(LispValue code, int indentAmount)
public void indent(int amount)
public String LispFunctionNameString()
public LispValue LispFunctionNameSymbol()
public void internal_princ(PrintStream os)
internal_princ
in interface LispValue
internal_princ
in class StandardLispValue
public void internal_prin1(PrintStream os)
internal_prin1
in interface LispValue
internal_prin1
in class StandardLispValue
public void internal_print(PrintStream os)
internal_print
in interface LispValue
internal_print
in class StandardLispValue
boolean validArgumentLength(LispValue numberOfArguments)
true
if
the list of arguments satisfies the length restrictions
posed by the function, and false
otherwise.
numberOfArguments
- usually the result of args.length()
LispPrimitive
public boolean validArgumentList(LispValue args)
true
if
the list of arguments satisfies the length and format restrictions
posed by the function, and false
otherwise.
It calls validArgumentLength
, so the programmer
doesn't need to call it.
This method is called by the compiler.
args
- the list of arguments.
LispPrimitive
,
LispCompiler
public String parameterCountString()
This method is called by the compiler when an argument count exception is generated.
LispPrimitive
,
LispCompiler
public abstract void Execute(SECDMachine machine) throws CompilerException
LispValueFactory
.
Example implementations:
FIRST
class FirstPrimitive extends LispPrimitive
{
public First()
{
super("FIRST", 1); // 1 argument
}
public void Execute(SECDMachine machine)
{
LispValue arg = machine.S.pop();
machine.S.push(my_first(arg));
machine.C.pop();
}
}
A multi-argument function must pop the arguments in reverse order.
public void Execute(SECDMachine machine) { LispValue arg2 = machine.S.pop(); LispValue arg1 = machine.S.pop(); machine.S.push(my_new_function(arg1, arg2)); machine.C.pop(); } }To register the new primitive, call:
Jatha.COMPILER.Register(new FirstPrimitive());
machine
- The abstract machine instance.
CompilerException
LispCompiler
LispValue BuiltinFunctionCode(LispValue fn)
public LispValue CompileArgs(LispCompiler compiler, SECDMachine machine, LispValue args, LispValue valueList, LispValue code) throws CompilerException
compiler
- args
- valueList
- code
-
CompilerException
LispCompiler
public LispValue CompileArgs(LispCompiler compiler, SECDMachine machine, LispValue function, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |