This chapter is for whoever works on the RVM: the principles every change follows, the code and documentation conventions, how a change is carried through both hosts and the generated files, the boundary with the Rexx Parser, and which checks to run for each kind of change. It assumes the overview (01) and the source map (15); the test suites themselves are described in 16-testing.md.
Every behaviour of the RVM is judged against native ooRexx 5
(rexx): the same program must write the same standard
output and standard error and end with the same return code. When the
documentation (rexxref, the ANSI standard) and native ooRexx disagree,
native wins, so that native stays usable as the oracle for everything
(17, P1). The few deliberate
exceptions are listed, with their reasons, in 17-divergences.md (determinism, no crashes,
no daemon); even the errors of the built-in functions are native's.
A feature is finished when the result equals native ooRexx in both
hosts, and a test case that shows it runs against native in the suites
(16). The ooRexx interpreter sources
(RexxActivation.cpp, NumberStringMath.cpp,
CoreClasses.orx...) are the reference for how
native does it; the chapters cite the file when a design relies on
it.
The RVM ports native behaviour; it does not approximate it. When
native has a structure whose behaviour a program can observe, the
structure is ported, not imitated: the stem tail tree is the native
compound-variable table, so DO OVER and
ALLINDEXES give native's order (10); the prelude is ooRexx's
own CoreClasses.orx, cut, so error reports show native's
line numbers (10). Native
quirks are copied too, as long as a correct program can rely on
them.
What is not copied are native defects: crashes, hangs, results that contradict native's own documentation. The RVM does the documented thing there; the defects visible to a correct program are listed in 17.
The ooRexx host is written in ooRexx, but it does not let the host
interpreter supply Rexx semantics: decimal arithmetic (02), variable pools, the built-in
functions and the object model are all implemented explicitly. The host
is used for bytes (strings as byte sequences, Length,
SubStr within range, concatenation, Pos,
MutableBuffer), files, processes and the clock — never for
semantic built-ins such as WORD, STRIP or
TRANSLATE. The reason is the second host: whatever the
ooRexx host borrows implicitly, the JS host would have to rediscover.
The deliberate exceptions (collections and some libraries borrowed from
native ooRexx in the ooRexx host, and ported in the JS host) are listed
in 15.
The JS host mirrors the ooRexx host file by file and, mostly, method by method (15). A change is made in both hosts in the same change, and its test runs in both. The compiler exists once (in Rexx); both hosts run the same R-code, which is what makes the JS host checkable against the ooRexx host instruction by instruction. When the two hosts must differ (the browser has no processes, JS strings have no identity), the difference is documented in the "Host differences" section of the chapter concerned.
The RVM's own choices are deterministic: activities switch after a
count of clauses, not after a time; a wait nothing can satisfy ends the
run; a virtual clock (RVM_CLOCK=virtual) exists for tests
(07, 17, P4). New code keeps it that
way: no dependence on timing, hash order of host maps, or process
scheduling where a program can see it.
Code, identifiers, comments, file headers and this documentation are in English.
.cls, .rex, .orx written for the
RVM)Do/End,
If/Then/Else,
Select/When/Otherwise/End,
Loop/End).If,
Then, Select, Loop,
Signal, Call, Return,
Parse, Use, Expose,
Forward. Never select or
THEN.camelCase;
public routines, labels and classes in PascalCase; classes
of the RVM carry the RVM. prefix (RVM.Machine,
RVM.BaseContext) and the packages are named after their
main class (RVM.Machine.cls). Packages require each other
as modules/rvm/RVM.X.cls, with bin/ on
REXX_PATH.result (any
message instruction, even obj~x = v, and every
CALL overwrite it), rc (overwritten by
commands) and sigl (overwritten by CALL and
SIGNAL). Use res, outcome,
ret.- at the end of the
line, with the continued code aligned./* + 76 * + */) for major
sections; a line of dashes after -- for minor ones.Signal On Syntax Name Label /
Signal Off Syntax. Select without a default
action ends with Otherwise Nop.WordPos(value, "opt1 opt2 opt3").js/*.mjs)ES modules, two-space indentation, camelCase for
functions and variables, PascalCase for classes. Names
follow the ooRexx host so that a reader of one host can find the code in
the other: CallRoutine → callRoutine,
RVM.Machine~execute → Machine.execute; where
the JS name differs, the correspondence table of 15 gives it. A JS method that
ports a Rexx one says so in its comment
(// see RVM.PreludeLoader~loadStreams), and the Rexx side
names its JS counterpart where that helps.
Every source file opens with a comment box of exactly 80 columns: the
file name and a one-line title (underlined with =), then a
description of what the file does — its classes or
exports, its model, how it fits with the rest — then the package line,
the copyright and the licence. The licence is Apache 2.0 or, for files
derived from ooRexx, the CPL 1.0, with a different box; which files
carry which, and the rule for a new file that ports ooRexx code, are in
19-licensing.md. The generators
(makeprelude.rex, genprelude.rex,
gendata.rex) write the headers of the files they
produce.
Headers and comments describe the code as it is. They carry no
history (no version tables, no dates, no "previously" or "now"), no
roadmap ("not supported yet", "later"), and no references to material
outside the repository; the design and its reasons belong in these
chapters, which a comment may cite (see doc/05-machine.md).
Versions are the constants RVM.Compiler~VERSION,
RVM.ISA~VERSION and RVM.RCode~VERSION (04), not comment text. History lives in
version control.
prelude.orx,
prelude-streams.orx, their .rcode,
js/rvm-data.mjs, js/rvm-prelude*.mjs) are
never edited by hand: change the generator or its input and regenerate
(14).Em-dashes as the character —, not ---.
Headings in sentence case at every level (## Design notes,
### The stream table and stream scope): first word and
proper names capitalised. A chapter's H1 is its number and title
(# 13. I/O, commands and queues). Links to code are
relative to doc/ (../RVM.Machine.cls); code is
cited by class, method or routine name, never by line number.
.Nil: initialise every attribute in init.| and & evaluate both operands; a
comma-separated condition list in If/When
(If a, b Then) stops at the first false one." " b concatenates two blanks;
'x='x is a hexadecimal literal and '['b a
binary one.options.name) uses the variable's value: write
options.["NAME"].::Method "Class::name" directives after a
::Class belong to that class. That is why
RVM.Compiler.cls keeps its own classes at the end, after
the visitor's floating rcompile methods.A change is not finished until the documentation it affects is updated in the same change — exactly as it is not finished without its test. In practice:
| The change | Also update |
|---|---|
| Behaviour, structure or mechanism described in a chapter | that chapter (the chapter of each area is in 15) |
| A new file, or a file renamed or removed | 15-source-map.md; 19-licensing.md and ../NOTICE if
it is derived from ooRexx |
| An instruction, an operand, a section of the R-code | 04-rcode.md and the version constant (04) |
| A behaviour that differs from native, found, accepted or fixed | 17-divergences.md (a fixed one is removed); the census acceptance rule, if one covers it |
| Something left unimplemented, or a gap closed | the chapter's "Known gaps" and 18-known-gaps.md |
| An environment variable or launcher option | 01-overview.md and the chapter of the mechanism |
| A new kind of test or suite | 16-testing.md |
A divergence entry records native's behaviour, the RVM's, the hosts that show it, its status and the reason (17). A decision with a reason goes into the "Design notes" of its chapter.
rexx. If the behaviour is not obvious, read
the ooRexx source that implements it. Write the program as a test case
that compares with native (16).bin/modules/rvm/rvm and bin/modules/rvm/js/rvm
against rexx.RVM.RCode~VERSION and RCODE_VERSION;
instruction set → RVM.ISA~VERSION and
ISA_VERSION (with RVM.ISA and ISA
kept identical); generated code → RVM.Compiler~VERSION (04). The compiler version is what
invalidates the .rcode caches (03): a compiler change that
alters the generated code without bumping it leaves stale caches that
are still used.Step-by-step recipes for the common changes (a built-in function, a native method, a Rexx method in the prelude, an R-code instruction, a library routine) are in 21-recipes.md.
| What changes | ooRexx host | JS host | Then |
|---|---|---|---|
| An instruction, a way to send or deliver, activations, traps | RVM.Machine.cls |
js/machine.mjs |
|
| A native method, a class of the object model, the World | RVM.Objects.cls |
js/objects.mjs |
|
| Variables, the context | RVM.BaseContext.cls (+ RVM.Context in
RVM.Machine.cls) |
js/context.mjs |
|
| Arithmetic, number formatting | RVM.Number.cls |
js/number.mjs |
|
| A built-in function, argument checking | RVM.BIFs.cls (a new one: also the name list of
RVM.BIFTable~activate) |
js/bifcore.mjs, js/bifs*.mjs |
a new one: the parser's BIFs.cls,
js/rvm-data.mjs (21) |
| Streams | RVM.Stream.cls |
js/streams.mjs |
|
| Commands, ADDRESS WITH, queues, the host | RVM.Commands.cls, RVM.Host.cls,
RVM.Machine.cls |
js/machine.mjs, js/host-node.mjs,
js/hostfile-node.mjs, js/host-browser.mjs |
|
| A library routine (REXXUTIL, rxmath, rxsock...) | its RVM.*.cls; the registry in
RVM.BIFs.cls |
its js/*.mjs; js/libraries.mjs |
(12) |
| The R-code format or the instruction set | RVM.Compiler.cls, RVM.RCode and
RVM.ISA in RVM.Machine.cls |
js/rcode.mjs, js/machine.mjs |
versions; both prelude .rcode and .mjs; 04 |
| The compiler's output | RVM.Compiler.cls |
— | RVM.Compiler~VERSION; both prelude .rcode
and .mjs |
| The prelude | makeprelude.rex, prelude-rvm.orx |
— | prelude*.orx, .rcode,
js/rvm-prelude*.mjs |
| The parser's error texts or BIF table | (used live) | — | js/rvm-data.mjs |
The chains and the exact commands are in 10 and 14. In short:
| You changed | Regenerate |
|---|---|
CoreClasses.orx / StreamClasses.orx (a new
ooRexx), makeprelude.rex |
prelude*.orx, then as below |
prelude-rvm.orx, a prelude*.orx, or
anything that alters the compiler's output (compiler, ISA, R-code
format) |
prelude*.orx.rcode (./rvm -l), then
js/rvm-prelude*.mjs (genprelude.rex) |
A new ooRexx with new error messages, or the parser's
BIFs.cls |
js/rvm-data.mjs (gendata.rex) |
| Anything that alters the compiler's output | delete the .rcode caches written with -w
next to test programs; rebuild the browser library (14) |
The JS host does not notice a stale js/rvm-prelude*.mjs
as long as the format and ISA versions match (10):
forgetting to regenerate makes the two hosts run different preludes,
which no load-time check catches. On an unchanged tree the generators
reproduce the committed files byte for byte; that is the quick check
that the toolchain is right.
The RVM is a client of the Rexx Parser (bin/), and
depends on it at these points:
| What | Where | Used by |
|---|---|---|
| The AST (Tree API) | parser.cls, bin/parser/*.cls |
the compiler (03) |
The BIF set and argument table (.Parser.BIF,
.Parser.BIFInfo) |
bin/parser/BIFs.cls,
bin/parser/SecondPass.cls |
the compiler, RVM.BIFs.cls,
js/rvm-data.mjs (11) |
| Error texts (ERRORTEXT, secondary messages) | the host's ErrorText (with inserts since ooRexx
r13480) |
RVM.Machine.cls, js/rvm-data.mjs (06) |
Parser options: INTERPRET fragments, METHOD (sources of
Method~new and the like), the shebang line, early
checks |
parser.cls |
the compiler (03, 09) |
A parse error: the condition USER REXX.PARSER.ERROR (thrown), whose
ADDITIONAL is a Rexx.Parser.Error (code,
line, column, clause,
substitutions) |
bin/parser/BaseClassesAndRoutines.cls,
bin/parser/ErrorHandler.cls |
rvm.rex (ParseError,
CompileFileError, FragmentError),
RVM.Machine.cls (ParseErrorLine),
js/compiler.mjs and js/host-node.mjs (the
-f answer) (06) |
How a parser change breaks the RVM. The parser's own tests do not exercise the compiler, and the compiler is bound to the AST by names, so the failure depends on what changed:
Load.Parser.Module.rex cannot find the class of a
"Class::rcompile" method and stops ("Internal error! Class
X not found."), so every compilation fails at once. Loud.rcompile: Gen compiles it to
ERR 93.900 "RVM: <class> is not supported yet",
raised only if that code runs (03). The smoke
test's astcheck.rex names it (NEW) at once (16); give it an
rcompile, or a place in that list with its reason.Rexx.Parser.Error renamed:
error reports lose their clause line or their position; no test of the
parser looks at them.Only programs that use the construct find the last two: the smoke test covers the common ones in minutes, the end-to-end suites and the census the rest.
Rules:
bin/modules/rvm/ is changed as
part of an RVM change. A fix or an addition to the parser (an
AST accessor, a translation error, a BIF table entry) is made in the
parser and proposed to the Rexx Parser project: one diff -u
per file against the version it was made on, what each change does and
why the RVM needs it, and the tests it passed. Running programs on the
RVM is a good way to find parser bugs; they are fixed in the parser, not
worked around in the compiler. Some RVM features need such a parser
change first: a new built-in function exists for the compiler only once
the parser's BIF table has it (21). The
RVM side is then made against the parser with that change, and both are
proposed together.tests/RunTests.rex), which must pass whole
— including the suites that belong to the parser and the other projects
of the repository — and the RVM's smoke test, which exercises the AST,
the BIF table, the error texts and INTERPRET in a few minutes.bin/resources/frontier, one integer,
described in bin/resources/readme.md), which every
.rcode records, so caches made against the old parser are
not used (03). The Rexx
Parser raises it in the same change, and its note to the RVM says so. If
the change alters what the compiler generates, the prelude is
regenerated. A change to the error texts or the BIF table needs
js/rvm-data.mjs regenerated; the ooRexx host reads them
live.The full battery takes long and is not the default. Run what exercises the code that changed, in both hosts; widen only if something fails. The suites named here, how to run them and how long each takes are in 16-testing.md. Before launching a long run, estimate its time from the last real run.
| You touched | Run |
|---|---|
| Anything | the smoke test (rexx bin/modules/rvm/smoke/smoke.rex,
both hosts, a few minutes) |
The object model (RVM.Objects.cls,
js/objects.mjs, the OO parts of the machine) |
the object-oriented end-to-end cases of the families touched (by prefix), both hosts |
The machine, program loading, external routines,
::REQUIRES |
the Classic end-to-end suites (native vs ooRexx host; JS host vs ooRexx host), the external-routine tests on each host, the cache tests |
| A collection class (Array, List, Queue, Set, Bag, Relation, MutableBuffer...) | that collection's fuzzer; for RVM.Stem / the Stem
class, the stem cases and the stem fuzzer |
| Arithmetic, PARSE, CALL, SIGNAL, TRACE, EXPOSE | the Classic fuzzers of that area, on both hosts |
| Conditions, error reports, concurrency | the OO end-to-end families for conditions, RAISE, tracebacks, concurrency, semaphores, alarms, UNINIT |
HALT, the scheduler's waits, js/rvm.mjs (the
worker) |
the signal tests (tests/signal/signal.sh) |
Standard input (RVM.StdinReader,
inputNeed, NodeHost's stdin*, the
reader in rvm.mjs) |
the stdin-, stdio- and
stream- OO end-to-end families, the signal tests, and by
hand a terminal (a pseudo-terminal: 16) |
| A library (REXXUTIL, rxmath, rxregexp, rxsock, hostemu) | its OO end-to-end family; for rxregexp, its fuzzer |
| The compiler or the R-code | all of the above that the change can reach, with the prelude regenerated; the self-hosting check (the compiler run on the JS host produces the same R-code) |
Windows code (IsWindows, NativeRun, the
WINDOWS branches of host-node.mjs and
hostfile-node.mjs, rvm.cmd) |
on Unix, the smoke test and the families it touches (with
RVM_WINDOWS_SHARING=1 for file sharing,
RVM_WINDOWS_HOSTEMU=1 for hostemu: the
hostemu- family); on Windows, the smoke tool,
--dir and --batch (16) |
The browser host (host-browser.mjs,
rvm-browser.mjs, compiler.mjs) |
the browser end-to-end run (rebuild the library first) |
The parser, or anything under bin/ the repository's
tests use |
cd tests && rexx RunTests.rex --fix (all suites
must pass) and the smoke test |
| A batch of fixes aimed at the official ooRexx test suite | the census before and after, compared with the last saved one |
Notes:
execRexxPrg in ooTest) run
on the RVM because the launchers set RVM_EXECUTABLE (13).rxapi daemon keeps registrations
between runs; after running the official suite, restart it
(pkill -x rxapi) before comparing with native, or REXXUTIL
registration tests fail natively..rcode
caches next to test programs, including those inside a copy of the
official suite.rexxcps, on both hosts, before and after. The timings of
this machine vary by 10% from run to run, even in CPU time; to compare
the ooRexx host, count instructions instead
(valgrind --tool=callgrind, a loop of two sizes: the
difference divided by the extra iterations). More code in the ooRexx
host costs a little on its own (the host's garbage collector marks it),
whether it runs or not.rexx,
with no expected files to keep up to date except for the deliberate
divergences. Following the standard where native differs would turn
every such place into a hand-maintained exception.tests/:
the self-hosting check, the browser end-to-end run and the rxregexp
fuzzer (16).