This chapter says what the RVM is and what it is not, the principles that govern every part of it, its architecture from source text to running program, the two hosts and how they differ, how to run it (launchers, options, the browser entry point, requirements), every environment variable it reads, and a glossary of the terms used throughout these documents. It assumes only a working knowledge of Rexx and ooRexx; everything else is introduced here and developed in the later chapters. The documentation describes baseline version 0.1.
The RVM (Rexx Virtual Machine) is an implementation of ooRexx 5 as a compiler plus a virtual machine:
bin/parser/, its Tree API) builds for a program and
turns it into R-code, a line-oriented text format (04).The machine exists twice, as two hosts that run the
same R-code: one written in ooRexx (RVM.*.cls, run by
native ooRexx 5), and one written in JavaScript (js/*.mjs,
run by Node.js or a web browser). The compiler exists once; the JS host
borrows it (see Compiling).
The aim is that a Rexx or ooRexx program, run on either host, writes
the same standard output and standard error and ends with the same
return code as it does on native ooRexx 5. The RVM covers the whole
language, classic and object-oriented: every instruction and directive,
INTERPRET and interactive trace, conditions, concurrency (activities,
GUARD, START, REPLY), the prelude classes of
CoreClasses.orx and StreamClasses.orx,
REXXUTIL, rxmath, rxregexp, rxsock and hostemu. What is missing is
listed in 18-known-gaps.md; where it
differs on purpose, in 17-divergences.md.
rexxc writes (17).bin/parser/, documented with it); the RVM depends
on it and does not change it (20)./bin/sh and PARSE SOURCE says LINUX
(JS under Node); on Windows they go through cmd.exe and it says
WindowsNT (13);
in a page, BROWSER. The suites' scripts are Unix scripts:
on Windows the RVM is tested with the smoke tool only (16).These principles are stated here and applied, with their consequences, in every chapter; 20-maintaining.md gives the working rules that follow from them.
rexx does, not the ooRexx reference
manual nor the ANSI standard. When they disagree, native wins, so that
native stays usable as a mechanical oracle for everything: every test
compares standard output, standard error and return code with native's
(17, P1), the errors of the
built-in functions included (native's 93.9xx method errors where ooRexx
runs a function as a method of String). The deliberate exceptions are
few and documented (determinism, no crashes, no daemon).DO OVER and ALLINDEXES give native's order;
hashed collections reproduce native's iteration order; the prelude
is CoreClasses.orx, so error reports show native's
line numbers. The ooRexx interpreter sources
(RexxActivation.cpp, NumberStringMath.cpp,
...) are the reference for how, and the chapters cite
them.LENGTH counts bytes, comparisons
compare bytes, files are read and written byte for byte. The JS host
represents a string as a JS string with one character per byte (0–255),
converting with latin1 at every I/O boundary (02).RVM_CLOCK=virtual)
lets tests of timers run instantly and reproducibly (07, 17, P4). source text (.rex, .cls, INTERPRET data, Routine~new, a typed trace line)
|
v
Rexx Parser (bin/parser/, ooRexx) --> AST (Tree API)
|
v
RVM.Compiler (ooRexx) --> R-code text <--> .rcode cache next to the source
|
+---------------------+----------------------+
v v
ooRexx host: RVM.*.cls JS host: js/*.mjs
run by native ooRexx 5 Node.js, or a browser bundle
| |
+------------- same design, ported ----------+
|
machine loop, activations, frames, CALL/SIGNAL/RETURN, PARSE, TRACE,
conditions, activities and scheduler
runtime values and Number; objects, classes, the prelude;
built-in functions; libraries; streams, commands, queues
host files, processes, environment, clock, sockets
Parser and compiler. The front end (../rvm.rex) reads the source, has the
Rexx Parser build the AST and calls RVM.Compiler~compile, a
visitor over the AST nodes. The compiler resolves names to variable
slots, emits instructions that carry Rexx semantics and their own trace
tags, and writes the result with RVM.RCode~write (03).
R-code is text: a header, tables (names, constants,
labels, clauses, classes, routines, methods...) and the instructions,
with an instruction table (RVM.ISA) that both hosts use to
verify a program before running it (04). The
program always runs from the text of its R-code, even right
after compiling, so what the compiler writes is exactly what any machine
reads. R-code can be cached next to its source (x.rex →
x.rcode) and is reused while the source text, the compiler,
the ISA and the parser's frontier stamp are unchanged (03).
Machine. A dispatch loop with explicit registers and explicit frames: the machine never recurses on the host stack to run Rexx code, which is what makes SIGNAL, conditions, interactive trace and green-thread activities uniform (05, 06, 07).
Runtime. Values and decimal arithmetic (02); the object model (08) and reflection (09); the prelude — ooRexx's
own CoreClasses.orx and StreamClasses.orx,
compiled by the RVM and loaded as the REXX package (10); the built-in functions (11); the libraries (12); streams, commands and queues (13).
Host. Everything that touches the system goes
through a host layer: RVM.Host.cls in the ooRexx host, a
host object (NodeHost, BrowserHost) in the JS
host (13, 14).
| Where | Who compiles programs, INTERPRET data, run-time sources |
|---|---|
| ooRexx host | RVM.Compiler, in the same process |
| JS host, Node.js | native ooRexx, in a subprocess per request:
rexx rvm.rex -p FILE, -f (fragments),
-s OPTION (run-time sources) (03) |
| JS host, browser | the same rvm.rex and compiler, as R-code, running
on the JS RVM in a world of their own
(compiler.mjs), when the page enables it (14) |
There is one compiler, so every host gets identical R-code for the same source.
| ooRexx host | JS host | |
|---|---|---|
| Code | ../RVM.*.cls, ../rvm.rex |
../js/*.mjs |
| Runs on | native ooRexx 5 | Node.js; a browser (bundle of rvm-browser.mjs) |
| Launcher | ../rvm |
../js/rvm (Node); none in a
browser |
| Compiler | in process | rexx rvm.rex subprocess (Node);
compiler.mjs (browser) |
| Byte string | the host's .String |
a JS string, one character per byte |
| Collections, MutableBuffer | mostly the host's own classes, wrapped | ports of the native C++ classes |
| rxmath, rxregexp, rxsock | the host's libraries behind the RVM's checks | computed or ported in JS; sockets by a worker (Node only) |
| Prelude | prelude*.orx.rcode files |
embedded (rvm-prelude*.mjs) |
| Error texts, BIF table | the parser's classes, live | generated (rvm-data.mjs) |
| PARSE VERSION | REXX-RVM-ooRexx-<version> 6.06 <date> |
REXX-RVM-JavaScript-<version> 6.06 <date> |
.RexxInfo~executable |
RVM_EXECUTABLE, else the host's rexx |
RVM_EXECUTABLE, else Node's executable;
.nil in a browser |
| Speed | about a thousand times slower than native on call-heavy code | about ten times faster than the ooRexx host |
The JS host in a browser has no commands (every ADDRESS environment is unknown, RC 30), no rxsock, standard input fixed before the run and in-memory files (14). The ooRexx host is the one to debug in (it is Rexx, traceable with native TRACE); the JS host is the one to run large suites with. Each chapter ends its body with a "Host differences" section where they differ.
sh for the launchers and commands, and dd for
the reads of standard input that let other activities run (07).rexx on the PATH) for the
ooRexx host, and for compiling under Node (the JS host spawns
rexx). The RVM is tested against ooRexx 5.3.0, and reports
that version in .RexxInfo.bin/modules/rvm/ of the Rexx Parser's tree and requires
bin/parser/ and bin/parser.cls;
bin/ must be on REXX_PATH when
rvm.rex runs (the launcher rvm does it).Nothing is installed: the launchers run from where they are; symbolic links to them work (they resolve their own directory).
rvm FILE [ARGUMENTS] # ooRexx host: compile FILE and run it
rvm -e PROGRAM [ARGUMENTS] # a program in a string, as rexx -e
js/rvm FILE [ARGUMENTS] # JS host under Node
js/rvm -e PROGRAM [ARGUMENTS]
Both launchers are sh scripts. Each sets
RVM_EXECUTABLE to the path it was called by (absolute,
symbolic links not resolved) and runs its front end: ../rvm prepends bin/ (two
levels up from its resolved directory) to REXX_PATH and
runs rexx rvm.rex "$@"; ../js/rvm prepends the same
bin/ and runs node rvm.mjs "$@". With both, a
program can ::REQUIRES "parser.cls" (the Rexx Parser is
meant to become part of ooRexx; when it does, the launchers are
revisited). Because .RexxInfo~executable is the launcher, a
Rexx program that starts another Rexx program through it (the ooTest
framework's execRexxPrg, the samples) keeps running on the
same RVM.
Common behaviour, as rexx:
ARG) and its .SYSCARGS. With -e,
the program is named INSTORE and has no
.SYSCARGS.RVM_QUEUES,
RVM_MACROSPACE) before it runs.How FILE is found: the ooRexx host uses native ooRexx's program
search from rvm.rex (Package~findProgram: the
name as given, the current directory, REXX_PATH,
PATH, with the usual extensions); the JS host takes the
name as given, and if that is not a file searches for it as an external
routine is searched (current directory, REXX_PATH,
PATH; 03). A file whose name
ends in .rcode (ooRexx host) or whose text starts with
RCODE (JS host) is run as R-code. A source with a valid
.rcode cache next to it runs from the cache without
compiling.
rvm.rex
(ooRexx host) rvm passes its arguments to ../rvm.rex unchanged;
rexx rvm.rex ... is the same thing when bin/
is on REXX_PATH. An option is the first word; only one of
-l/-c is meaningful, and -w may
come right after it (rvm -l -w FILE) or stand alone
(rvm -w FILE). The order matters: in
rvm -w -l FILE the word after -w is taken as
the file name.
| Option | Effect |
|---|---|
(none) FILE |
compile FILE (or use its .rcode cache) and run it |
FILE.rcode |
run R-code already compiled (no source: SOURCELINE sees nothing) |
-l FILE |
compile FILE and write its R-code on standard output; do not run |
-c FILE |
compile FILE and write its R-code to its cache file
(x.rex → x.rcode, otherwise
name.rcode); do not run |
-w FILE |
run, and write the cache of every source compiled during the run (the program, its external routines, its required packages, the prelude) |
-e PROGRAM |
compile and run the string PROGRAM as INSTORE (combines
with -l and -w) |
-p FILE, -f, -s OPTION |
the compile-request protocol the JS host uses under Node: an external routine's file, an INTERPRET fragment or typed trace line, a run-time source (03). Not for interactive use. |
-l and -c always compile (they never read a
cache). Given a .rcode file they do nothing special: the
R-code is run. A FILE name with blanks is given in double quotes.
rvm -l prog.rex > prog.rcode # same R-code as: rvm -c prog.rex
rvm prog.rcode # run it on the ooRexx host
js/rvm prog.rcode # or on the JS host
rvm.mjs (JS host under Node)
js/rvm passes its arguments to ../js/rvm.mjs:
| Option | Effect |
|---|---|
FILE |
R-code (first line RCODE n), or a source loaded as an
external routine is: its .rcode cache when valid, else
compiled by rexx rvm.rex -p FILE |
-s SOURCE FILE |
FILE is R-code compiled from SOURCE: PARSE SOURCE and error reports name SOURCE, and SOURCELINE sees its lines |
-w FILE |
write the cache of every source compiled during the run |
-e PROGRAM |
compile the string (by rvm.rex -s -) and run it as
INSTORE; the text is taken from the command line as UTF-8
and turned into bytes |
-s and -w may come in either order before
FILE. There is no -l or -c: R-code is written
by the ooRexx side (or by -w).
There is no launcher. A page bundles ../js/rvm-browser.mjs
(which exports BrowserHost, runProgram,
runSource, compileSource,
reportError, readRCode,
sourceLines), for example:
esbuild rvm-browser.mjs --bundle --format=iife --global-name=RVM --minify --outfile=rvm.js
and runs R-code, or source once the compiler library is enabled:
const host = new RVM.BrowserHost({ onOut, onErr, stdin: "" });
const exitCode = RVM.runProgram(rcodeText, host, "/home/rexx/prog.rex");
// with RVM.BrowserHost.addLibrary(...) and enableCompiler(...) first:
const code = RVM.runSource(sourceText, host, "/home/rexx/prog.rex");The run is synchronous; output arrives through the callbacks. Files are in memory, the environment is a table per host. The details, and how to build the compiler library, are in 14.
../rxqueue/rxqueue and
../js/rxqueue/rxqueue:
the rxqueue filter, put first on the PATH of
every command an RVM runs (13).../smoke/smoke.rex:
the quick test of both hosts against native expected output (16).../makeprelude.rex,
js/gendata.rex, js/genprelude.rex: generators
(10,
14).Every environment variable either host reads. "Both" means the ooRexx
host and the JS host under Node; in a browser the variables are the
page's table (host.env), where only the ones marked
"browser" mean anything. Programs can of course read and set any
variable themselves (VALUE(name, , 'ENVIRONMENT'),
SETLOCAL, export/set commands);
these are the ones the RVM itself consults.
| Variable | Read by | Hosts | Effect | Chapter |
|---|---|---|---|---|
RVM_EXECUTABLE |
.RexxInfo~executable |
both | Set by the launchers to their own path. When set,
.RexxInfo~executable is that file; otherwise the host's
rexx (ooRexx host) or Node's executable (JS). |
09 |
RVM_QUEUES |
the front ends at start (shareQueues);
rxqueue.rex |
both | Set by the RVM in the environment of every command it runs: a file holding a snapshot of its external data queues. An RVM started by the command loads it, and writes it back at the end if the queues changed; the parent reloads it when the command ends. | 13 |
RVM_MACROSPACE |
as RVM_QUEUES |
both | The same mechanism for the REXXUTIL macrospace. | 12 |
RVM_CLOCK |
the scheduler at start | both, browser | virtual (any case): timers use a virtual clock that
advances only when no activity is ready, jumping to the next deadline;
DATE and TIME add the virtual offset to the
host's time. For deterministic, wait-free test runs. |
07 |
RVM_SLICE |
the scheduler at start | both, browser | A whole number: the clauses an activity runs before yielding to
other ready activities; 0 (or a negative one) never yields;
default 10000. |
05, 07 |
RVM_WORKER |
js/rvm.mjs at start |
JS under Node only | 0: run the program in the main thread, with no worker:
a signal (Ctrl-C) then ends the process instead of being a HALT. |
14, 07 |
RVM_LOCAL |
the world at start | both, browser | eager (any case): make .LOCAL at start, as
native does, instead of when first needed. |
09 |
RVM_TBCHECK |
report of an untrapped error | ooRexx host; JS under Node only | Any non-empty value: compare the report with the error's
TRACEBACK and print
RVM_TBCHECK mismatch in ... on standard error when they
differ. A test aid. |
06, 16 |
RVM_WINDOWS_SHARING |
HostFile.open, FileOps |
JS under Node only | 1: apply Windows's rules for sharing a file (a second
open of an open file is ERROR:13, an open file cannot be
deleted) on any system. A test aid; on Windows they always apply. |
13 |
RVM_WINDOWS_HOSTEMU |
the first EXECIO | both | 1: hostemu is Windows's (its way of opening files;
Microsoft's text mode, its FILE's states and
atoi) on any system. A test aid; on Windows it always
is. |
12 |
RVM_ACTTRACE |
the activity loop | both | Any non-empty value: print ACT id outcome resumeAt (JS:
ACT id outcome) on the error stream at every activity
switch. A debugging aid. |
07 |
REXX_PATH |
external routine and ::REQUIRES search;
rvm.rex's own ::REQUIRES |
both, browser | Directories searched after the caller's and the current directory,
before PATH (separated by :; on Windows by
;). The launchers prepend bin/; the Node host
prepends it for the rexx processes it spawns; in a browser
it is the library roots. |
03 |
PATH |
external routine search; command search | both, browser (search only) | Searched after REXX_PATH. For commands, the RVM's
rxqueue directory is put first; default
/bin:/usr/bin when it does not exist (an empty
PATH is the current directory only, as
execvp). |
03, 13 |
HOME |
cd command; ~ in file names |
both, browser | The home directory for cd with no operand,
~ and ~/.... |
13 |
TMPDIR |
temporary files | both | Directory for the files of command redirection and queue/macrospace
sharing, and File~temporaryPath; default /tmp
(on Windows, TEMP). |
13 |
RXQUEUE |
rxqueue.rex |
both | The default queue of the rxqueue filter when none is
named (then SESSION). |
13 |
The browser table starts with HOME
(/home/rexx), USER (rexx),
PATH (/bin:/usr/bin) and
REXX_PATH (the library roots). Note that
RVM_REX in host-node.mjs is a JS constant (the
path of rvm.rex), not an environment variable.
ADD is full Rexx addition, traced
>O>), so TRACE output and error behaviour come out of
the machine without the compiler simulating them (04).goto. A VM confines those problems to
the machine and the runtime, where they are solved once (own decimal
arithmetic, byte strings, an explicit loop), and keeps them out of the
compiler.RVM_EXECUTABLE so that a
Rexx program that starts "the interpreter" (test frameworks do) starts
the RVM, not native ooRexx; otherwise programs run that way would
silently be judged on native.REXX-RVM-ooRexx-...,
REXX-RVM-JavaScript-...) at language level 6.06, as
native's invariant .RexxInfo~name = PARSE VERSION requires;
the numeric .RexxInfo version fields report the ooRexx
version whose behaviour the RVM follows (09).| Term | Meaning |
|---|---|
| activation | One running invocation of Rexx code: a program, routine, method,
internal call, trap handler or INTERPRET. It lives in three parallel
stacks: machine frame, saved caller state (RVM.Activation)
and level (05). |
| activity | The RVM's equivalent of an ooRexx thread: a green thread with its own context and activation stack, multiplexed on one machine loop by the scheduler (07). |
| behaviour | The method dictionary of an object, built from its class's method resolution order (MRO), scopes and per-object methods (08). |
| BifSend | RVM.BifSend / BifSend: what a built-in
function returns instead of a value when the result needs a message send
(the stream functions, RXQUEUE); the machine sends it (11). |
| byte layer | The few host string operations the runtime is allowed to use (length, in-range substring, concatenation, search, MutableBuffer), all byte-exact (11). |
| census | A run of the official ooRexx test suite (ooTest), group by group, on native and on an RVM host, comparing counts; with its acceptance rules for documented divergences (16). |
| clause boundary | The CLAUSE instruction at the start of each clause:
where trace, pending CALL ON traps, the time slice and HALT are handled
(04). |
| context | RVM.Context / Context: the execution state
of one activity (activations, settings, traps, clock), plus globals
shared by all activities. Not .context, which is a
RexxContext object. |
| delegation | How a native method that needs Rexx code ends: it returns an
RVM.Delegate / Delegate (receiver, message,
arguments) and the machine sends it, instead of the native calling Rexx
itself (08). |
| fragment | R-code compiled apart for INTERPRET data or a line typed at an interactive-trace pause, relocated into the running program (04). |
| frame | A variable frame (slot cells, RVM.Vars /
Frame); or a machine frame (return information), depending
on context (05). |
| host | (1) One of the two implementations of the machine: the
ooRexx host or the JS host. (2) The
host object or layer through which the machine reaches the system
(RVM.Host.cls, NodeHost,
BrowserHost). (3) "The host's X": something provided by the
language a host is written in (e.g. the host's
.Array). |
| INSTORE | The name of a program given as a string (rvm -e), as
native names it. |
| ISA | The instruction set: the table RVM.ISA (operands of
every opcode) shared by the writer and both verifiers; its version,
RVM.ISA~VERSION, is part of every R-code header (04). |
| kind (of a class) | What the instances of a built-in class or its subclasses wrap as native value (DIRECTORY, ARRAY, STEM...); inherited by subclasses (08). |
| level | RVM.Level / Level: the part of an
activation that .context, StackFrames, TRACEBACK and locks
see (09). |
| library registry | The closed list of native libraries the RVM implements (REXX,
rexxutil, rxmath, rxregexp, rxsock, hostemu); EXTERNAL and
::REQUIRES ... LIBRARY resolve against it (12). |
| native | (1) Native ooRexx: the C++ interpreter, rexx. (2) A
native method or routine: one implemented in the host language rather
than in Rexx (08). |
| NeedString | The mechanism by which an instruction that needs the string value of
an object with a Rexx STRING method is abandoned, the
method run, and the instruction re-executed (05). |
| ooTest | The official ooRexx test suite (exported with svn), run
by the census (16). |
| oracle | Native ooRexx 5 used as the reference: a test passes when standard output, standard error and return code equal native's. An "oracle directory" is the tooling that runs a program both ways and compares (16). |
| P1–P5 | The principles behind the divergences from native, defined in 17; e.g. P4: determinism. |
| phantom (activation) | An activation after FORWARD without CONTINUE: it only waits for the forwarded result, and an error in that send goes past its traps (08). |
| prelude | The Rexx part of the REXX package: ooRexx's
CoreClasses.orx and StreamClasses.orx, cut by
makeprelude.rex, plus the RVM's
prelude-rvm.orx; compiled to R-code and loaded at start (10). |
| R-code | The RVM's program format: a text file with header, tables and
instructions (04). A
.rcode cache is the R-code of a source
kept next to it (03). |
| redo piece | Code compiled out of line at the end of a body that =
at an interactive-trace pause runs to repeat a clause
(RVM.Unit~redo, 03). |
| runSync / sendSync | Running a program or a message to completion in a separate machine instance, for natives that need a result at once (05). |
| scheduler | The object that keeps activities, switches between them at clause boundaries and owns the timer clock (07). |
| slice | The number of clauses an activity runs before it yields
(RVM_SLICE). |
| slot | The compile-time number of a variable name in a program's NAMES table (04). |
| smoke test | smoke/: a small selection of programs covering every
instruction, run on both hosts against native's expected output (16). |
| thunk | A piece of Rexx run on a nested machine to completion, e.g. an
ADDRESS ... WITH target object's method (05). |
| Tree API | The Rexx Parser's API over its AST, which the compiler visits (03). |
| virtual clock | The timer clock of RVM_CLOCK=virtual, which moves only
when every activity waits (07). |
| world | RVM.World / World: the universe of one
run: the classes, .nil, .environment,
.local, the scheduler (08). |
rvm.rex's option handling is positional and minimal:
-l/-c given a .rcode file run it
instead of rejecting the request.