net.scheinerman.phoenix.interpreter.functions
Class NativeFunction
java.lang.Object
net.scheinerman.phoenix.interpreter.Interpreter
net.scheinerman.phoenix.interpreter.functions.Function
net.scheinerman.phoenix.interpreter.functions.NativeFunction
public class NativeFunction
- extends Function
A native function is a function that calls the main method of a Java program with a list of inputs.
A native function takes a list of inputs in the left and right hand arguments and calls a Java program
at a denoted path. The list of arguments is translated into a form that is accepted into the command
line arguments of a Java program (String[] args
). The body of a native function must only
be the pathname enclosed in double quotes. For example, the following are valid native function
definitions:
native function void foo(str name):
    "home/foo"
global native function void (num n) bar (str s):
    "../home/bar"
native global function void (num n) foobar (str s, str name):
    "foobar"
These are all valid definitions that run the specified programs. Notice that the order of the keyword
native
and the keyword global
does not matter as long as they are both before
they keyword function
. Also, all native functions must be void, otherwise a error
will result. The support for return values will hopefully come in a later version.
Each of the functions above can be called as below. Their command line equivalents are shown:
Phoenix | Command line |
foo("temp") | java home/foo temp |
(3)bar("test") | java ../home/bar 3 "test" |
(0)foobar("temp 2", "test 2") | java foobar 0 "temp 2" "test 2" |
- Since:
- 1.5
- Version:
- 1.0
- Author:
- Jonah Scheinerman
- See Also:
Function}, {@link Interpreter}
Field Summary |
private java.lang.String[] |
names
An array of the names of the variables that will be passed to the function. |
private java.lang.String |
path
The path of the Java class to be run by this native function. |
private Variable[] |
types
An array of the types of the variables that will be passed to the function. |
Fields inherited from class net.scheinerman.phoenix.interpreter.Interpreter |
_break, _continue, _return, breakValue, code, fat, file, keywordList, line, line_diff, printValues, retType, retTypeSet, retValue, run_code, stop, vat |
Constructor Summary |
NativeFunction(java.lang.String name,
java.lang.String path,
Variable[] b4_types,
java.lang.String[] b4_names,
Variable[] af_types,
java.lang.String[] af_names)
Creates a new native function with the given name, class path and arguments. |
Method Summary |
private static java.lang.String |
getArgList(Variable[] b4_args,
Variable[] af_args)
Returns a version of the left and right hand arguments in a form that is appropriate for passing
into a Java program via command line arguments. |
void |
run(Variable[] b4_args,
Variable[] af_args)
Runs this native function with the given left-hand and right-hand arguments. |
Methods inherited from class net.scheinerman.phoenix.interpreter.functions.Function |
addArgs, check, dealWithReturn, getAfterNames, getAfterTypes, getBeforeNames, getBeforeTypes, getDefinition, getName, printHelp, setModifiers, setName, setVATandFAT, toString |
Methods inherited from class net.scheinerman.phoenix.interpreter.Interpreter |
dealWithBreak, dealWithContinue, dealWithError, delete, doRun, getBlock, getFunction, getFunctionArguments, getFunctionFromDefinition, getReturnValue, getVariable, getWhitespace, initNewTables, isValidIdentifier, makeDefaultVariable, makeFunction, makeVariable, makeVariable, parsePhrase, putFunction, removeComments, removeWhitespace, retValueMatches, run |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
path
private java.lang.String path
- The path of the Java class to be run by this native function.
types
private Variable[] types
- An array of the types of the variables that will be passed to the function.
names
private java.lang.String[] names
- An array of the names of the variables that will be passed to the function.
NativeFunction
public NativeFunction(java.lang.String name,
java.lang.String path,
Variable[] b4_types,
java.lang.String[] b4_names,
Variable[] af_types,
java.lang.String[] af_names)
- Creates a new native function with the given name, class path and arguments. All arguments are
passed from left to right into the main method of the class when this function is called.
- Parameters:
name
- - the function identifierpath
- - the path of the class enclosed in quotes. This should be the sole content of the
function code block.b4_types
- - an array of variables whose types are equivalent
to the types of variables of the left-hand arguments.b4_names
- - the names of the left-hand arguments.af_types
- - an array of variables whose types are equivalent
to the types of variables of the right-hand arguments.af_names
- - the names of the right-hand arguments.
getArgList
private static java.lang.String getArgList(Variable[] b4_args,
Variable[] af_args)
- Returns a version of the left and right hand arguments in a form that is appropriate for passing
into a Java program via command line arguments.
- Parameters:
b4_args
- - The left-hand arguments.af_args
- - The right-hand arguments.
- Returns:
- A version of the arguments that can be read into a Java program in the command line.
run
public void run(Variable[] b4_args,
Variable[] af_args)
- Runs this native function with the given left-hand and right-hand arguments. If these arguments do
not match the given variable types passed to the constructor, a
SyntaxException
will be thrown. If the path given to the constructor is invalid in that it does not exist or does
not point to a valid java class, an IOException will be thrown.
- Overrides:
run
in class Function
- Parameters:
b4_args
- - he left-hand argumentsaf_args
- - the right-hand arguments
- Throws:
SyntaxException
- if the variables are of the wrong type