Compiling Scripts in Pnuts

compile()

compile(InputStream input_stream) or
(String expression) or
(Pnuts parsedExpression)

compile(input_stream) function compiles a script reading input_stream and returns a pnuts.lang.Pnuts object. To execute the returned object, call run() or run(pnuts.lang.Context) method.

compile(expression) and compile(parsedExpression) function compile the expression and returns a pnuts.lang.Pnuts object. To execute the returned object, call run() method or run(pnuts.lang.Context) method.

e.g.
code1 = compile(open("/tmp/test.pnut"))
code1.run()

code2 = compile("1 + 2")
code2.run()

compile(parsedExpression) takes a Pnuts object which can be obtained by parse() function.

compile(PnutsFunction function)

compile(function) function compiles the specified function to optimize its execution speed.

e.g.
function func (x) x + 1
compile(func)
compile(String source , String name , File dest) or
(Pnuts source , String name , File dest) or
(String source , String name , ZipOutputStream dest) or
(Pnuts source , String name , ZipOutputStream dest)

When source is a String or a Pnuts object (a parsed expression), it is compiled into a class name. When source is a function, it is also compiled into a class name.

When dest is a String or a java.io.File object, the compiled files are saved in the directory. When dest is a java.util.zip.ZipOutputStream object, the compiled files are added to the ZIP archive.


Back