Command Shell

Invoking and Terminating the Interpreter

C:\> pnuts

The "pnuts" command invokes a Pnuts interpreter. The greeting message shows the version of Pnuts, the JDK version, and JVM vendor's name.

C:\> pnuts
Pnuts version 1.0 (03/26/2002), 1.3.1_02 (Sun Microsystems Inc.)
Java HotSpot(TM) Client VM (mixed mode)
> 
> expression
result

Input an expression after the prompt (>) then hit ENTER key. Then the expression is evaluated and the result is shown.

> 1 + 2
3
> exit()

Either exit() or quit() is used to terminate the command shell.

pnuts Command Options

C:\> pnuts { -e expression | -r resource | -R resource | -f initfile | -F initfile | -u URL | -U URL | -m moduleName | -a | -b | -p | -w | -s | -v | -encoding enc | -inputlog file | -version | -help }* { fileName { arg1, ... }}

-version option prints the version information and exits.

-encoding option specifies the character encoding for script files.

-e option evaluates the next argument as an expression.

C:\> pnuts -e println(\"hello\")
...
C:\>

-r option loads a resource file specified with the next argument, and continues the interactive session.

-R option loads a resource file specified with the next argument, and terminates the session.

C:\> pnuts -r examples/fact.pnut
Pnuts version 1.0 (03/26/2002), 1.3.1_02 (Sun Microsystems Inc.)
Java HotSpot(TM) Client VM (mixed mode)
>

-f option loads a local file specified with the next argument, and continues the interactive session.

-F option loads a local file specified with the next argument, and terminates the session.

C:\> pnuts -f "$HOME/init.pnut"
Pnuts version 1.0 (03/26/2002), 1.3.1_02 (Sun Microsystems Inc.)
Java HotSpot(TM) Client VM (mixed mode)
>

-u option loads a script file specified as a URL, and continues the interactive session.

-U option loads a script file specified as a URL, and terminates the session.

C:\> pnuts -u http://javacenter.sun.co.jp/pnuts/examples/calculator.pnut -e quit()

-m option add a module to the initial context. Functions in the module can be accessed without specifying the package name prefix.

C:\> pnuts -m my.module

-v option sets verbose output mode. When an exception is thrown the stack trace is printed. In addition, a log message is printed when a script file is loaded.

C:\> pnuts -v
Copyright (c) 1997,1998 Sun Microsystems, Inc. All rights reserved.
Pnuts interpreter Version 1.0, 1.1.8 (Sun Microsystems Inc.)
> throw("hogehoge") 
java.lang.RuntimeException: hogehoge
	at java.lang.Throwable.(Compiled Code)
	at pnuts.lang.PnutsFunction.call_builtin(Compiled Code)
	at pnuts.lang.PnutsFunction.exec(Compiled Code)
	at pnuts.lang.PnutsInterpreter._applicationNode(Compiled Code)
	at pnuts.lang.SimpleNode.jjtAccept(Compiled Code)
	at pnuts.lang.PnutsInterpreter._expressionList(Compiled Code)
	...
	...

If -a option is given in Java2 environment, all non-public members are accessible from scripts.

string = "Hello"
string.value ==> ['H', 'e', 'l', 'l', 'o']

If -p option is specified, only public members are accessible from scripts.

If -b option is given, all field access expressions are interpreted as JavaBeans access. This switch no longer useful since it became the default behavior.

import("java.awt.*")
f = Button("OK")
f.label

If -w option is given, a Swing-based GUI console comes up and the Pnuts interpreter runs in it.

C:\> pnuts -w

If -s option is given, scripts are executed in the secure sand-box.

C:\> pnuts -s unsecure_script.pnut

-inputlog option specifies the log-file's name to which user input in an interactive session are saved.

C:\> pnuts -inputlog c:\tmp\input.log

See 'On-the-fly Compiler and AST Interpreter' for -pure option and -O option, and 'Debugging Scripts' for -d option and -vd option

Passing Arguments to JVM

If -J<option> is given, the <option> is passed to JVM. For example, the following command passes -Xmx4m to JVM.

pnuts -J-Xmx4m

${PNUTS_HOME}/modules directory

When the pnuts command is executed, JAR files in ${PNUTS_HOME} directory are appended to the CLASSPATH setting.

Command Line Arguments

If a fileName is specified in pnuts command, the file and the arguments that follows can be accessed with the global variable '$args'.

for (i : 0..$args.length - 1) println($args[i])
echo.pnut
C:\> pnuts echo.pnut 1 2 3
echo.pnut
1
2
3

Environment Variables

Environment Variable Description
PNUTS_JAVA_COMMAND Specifies the path of the java command. The default value is "java".
PNUTS_JDK11_COMPATIBLE If this environment variable is defined, Pnuts classes are appended to CLASSPATH and loaded by the system classloader. Otherwise, Pnuts classes are loaded by the boot classloader.
PNUTS_MODULE Startup modules, which are separated by semi-colon. "pnuts.tools" is the default value.
HTTP_PROXY_HOST Specifies HTTP proxy host.
HTTP_PROXY_PORT Specifies HTTP proxy port.

The System Properties

The following properties must be set before any of Pnuts API classes is loaded.

Property Description
pnuts.lang.defaultPnutsImpl If a class that implements pnuts.lang.Implementation interface is specified, an instance of the class is created with the default constructor and it becomes the default Implementation object. See 'The pnuts.lang.defaultPnutsImpl Property' for more details.
pnuts.lang.defaultConfiguration If a vaild pnuts.lang.Configuration subclass is specified, an instanceof the class is created with the default constructor and it becomes the default Configuration.
pnuts.compiler.optimize If true is specified, Pnuts compiler generates a little faster code. Instead, line number information is not printed when an error occurs.
pnuts.compiler.traceMode If true is specified, Pnuts compiler generates Context.updateLine(int) method for every expression.
pnuts.compiler.useDynamicProxy If true is specified, method/constructor call is implemented by dynamic proxy class, rather than reflection API. Method/constructor call could be a little faster using with JIT compiler.
pnuts.compiled.script.prefix If this property is set at start up time, when the function load() is called with a parameter that does not end with the suffix '.pnut', Pnuts interpreter tries to load a precompiled script as a Java class. The class name is the script name that '/' is replaced by '.' after the value of the property. For instance, when a script name is "lib/stream" and the property "pnuts.compiled.script.prefix" is "pnuts.precompiled.", pnuts.precompiled.lib.stream class is loaded if it exists. The pnuts command defines the property as "" by default.
pnuts.package.factory If this property is specified at start up time, the class becomes the default package factory. See pnuts.lang.PackageFactory.

The following properties are related to the pnuts command.

Property Description
pnuts.interactive If this property is not specified, when neither script files nor expression (with -e) nor redirection are given, pnuts command runs in interactive mode, which means that the prompt string and results are displayed. The property pnuts.interactive allows to specify explicitly that pnuts command runs in interactive or batch mode no matter what is given in the command line.
pnuts.debugger When -d option is given to the pnuts command, a class name of the debugger can be specified to the 'pnuts.debugger' property. If the property value is "pnuts.tools.VisualDebugger", the graphical debugger is used instead of the terminal-style debugger.
pnuts.tools.modules Specifies the modules to be used at the startup time. It should be a comma-separated list.
pnuts.home The directory where Pnuts is installed. This property is read-only.

Version Number

The value of pnuts_version variable is the version number of Pnuts.