Contains various language-dependent methods.
Also contains "global" state about the executation environment,
such as the global Environment. There can be multiple Languages
associated with different threads, representing mutiple top-levels.
(However, this functionality is incomplete.)
asType
public Type asType(Object spec)
"Coerce" a language-specific "type specifier" object to a Type.
booleanObject
public Object booleanObject(boolean b)
coerceFromObject
public Object coerceFromObject(Class clas,
Object obj)
coerceToObject
public Object coerceToObject(Class clas,
Object obj)
coerceToObject
public Object coerceToObject(int val)
defAliasStFld
protected void defAliasStFld(String name,
String cname,
String fname)
Declare in the current Environment a variable aliased to a static field.
defProcStFld
protected void defProcStFld(String name,
String cname)
Declare in the current Environment a procedure bound to a static field.
name
- the procedure's source-level name.cname
- the name of the class containing the field.
The name of the field is the mangling of name
.
defProcStFld
protected void defProcStFld(String name,
String cname,
String fname)
Declare in the current Environment a procedure bound to a static field.
name
- the procedure's source-level name.cname
- the name of the class containing the field.fname
- the name of the field, which should be a static
final field whose type extends gnu.mapping.Procedure.
define
public void define(String sym,
Object p)
Enter a value into the current environment.
defineFunction
public void defineFunction(String name,
Object proc)
Enter a function into the current environment.
Same as define(name,proc) for Scheme, but not for (say) Common Lisp.
defineFunction
public final void defineFunction(Named proc)
Enter a named function into the current environment.
emitCoerceToBoolean
public void emitCoerceToBoolean(CodeAttr code)
Generate code to test if an object is considered true.
Assume the object has been pushed on the JVM stack.
Generate code to push true or false as appropriate.
emitPushBoolean
public void emitPushBoolean(boolean value,
CodeAttr code)
eval
public final Object eval(Reader in)
throws Throwable
Evaluate expression(s) read from a Reader.
This just calls eval(InPort).
eval
public final void eval(Reader in,
Writer out)
throws Throwable
Read expressions from a Reader and write the result to a Writer.
eval
public void eval(Reader in,
Consumer out)
throws Throwable
Read expressions from a Reader and write the result to a Consumer.
eval
public final Object eval(String string)
throws Throwable
Return the result of evaluating a string as a source expression.
eval
public final void eval(String string,
Writer out)
throws Throwable
Evaluate a string and write the result value(s) on a Writer.
eval
public final void eval(String string,
Consumer out)
throws Throwable
Evaluate a string and write the result value(s) to a Consumer.
eval
public final void eval(String string,
PrintConsumer out)
throws Throwable
Evaluate a string and write the result value(s) to a PrintConsumer.
This is to disambiguate calls using OutPort or XMLPrinter,
which are both Writer and Consumer.
eval
public final Object eval(InPort port)
throws Throwable
Evaluate expression(s) read from an InPort.
getDefaultLanguage
public static Language getDefaultLanguage()
getEnvPropertyFor
public Object getEnvPropertyFor(Declaration decl)
getEnvPropertyFor
public Object getEnvPropertyFor(java.lang.reflect.Field fld,
Object value)
getEnvironment
public final Environment getEnvironment()
Get current user environment.
getInstance
public static Language getInstance(String name)
Look for a language with the given name or extension.
If name is null, look for the first language available.
getInstance
public static Language getInstance(String langName,
Class langClass)
getInstanceFromFilenameExtension
public static Language getInstanceFromFilenameExtension(String filename)
getLangEnvironment
public Environment getLangEnvironment()
getLanguages
public static String[][] getLanguages()
Get a list of all available languages
getName
public String getName()
getNamespaceOf
public int getNamespaceOf(Declaration decl)
Return the namespace (e.g value or function) of a Declaration.
Return a bitmask of all the namespces "covered" by the Declaration.
getNewEnvironment
public final Environment getNewEnvironment()
getOutputConsumer
public Consumer getOutputConsumer(Writer out)
getSymbol
public Symbol getSymbol(String name)
getTypeFor
public Type getTypeFor(Class clas)
getTypeFor
public Type getTypeFor(String name)
hasSeparateFunctionNamespace
public boolean hasSeparateFunctionNamespace()
True if functions are in a separate anme space from variable.
Is true for e.g. Common Lisp, Emacs Lisp; false for Scheme.
isTrue
public boolean isTrue(Object value)
Test if a value is considered "true" in this language.
loadClass
public void loadClass(String name)
throws java.lang.ClassNotFoundException
lookup
public Object lookup(String name)
noValue
public Object noValue()
The value to return for a "void" result.
parse
public final Compilation parse(InPort port,
SourceMessages messages,
int options)
throws java.io.IOException,
SyntaxException
Parse one or more expressions.
port
- the InPort to read the expressions from.messages
- where to send error messages and warningsoptions
- various flags, includding PARSE_IMMEDIATE
and PARSE_ONE_LINE
- a new Compilation.
May return null if PARSE_ONE_LINE on end-of-file.
print
public void print(Object obj,
OutPort out)
print
public void print(Object value,
OutPort out,
boolean readable)
registerLanguage
public static void registerLanguage(String[] langMapping)
Add a language to the list.
langMapping
- is a language definition, the first index
is the language name, subsequent indexes are file types that
might cause the language to be used and the final index is the
name of the class that implements the language.
runAsApplication
public void runAsApplication(String[] args)
setDefaultLanguage
public static void setDefaultLanguage(Language language)
setDefaults
public static void setDefaults(Language lang)
string2Type
public static Type string2Type(String name)