NetRexx User's Guide, version 2.02
Copyright (c) IBM Corporation, 2001. All rights reserved. ©
Draft of 22 May 2001
[previous | contents | next]

Using the translator as an Interpreter

In addition to being used as a compiler, the translator also includes a true NetRexx interpreter, allowing NetRexx programs to be run on the Java 2 (1.2) platform without needing a compiler or generating .class files.

The startup time for running programs can therefore be significantly reduced as no Java source code or compilation is needed, and also the interpreter can give better runtime support (for example, exception tracebacks are localized to the programs being interpreted, and the location of an exception will be identified often to the nearest token in a term or expression).

Further, in a single run, a NetRexx program can be both interpreted and then compiled. This shares the parsing between the two processes, so the .class file is produced without the overhead of re-translating and re-checking the source.

Interpreting programs

The NetRexx interpreter is currently designed to be fully compatible with NetRexx programs compiled conventionally. There are some minor restrictions, but in general any program that NetRexxC can compile without error should run. In particular, multiple programs, threads, event listeners, callbacks, and Minor (inner) classes are fully supported.

To use the interpreter, use the NetRexxC command as usual and specify either of the following command options (flags):


after parsing, execute (interpret) the program or programs by calling the static main(String[]) method on the first class, with an empty array of strings as the argument. (If there is no suitable main method an error will be reported.)

-arg words...

as for -exec, except that the remainder of the command argument string passed to NetRexxC will be passed on to the main method as the array of argument strings, instead of being treated as file specifications or flags. Specifying -noarg is equivalent to specifying -exec; that is, an empty array of argument strings will be passed to the main method (and any remaining words in the command argument string are processed normally).

When any of -exec, -arg, or -noarg is specified, NetRexxC will first parse and check the programs listed on the command. If no error was found, it will then run them by invoking the main method of the first class interpretively.

Before the run starts, a line similar to:

  ===== Exec: hello =====

will be displayed (you can stop this and other progress indicators being displayed by using the -verbose0 flag, as usual).

Finally, after interpretation is complete, the programs are compiled in the usual way, unless -nojava[1]  or -nocompile was specified.

For example, to interpret the ‘hello world’ program without compilation, the command:

  nrc hello -exec -nojava

can be used. If you are likely to want to re-interpret the program (for example, after changing the source file) then also specify the -prompt flag, as described above. This will give very much better performance on the second and subsequent interpretations.

Similarly, the command:

  nrc hello -nojava -arg Hi Fred!

would invoke the program, passing the words ‘Hi Fred!’ as the argument to the program (you might want to add the line ‘say arg’ to the program to demonstrate this).

You can also invoke the interpreter directly from another NetRexx or Java program, as described in the Using the NetRexxA API section.

Interpreting – Hints and Tips

When using the translator as an interpreter, you may find these hints useful:
  • If you can, use the -prompt command line option (see above). This will allow very rapid re-interpretation of programs after changing their source.
  • If you don't want the programs to be compiled after interpretation, specify the -nojava option, unless you want the Java source code to be generated in any case (in which case specify -nocompile, which implies -keep).
  • By default, NetRexxC runs fairly ‘noisily’ (with a banner and logo display, and progress of parsing being shown). To turn off these messages during parsing (except error reports and warnings) use the -verbose0 flag.
  • If you are watching NetRexx trace output while interpreting, it is often a good idea to use the -trace1 flag. This directs trace output to the standard output stream, which will ensure that trace output and other output (for example, from say instructions) are synchronized.
  • Use the NetRexx exit instruction (rather than the System.exit() method call) to end windowing (AWT) applications which are to be interpreted. This will allow the interpreter to correctly determine when the application has ended. This is discussed further in the Interpreter restrictions section.

Interpreting – Performance

The initial release of the interpreter, in the NetRexx 2.0 reference implementation, directly and efficiently interprets NetRexx instructions. However, to assure the stability of the code, terms and expressions within instructions are currently fully re-parsed and checked each time they are executed. This has the effect of slowing the execution of terms and expressions significantly; performance measurements on the initial release are therefore unlikely to be representative of later versions that might be released in the future.

For example, at present a loop controlled using ‘loop for 1000’ will be interpreted around 50 times faster than a loop controlled by ‘loop i=1 to 1000’, even in a binary method, because the latter requires an expression evaluation each time around the loop.

[1] The -nojava flag stops any Java source being produced, so prevents compilation. This flag may be used to force syntax-checking of a program while preventing compilation, and with optional interpretation.

[previous | contents | next]