|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jatha.compile.LispCompiler
public class LispCompiler
LispCompiler has a compile() method that will compile a LISP expression and return the SECD code for that expression. Example LISP read/eval/print loop:
expr = parser.read(stream); code = compiler.compile(expr); result = machine.eval(code); result.print();
Macro compilation contributed by Jean-Pierre Gaillardon, April 2005
SECDMachine
,
SECDop
Field Summary | |
---|---|
(package private) LispValue |
AMP_REST
|
(package private) LispValue |
AND
|
(package private) static boolean |
DEBUG
|
(package private) LispValue |
DEFMACRO
|
(package private) LispValue |
DEFUN
|
(package private) LispValue |
DUMMY_FUNCTION
|
(package private) LispValue |
DUMMY_MACRO
|
private Jatha |
f_lisp
|
(package private) LispValue |
IF
|
(package private) LispValue |
LAMBDA
|
private Stack |
legalBlocks
|
private Stack |
legalTags
|
(package private) LispValue |
LET
|
(package private) LispValue |
LETREC
|
(package private) LispValue |
MACRO
|
(package private) LispValue |
OR
|
(package private) LispValue |
PRIMITIVE
|
(package private) LispValue |
PROGN
|
(package private) LispValue |
QUOTE
|
private Map |
registeredDos
|
(package private) LispValue |
SETQ
|
(package private) boolean |
WarnAboutSpecialsP
|
Constructor Summary | |
---|---|
LispCompiler(Jatha lisp)
|
Method Summary | |
---|---|
LispValue |
compile(LispValue expr,
LispValue valueList,
LispValue code)
compile takes a LISP expression, a list of global variables, and optionally an already-generated list of code. |
LispValue |
compile(SECDMachine machine,
LispValue expr,
LispValue varValues)
compile takes a LISP expression, a list of global variables, and optionally an already-generated list of code. |
(package private) LispValue |
compileAnd(SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileAndAux(LispValue dummyVar,
LispValue args)
|
(package private) LispValue |
compileApp(SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileAppConstant(SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
|
LispValue |
compileArgsLeftToRight(LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileAtom(SECDMachine machine,
LispValue expr,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileBuiltin(SECDMachine machine,
LispValue fn,
LispValue args,
LispValue valueList,
LispValue code)
|
LispValue |
compileConstantArgsLeftToRight(SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileDefmacro(SECDMachine machine,
LispValue name,
LispValue argsAndBody,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileDefun(SECDMachine machine,
LispValue name,
LispValue argsAndBody,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileIf(SECDMachine machine,
LispValue test,
LispValue thenExpr,
LispValue elseExpr,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileLambda(SECDMachine machine,
LispValue body,
LispValue valueList,
LispValue code)
|
LispValue |
compileLet(SECDMachine machine,
LispValue vars,
LispValue values,
LispValue valueList,
LispValue body,
LispValue code)
|
(package private) LispValue |
compileList(SECDMachine machine,
LispValue expr,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileOptimizedIf(SECDMachine machine,
LispValue test,
LispValue thenExpr,
LispValue elseExpr,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileOr(SECDMachine machine,
LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileOrAux(LispValue dummyVar,
LispValue args)
|
(package private) LispValue |
compileProgn(LispValue body,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileSpecialBind(SECDMachine machine,
LispValue vars,
LispValue values,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileSpecialForm(SECDMachine machine,
LispValue function,
LispValue args,
LispValue valueList,
LispValue code)
|
(package private) LispValue |
compileSpecialUnbind(SECDMachine machine,
LispValue vars,
LispValue code)
|
(package private) LispValue |
compileUserDefinedFunction(SECDMachine machine,
LispValue fn,
LispValue args,
LispValue valueList,
LispValue code)
FN is an instance of StandardLispFunction |
Stack |
getLegalBlocks()
|
Stack |
getLegalTags()
|
Map |
getRegisteredDos()
|
LispValue |
indexAndAttribute(LispValue e,
LispValue l)
Looks up the symbol in a list of lists. |
int |
indexInList(LispValue e,
LispValue l,
LispValue[] attribute)
Looks up the symbol in a list |
void |
init()
Initializes the compiler by registering the LISP primitive functions so that the compiler can recognize them. |
private void |
initializeConstants()
|
static boolean |
isBuiltinFunction(LispValue code)
Send in either code or a symbol with a function value. |
boolean |
isLegalTag(LispValue tag)
|
boolean |
isMacroCode(LispValue code)
|
LispValue |
quoteList(LispValue l)
Returns the input list with quotes added before every top-level expression. |
void |
Register(LispPrimitive primitive)
Use this function to register any new LISP primitives that you create from Java code. |
void |
Register(LispPrimitive primitive,
LispPackage pkg)
Use this function to register any new LISP primitives that you create from Java code. |
void |
Register(LispPrimitive primitive,
String pkgName)
Use this function to register any new LISP primitives that you create from Java code. |
boolean |
specialFormP(LispValue fn)
|
LispValue |
valuesFromLetBindings(LispValue varValueList)
|
LispValue |
varsFromLetBindings(LispValue varValueList)
|
void |
WarnAboutSpecials(boolean value)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static boolean DEBUG
LispValue AND
LispValue DEFMACRO
LispValue DEFUN
LispValue IF
LispValue LAMBDA
LispValue LET
LispValue LETREC
LispValue OR
LispValue PRIMITIVE
LispValue PROGN
LispValue QUOTE
LispValue SETQ
LispValue AMP_REST
LispValue MACRO
LispValue DUMMY_FUNCTION
LispValue DUMMY_MACRO
boolean WarnAboutSpecialsP
private Jatha f_lisp
private final Stack legalBlocks
private final Stack legalTags
private final Map registeredDos
Constructor Detail |
---|
public LispCompiler(Jatha lisp)
Method Detail |
---|
private void initializeConstants()
public void init()
LispCompiler
public void Register(LispPrimitive primitive)
compiler.Register(new RevAppendPrimitive());
primitive
- LispPrimitive
public void Register(LispPrimitive primitive, LispPackage pkg)
compiler.Register(new RevAppendPrimitive());
primitive
- LispPrimitive
public void Register(LispPrimitive primitive, String pkgName)
compiler.Register(new RevAppendPrimitive());
primitive
- LispPrimitive
public Stack getLegalBlocks()
public Stack getLegalTags()
public Map getRegisteredDos()
public boolean isLegalTag(LispValue tag)
public void WarnAboutSpecials(boolean value)
public int indexInList(LispValue e, LispValue l, LispValue[] attribute)
e
- a Symboll
- a listattribute
- The attribute of the found symbol is assigned to attribute[0]. It can be NIL or &rest
public LispValue indexAndAttribute(LispValue e, LispValue l)
indexAndAttribute(b, ((a b c) (d e f)) = (NIL. (1 . 2)) indexAndAttribute(f, ((a b c) (d e f)) = (NIL.(2 . 3)) indexAndAttribute(z, ((a b c) (d e f)) = (NIL. NIL) indexAndAttribute(l, ((a &rest l) (d e f)) = (&rest .(1 . 2))
e
- a Symboll
- a list of lists
public LispValue compileArgsLeftToRight(LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
public LispValue compileConstantArgsLeftToRight(SECDMachine machine, LispValue args, LispValue valueList, LispValue code)
public LispValue quoteList(LispValue l)
public LispValue compile(SECDMachine machine, LispValue expr, LispValue varValues) throws CompilerException
expr
- expression to compilevarValues
- global or local variable list.
CompilerException
LispCompiler
public LispValue compile(LispValue expr, LispValue valueList, LispValue code) throws CompilerException
expr
- expression to compilevalueList
- global variable list.code
- [optional]
CompilerException
LispCompiler
LispValue compileAtom(SECDMachine machine, LispValue expr, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileList(SECDMachine machine, LispValue expr, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileSpecialForm(SECDMachine machine, LispValue function, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
public LispValue compileLet(SECDMachine machine, LispValue vars, LispValue values, LispValue valueList, LispValue body, LispValue code) throws CompilerException
CompilerException
LispValue compileSpecialBind(SECDMachine machine, LispValue vars, LispValue values, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileSpecialUnbind(SECDMachine machine, LispValue vars, LispValue code)
public LispValue varsFromLetBindings(LispValue varValueList)
public LispValue valuesFromLetBindings(LispValue varValueList)
public boolean specialFormP(LispValue fn)
LispValue compileApp(SECDMachine machine, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileAppConstant(SECDMachine machine, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileBuiltin(SECDMachine machine, LispValue fn, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileUserDefinedFunction(SECDMachine machine, LispValue fn, LispValue args, LispValue valueList, LispValue code) throws CompilerException
machine
- fn
- an instance of StandardLispFunctionargs
- valueList
- code
-
CompilerException
LispValue compileAnd(SECDMachine machine, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileAndAux(LispValue dummyVar, LispValue args)
LispValue compileOr(SECDMachine machine, LispValue args, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileOrAux(LispValue dummyVar, LispValue args)
LispValue compileDefun(SECDMachine machine, LispValue name, LispValue argsAndBody, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileDefmacro(SECDMachine machine, LispValue name, LispValue argsAndBody, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileIf(SECDMachine machine, LispValue test, LispValue thenExpr, LispValue elseExpr, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileOptimizedIf(SECDMachine machine, LispValue test, LispValue thenExpr, LispValue elseExpr, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileProgn(LispValue body, LispValue valueList, LispValue code) throws CompilerException
CompilerException
LispValue compileLambda(SECDMachine machine, LispValue body, LispValue valueList, LispValue code) throws CompilerException
CompilerException
public static boolean isBuiltinFunction(LispValue code)
code
- a LISP list.
public boolean isMacroCode(LispValue code)
code
- a Lisp list
|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |