9. Reflection: executables, packages, contexts, environments


9. Reflection: executables, packages, contexts, environments

This chapter covers the parts of the object model that let a program look at and manipulate its own code and execution: the Method, Routine and Package classes, .context (RexxContext) and StackFrame, VariableReference, the environment symbols (.local, .environment, package-local directories, .ROUTINES and friends), NAMESPACE, and .RexxInfo. It assumes the object core of chapter 8 (RVM.Obj, behaviours, natives, RVM.Delegate) and the activation and variable model of chapter 5.

All the classes described here are builtin classes made by RVM.World~init (../RVM.Objects.cls; World in ../js/objects.mjs), not prelude classes. Their methods are natives dispatched by family prefix in RunNatives / callNative:

Family Class Native routine (ooRexx host / JS host)
M. Method MethodNative / methodNative
RT. Routine RoutineNative / routineNative
PK. Package PackageNative, PackageNew, PackageOptions, DefaultOptions / packageNative, packageOptions, defaultOptions
CX. RexxContext ContextNative / contextNative
SF. StackFrame StackFrameNative / stackFrameNative
VR. VariableReference VarRefNative / varRefNative
RI. RexxInfo RexxInfoNative / rexxInfoNative

(R is the key of methods written in Rexx, hence RT. for Routine.)

9.1 First-class objects over existing descriptors

Every reflective object is an RVM.Obj whose native value is a descriptor the machine already uses. The object is created on first request and cached in the descriptor, so identity is preserved (.c~method('FOO') == .c~method('foo')).

Object Native value Made by Cached in
Method RVM.Method (Method in JS) World~methodObject m~obj
Routine RVM.Routine (../RVM.Machine.cls) World~routineObject r~obj
Package RVM.Program (../RVM.Machine.cls) World~packageObject program~pkgObj
RexxContext RVM.Level (Level in ../js/context.mjs) World~contextObject level~ctx
StackFrame RVM.FrameInfo (FrameInfo) World~stackFrameObject not cached: a new object each time, as native
VariableReference RVM.VarRef (VarRef) World~newVarRef not cached: each >x makes a new one, as native
Stem RVM.Stem World~stemObjectOf stem~obj (see chapter 10)

An instance of a subclass (.MyMethod~new(...)) wraps a fresh descriptor and is not stored in its obj slot: only the base class's object represents the descriptor (MethodNative NEW: If receiver == world~methodClass Then m~obj = o).

9.2 Compiling source at run time

Method~new, Method~newFile, Routine~new, Routine~newFile, Package~new(name, source), Package~loadPackage(name, source), and the source forms of DEFINE/SETMETHOD/ENHANCED... all go through the run's source compiler, World~sourceCompiler:

  • ooRexx host: RVM.SourceCompiler (../RVM.Machine.cls), which calls CompileSource in-process (parser + RVM.Compiler + R-code read).
  • JS host: SourceCompiler (../js/machine.mjs), which calls host.compileSource(option, name, lines). Node (../js/host-node.mjs) spawns rexx rvm.rex -s OPTION; the browser (../js/host-browser.mjs) runs the compiler in-process (../js/compiler.mjs) when enableCompiler was called, and otherwise has no compileSource, so these methods raise 93.900 "compiling a source is not available in this RVM" (as INTERPRET does there; see chapter 14).

Every such source becomes an RVM.Program of its own whose parent is the context it was given, and whose kind says what it was compiled for:

Method Parser option kind Result
SourceCompiler~method METHOD (directives allowed, method = prolog, EXPOSE allowed) METHOD RVM.Method key R, home = the program
SourceCompiler~routine - ROUTINE RVM.Routine at address 1
SourceCompiler~package - "" the program
SourceCompiler~named - "" the program, once per name (ExternalsTable)
SourceCompiler~file — "" LoadProgram of a file found as ::REQUIRES finds it (43.901)
SourceCompiler~prolog — — the prolog of a program as an RVM.Routine, made once (prologObj)

A program's parent chain is followed by every lookup (classes in World~env/findClass, routines in findRoutine, namespaces, external routines in LoadExternal, FINDPROGRAM), so runtime code sees what its context sees. A source that does not parse leaves an RVM.NativeCall with compileAt set (a COMPILE stack frame, §9.6) and raises its error; the frame's package (compilePackage), and so the condition's PACKAGE, is a package with that name and the source and nothing in it (as native's that did not translate).

Installing. A method or a routine compiled from a source (Method~new, Routine~new, their newFile, and the sources of DEFINE, SETMETHOD, RUN, ENHANCED, SUBCLASS...) is installed when it is made, as native's LanguageParser does (installPackage): the packages it requires start (their prologs run), its classes are made (their ACTIVATE and class INIT run), before the native returns. A native cannot run that code, so the compile (MethodArg, Method and Routine NEW) records the program in the native's own RVM.NativeCall (PendingInstall; installs, with the class flag pending); after every native the machine looks at the flag, and InstallsFirst turns the native's result into one RVM.PackageRun per program, with install set and the native's result last. The machine runs each as a package started by a native (EnterPackageRun), but the frame returns as soon as the program is READY (no prolog; its entry is not traced), and then shows the stub routine's trace (InstallTrace: native calls a stub named as the package, whose >I>/<I< lines appear after the requires ran, when the package's ::OPTIONS TRACE shows them), and goes on with the native's result (the next install, a delegate such as NEW's INIT, or the value). An error while installing is the native's, with the lines of what ran. A program with nothing to install (no classes, no requires) is not run. Outside a native (no native line), a program is installed when it first runs.

Arguments (ooRexx's BaseExecutable::processExecutableSource): the source is a string (one line), an Array of strings (93.952 for a hole or a non-string item), anything answering REQUEST ARRAY, else its REQUEST STRING; otherwise 93.961 for NEW (93.974 for DEFINE, SETMETHOD, RUN) — SourceArg. The name goes through REQUEST STRING (88.909, MethodNameArg). The context argument (SourceContext) is a Method (its home program; a native method's is the REXX package), a Routine (its program), a Package, or the string PROGRAMSCOPE (the running program, also the default); .nil counts as the string "The NIL object"; another string is 40.904; any other object is made a string as native's requestString does (its REQUEST STRING, else its string value with the NOSTRING condition), so it is 40.904 too (native's 93.953 there is never raised). Arguments after the context go to INIT (the native ends with an RVM.Delegate to INIT).

newFile(name [, context]) reads the file as named (relative to the current directory, no search), strips trailing CRs, raises 3.1 if it cannot be read (SourceFileLines; JS sourceFileLines via executableArgs); the package is named after the file.

9.3 Method objects

Method objects come from ~method, ~methods, ~instanceMethod(s), .METHODS, Package~definedMethods, Method~new/newFile, and Method~loadExternalMethod(name, descriptor) (a method of an RVM library, see chapter 12; .nil if absent; a new Method each time, whose package is its code's: that of the first ::METHOD ... EXTERNAL that resolved the entry, RVM.World~libraryHome, or .nil).

RVM.Method fields used by reflection: flags (any of P private, R protected, K package, U unguarded, A attribute; - none — written by RVM.Compiler's MethodFlags), extent (l.c-l.c of the source in its home program, or -), home (the RVM.Program it was compiled in; .Nil for natives), scope, key (R Rexx code, A.GET/A.SET/A.CONST, ABSTRACT, L library...), annotations.

Method Implementation
SOURCE SourceOf: the lines of extent in home (ExtentLines); a ::method x; body starts after the ;; nothing between directives gives no lines
SCOPE m~scope, .nil for floating methods (SETMETHOD FLOAT leaves the scope .nil)
ISGUARDED, ISPRIVATE, ISPROTECTED, ISPACKAGE flags U (negated), P, R, K
ISABSTRACT, ISCONSTANT, ISATTRIBUTE key ABSTRACT, key A.CONST, flag A or key A.GET/A.SET
SETGUARDED, SETUNGUARDED, SETPRIVATE, SETPROTECTED rewrite flags (no result: 91.999 in an expression)
PACKAGE home's Package object; a native's is the REXX package
ANNOTATIONS, ANNOTATION World~annotationsOf / annotationOf (see chapter 8)
SETSECURITYMANAGER sets secMgr of the method's program; 0 for a native

SETPROTECTED and SETSECURITYMANAGER (of Method, Routine and Package), Package~options and .Package~defaultOptions are flagged R, like the natives ooRexx protects (Setup.cpp's AddProtectedMethod), so a security manager is consulted before they run.

9.4 Routine objects

Routine objects come from .ROUTINES, Package~routines/findRoutine..., Routine~new/newFile, Package~prolog, .context~executable and Routine~loadExternalRoutine(name, descriptor). A routine of a library is one Routine object per library entry (RVM.World~libraryRoutineObject / World.libraryRoutineObject, keyed by the entry), as ooRexx's package manager keeps them: loadExternalRoutine (by any name), a ::ROUTINE ... EXTERNAL (made when its package is installed, CheckExternals) and the StackFrame of the native routine running give the same object. Its source is empty, its name is the entry as first written, and its package is REXX for REXXUTIL's routines (ooRexx has them inside), otherwise that of the ::ROUTINE that made it first, or .nil (made by loadExternalRoutine or by a call by name). Its CALL runs the native with its line (Compiled routine "name"), and a wait (SysSleep) makes the activity wait.

CALL, [] and CALLWITH(array) (CallWithArgs: 98.913, 93.903, 93.902) do not run the routine inside the native: the native returns an RVM.RoutineCall(routine, args) and the machine continues at EnterRoutineCall (../RVM.Machine.cls; JS RoutineCall handled in ../js/machine.mjs). The routine runs as an external routine is called (native RexxCode::call, SUBROUTINE): a frame of kind RCALL entered via EnterProgram, PARSE SOURCE SUBROUTINE, default ADDRESS, its package's NUMERIC and TRACE settings, entry traced >I> Routine "X" in package "P". The native lines that led there (Compiled method "CALL" with scope "Routine".) are kept for the traceback, and the result is delivered as the message's result (DoReturn/Deliver); no result drops RESULT (or is 91.999 in an expression). A library routine (r~address == .Nil) is a native: the ooRexx host runs it at EnterRoutineCall, the JS host directly in routineNative.

SOURCE gives ExtentLines(extent, program) (a Routine~new routine: its prolog lines; a library routine: empty). A Routine has no NAME (97.1, as native).

EXPOSE or USE LOCAL as the first instruction of code that is not a method is accepted by the parser and fails at run time: 98.992 (machine, EXPO) and 98.993 (the compiler emits ERR 98.993 when the unit body is not a method body). The parser rejects them only under the +expose/+uselocal early checks of rxcheck.

Special environment symbols

Resolved by DotSpecial (../RVM.Machine.cls; dotSpecial in JS) after the normal environment search (§9.8) has failed, so .local~routines = x or a ::CLASS ROUTINES wins:

Symbol Value
.ROUTINES World~routinesTable(program): StringTable of all ::ROUTINEs (private too, and those ADDROUTINE added), uppercase, made once (routinesObj); none → the symbol's name
.METHODS World~methodsTable: the floating methods (before the first ::CLASS), made once (methodsObj); none → name
.RESOURCES World~resourcesTable: ::RESOURCE name → Array of lines, the same mutable StringTable; none → name
.LINE the line where the current clause starts (in INTERPRET data, the INTERPRET's)
.CONTEXT World~contextObject(context~level)
.RS level~rs (0, 1, -1); before any command, the name

The same applies to VALUE('.NAME') (RVM.Context~dotValue).

9.5 Package objects

A Package object wraps an RVM.Program. The REXX package is the prelude (World~rexxPackage, loading it if needed; object name "The REXX Package"). Its classes are the builtins plus the prelude's public classes (World~rexxClasses); its routines and floating methods are the RVM's own and are hidden (isRexx in PackageNative), as are the prelude's own classes (RVM.*: CLASSES leaves them out and FINDCLASS looks past them, in .local and .environment), and anything that would change it raises 98.984.

Method(s) Implementation
NAME, SOURCE, SOURCESIZE, SOURCELINE(n) p~path, p~source (93.924 for a bad n; beyond the end, "")
CLASSES, PUBLICCLASSES, IMPORTEDCLASSES, ROUTINES, PUBLICROUTINES, IMPORTEDROUTINES, DEFINEDMETHODS new StringTable copies (StringTableOf) of classObjs, publicClasses, importedClasses, routines, publicRoutines, importedRoutines, floating. public* hold the package's own; imported* the merged, transitive view of its ::REQUIRES (MergeRequired)
IMPORTEDPACKAGES Array of p~required
FINDCLASS, FINDPUBLICCLASS World~findClass / findPublicClass (order below)
FINDROUTINE, FINDPUBLICROUTINE both RVM.World~findRoutine (class method): native findPublicRoutine also finds private routines, and the RVM imitates it
FINDNAMESPACE, NAMESPACES World~findNamespace, p~namespaces (§9.9)
FINDPROGRAM SourceCompiler~findProgram: as an external routine is found, from the package's directory and its parents'; .nil
ADDCLASS, ADDPUBLICCLASS, ADDROUTINE, ADDPUBLICROUTINE write the tables (also .ROUTINES if made)
ADDPACKAGE(pkg [, namespace]) World~addPackage: once; MergeRequired
LOADPACKAGE(name [, source]) a file (SourceCompiler~file, from this package's directory) or named source (named), once per name; returns RVM.PackageRun
PROLOG SourceCompiler~prolog as a Routine (the same one); .nil for packages of Method~new/Routine~new and REXX
LOCAL the package-local Directory (localObj), made on demand
ANNOTATIONS, ANNOTATION, RESOURCES, RESOURCE see chapter 8; RESOURCES is a new copy (same Arrays)
DIGITS, FUZZ, FORM, TRACE, OPTIONS §9.5.2
SETSECURITYMANAGER, LOADLIBRARY p~secMgr; RVMLibrary + World~loadLibrary (1/0)

Methods that need the package's classes call World~ensureInstalled, which installs a program that has not started (installNow). A program with ::REQUIRES is always installed by then (§9.2), so the 93.900 that ensureInstalled keeps for one that is not is never reached.

9.5.1 Package~new and loadPackage

  • .Package~new(name) is the same program a ::REQUIRES name gets (SourceCompiler~file from the current directory, loaded once per run).
  • .Package~new(name, source [, context]) always makes a new program (SourceCompiler~package), whose parent is the context's package (a Method's home, a Routine's program, a Package; else 93.953); with no context it has no parent. The object is an instance of the receiver (a subclass of Package too), and after the prolog it is sent INIT with no arguments (native newRexx): the PackageRun's runInit, kept in the RCALL frame (initAfter), makes the frame's return send it as a delegate whose result is the package.

Both natives (and LOADPACKAGE) end by returning an RVM.PackageRun(program, result, addTo). The machine, at EnterPackageRun, runs the package's prolog if the program is still NEW — as a ::REQUIRES does (its own requires and classes first, StartPackage; PARSE SOURCE REQUIRES; zero arguments; default address) — in an RCALL frame whose result is the Package object (rOverride), and on return adds it to addTo (World~addPackage). An already started package is delivered at once. A package with ::OPTIONS NOPROLOG returns without running its prolog.

9.5.2 Options and defaultOptions

DIGITS, FUZZ, FORM, TRACE return the package's ::OPTIONS (PackageOption; the REXX package's TRACE is ""). OPTIONS with no arguments returns the settings as an ::OPTIONS directive string (SettingsString, native PackageSetting::toString; for REXX the trace is ?n/a?).

options(name [, value]) is a port of native PackageClass::options (PackageOptions / packageOptions): the option is chosen by its first letters — A(ll), D(igits), E(rror), FA(ilure), FO(rm), FU(zz), I(nitialOptions), L(ostdigits), NU(meric), NOS(tring), NOT(ready), NOV(alue), P(rolog), R(esetOptions), S(etOptions), T(race), X(explicitlyDefined) — and it returns the value before any change. The state lives in the program: the seven-word settingsLine (DIGITS FUZZ FORM TRACE NUMERIC PROLOG SYNTAX-conditions, see chapter 4 OPTIONS), initialLine (for I and R), explicit (X: the options its ::OPTIONS set, the eighth word of the R-code line). S compiles the string as a whole ::OPTIONS directive in a source of its own (SettingsOf; 93.900 if it is not one or contains ;, CR or LF). Errors follow native: 93.914, 93.903, 93.901, 93.902, 93.900 (empty value), 93.905/93.907/33.1 (DIGITS), 93.906/26.900 (FUZZ), 24.1 (TRACE).

.Package~defaultOptions("D"|"C" [, value]) (DefaultOptions, native clzOptions) reads or sets the world's default settings (World~overrideLine, initially 9 0 SCIENTIFIC N NOINHERIT 1 -) and the override count (overrideCount, initially 0). OverrideOptions (../RVM.Machine.cls; overrideOptions in ../js/machine.mjs) is applied whenever a package is made — a program file loaded (LoadProgram, FreshProgram), a source compiled — but not the prelude nor a macrospace macro: while the count is not 0, every option the package's ::OPTIONS did not set explicitly takes the default, and the count goes down by one (a negative count never reaches 0). Only an explicit PROLOG protects the prolog setting; NOPROLOG is overridden (native isExplicitPrologOption). Setting D itself compiles a string, so it counts as a package made.

.Package~defaultOptions('D', '::options digits 20')
.Package~defaultOptions('C', 1)
p = .Package~new('pk', 'say digits()')    -- 20
q = .Package~new('pk2', 'say digits()')   -- 9

9.6 RexxContext and StackFrame

Levels

Every activation has an RVM.Level (Level in ../js/context.mjs): type (PROGRAM, ROUTINE, METHOD, INTERNALCALL, INTERPRET), name, exec + kind (what runs: an RVM.Method M, an RVM.Routine R, or a program's prolog P), target, args, rs, ctx, active, parent (INTERPRET), id (invocation number, given on first request from a global counter), plus the lock, HALT, notify and FORWARD state described in chapter 7. JS levels also carry prog.

RVM.Context keeps the current level and a stack levels parallel to savedActivations (chapter 5):

  • pushActivation creates an INTERNALCALL level that runs the caller's code and inherits its .RS; popActivation closes it (and its INTERPRETs) and releases its scope lock.
  • The main program's level is the PROGRAM level RVM.Context starts with. EnterLevel (in the machine's EnterProgram and EnterMethod; JS enterLevel) retypes a new level as ROUTINE (::ROUTINE, external program, ::REQUIRES prolog, Routine CALL) or METHOD and sets exec, kind, target.
  • enterInterpret / leaveInterpret / clearInterprets give each INTERPRET its own level (its own StackFrame and invocation), whose parent is the activation it runs in.

Because every activation goes through push/pop, a level is closed however the activation ends (RETURN, EXIT, SIGNAL out, an error unwinding), and a RexxContext kept after that raises 98.981.

RexxContext

.context is World~contextObject(context~level): one object per activation. ContextNative first maps an INTERPRET level to its parent (INTERPRET code reports the enclosing activation's values), then answers from the activation's current state: the running context if it is the current level, else the caller's saved activation (RVM.Context~levelState).

Method Value
NAME, ARGS (new Array each time), EXECUTABLE (ExecObject: Method, Routine, or the prolog Routine for P), PACKAGE (LevelPackage), RS, INVOCATION from the level
DIGITS, FUZZ, FORM, LINE, CONDITION (a condition object copy) from levelState
VARIABLES Directory of the frame's variables with a value, by their own name (ownName: an alias made by USE ARG >y appears under the referenced variable's name); stems as Stem objects; in a method, the exposed variables
STACKFRAMES RVM.Context~stackFrames(.True): the frames now, without the STACKFRAMES native's own
THREAD the activity the activation runs in (1 for the main program), noted on its level when .CONTEXT makes the object (level~thread), so asked from another activity it is still the activation's; INTERPRETER is always 1
NEW, COPY 93.967, 93.970

StackFrames

Stack frames come from the same walk that builds a traceback, RVM.Context~stackLines (chapter 6): each line carries an RVM.FrameInfo as its fifth element (JS index 4), built by FrameInfo~ofLevel for an activation or FrameInfo~ofNative for a native (an RVM.NativeCall: method, receiver, message, args; or only a "Compiled method" line of a stream object). stackFrames wraps each in a new StackFrame object. The condition object's STACKFRAMES (a List made once), TRACEBACK and PACKAGE (the innermost frame with a package) use the same data.

Field Value
TYPE PROGRAM, ROUTINE (also external programs, ::REQUIRES prologs, Routine CALL, native routines: Compiled routine), METHOD (also natives: NEW, SEND, Routine CALL...), INTERNALCALL, INTERPRET, COMPILE (a runtime source that does not parse: NativeCall~compileAt)
NAME, LINE (.nil for natives), TRACELINE (= STRING = MAKESTRING, and its string value wherever one is taken: SAY, concatenation, trace, the items of an Array's toString) from the line
EXECUTABLE, TARGET, ARGUMENTS ExecObject, receiver, a new Array
INVOCATION, CONTEXT from the level; .nil for natives and COMPILE frames

9.7 Variables as objects; VariableReference

Both hosts model a variable as a cell shared by every frame that sees it (chapter 5): RVM.Var (a value attribute, .Nil = no value; ../RVM.BaseContext.cls) in frames that are RVM.Vars (Directory name → Var; method frames and object pools are RVM.Vars too), and { v } cells in JS frame slots. EXPOSE and PROCEDURE EXPOSE put the same cell in the callee frame; nothing is copied back. This is the native RexxVariable model (RexxVariable.cpp), and it is what makes references possible.

>x and >a. (operand, or argument) compile to VREF name: the machine takes the local variable's cell (creating it, valueless, if absent) and makes a new VariableReference, World~newVarRef(cell, name), wrapping an RVM.VarRef (var/cell, name, isStem). Trace: >O> ">" => "X".

USE ARG >v / >s. compile to USEREF i name; UseRef (../RVM.Machine.cls) checks, in native order (UseArgVariableRef.cpp): omitted 88.931, not a reference 88.928, stem/simple mismatch 88.929/88.930 (inserting the referenced name), the local variable must be aliasable (no value; a stem: empty with its own name as default) else 98.995; then the frame slot is pointed at the referenced cell (aliasVar; the frame records the alias's own name), traced >R> with TRACE R or I.

VariableReference methods (VarRefNative):

Method Behaviour
NAME the referenced variable's name
VALUE VarRef~resolved: the value; no value → the name; a stem → its Stem object (the stem is made if needed)
VALUE= VarRef~assign (argument required, 88.901 VALUE): a simple variable takes the value; a stem variable takes a Stem object's stem, or a new stem with that default
UNKNOWN, REQUEST forwarded to the value by RVM.Delegate
=, ==, \=, \==, <>, >< hidden (.Nil in the method table), so they reach UNKNOWN and the value
NEW 93.967

Native quirks reproduced: the string value of a reference is the primitive string value of its value (VarRef~string: an object's default object name even if it defines STRING; say r shows a FOO, length(r) is 5); forwarding to the value does not add an "UNKNOWN" traceback line; and .context~variables lists an aliased variable under the referenced name.

9.8 Environment symbols, .local and .environment

Resolution order

World~env(symbol, program, specials) (ooRexx's PackageClass::findClass plus the dot-variable rules) resolves .NAME in this order:

  1. the program's classes (classObjs), then its imported public classes, then the same for each parent (runtime-compiled code);
  2. the builtins (World~builtins: the builtin classes, NIL, TRUE, FALSE) — classes and .nil before .local, as native (.local~object = 5; say .object shows the class) — and then the prelude's public classes (the rest of the REXX package's), when it is loaded (before that, nothing can be in the directories below: a message to any of them loads it);
  3. the package-local directory (Package~local);
  4. the security manager's LOCAL event, then .local;
  5. the security manager's ENVIRONMENT event, then .environment;
  6. with specials (the ENV instruction, dotValue): .nil, so the caller tries DotSpecial (§9.4);
  7. otherwise, if the prelude is not loaded yet, load it and retry; finally the symbol itself (.FOO → .FOO).

What is kept. As native's RexxDotVariable, the ENV instruction keeps what it found in steps 1 and 2 (World~envCached says so): the next evaluation of that name in the same program gives it without a search, so a later Package~addClass of the same name is not seen there; what came from the directories, the security manager or .environment is looked up every time. Native's parser makes one dot variable per name for a whole package (its dotVariables), so the RVM keeps one per name per RVM.Program (envCache); an external program called again is a fresh program, with an empty one. INTERPRET's code (from fragStart on) is parsed anew each time natively, so nothing found there is kept.

Package~findClass uses World~findClass instead, which follows native PackageClass::findClass order: the installed classes of the program and its parents, the public classes it sees (own, imported, parents', then the REXX package's), the package-local directory, .local, .environment.

.environment holds every builtin under its name, LOCAL, ENVIRONMENT, ENDOFLINE, REXXINFO, and the prelude's public classes (the prelude's prolog registers them, as CoreClasses does; ensurePrelude adds those of prelude-streams.orx). Since the prelude is loaded when first needed, a message to .environment (or COPY, or DO OVER it) loads it first, so the directory always shows them (68 entries: native's 69 without WEAKREFERENCE, see 17). .local ("The Local Directory") is empty until mounted.

.local is lazy

Native ooRexx builds .local at instance start (Interpreter::initLocal runs .LocalServer~new from CoreClasses.orx: STDIN/STDOUT/STDERR streams, the INPUT/OUTPUT/ERROR/TRACEOUTPUT/DEBUGINPUT monitors, STDQUE, SYSCARGS), and every SAY and default-stream BIF goes through those monitors.

The RVM mounts .local when it is first observable (World~ensureLocal, states "", MAKING, MADE): when env looks up one of LOCALNAMES (LOCAL STDIN INPUT DEBUGINPUT STDOUT OUTPUT STDERR ERROR TRACEOUTPUT STDQUE SYSCARGS) or a Directory native gets .local as receiver. Mounting sends .LocalServer~new synchronously (PreludeLoader~sendSync), registers STDQUE with RVM.Queues, sets SYSCARGS from RVM.Context~syscargs (set by the launchers; .False means none, as rexx -e), and remembers each monitor and its original destination (localOrig, localDest).

Until then, and afterwards while a monitor is still the original one and still has its single original destination, World~localTarget(name) answers .Nil and SAY / stream BIFs write straight to the host. Otherwise the instruction sends to the object: SAY via DoSend (mode SENDA), stream BIFs by returning an RVM.BifSend that the instruction sends (FUNCB/CALLB, delivered by Deliver BIF); where no instruction can carry the send (computed CALL, PARSE PULL, PARSE LINEIN) it is sent at once (BifNow, sendSync). A .nil entry makes SAY write directly and the functions send to .nil (97.1, as native). Trace lines use World~traceObject, which sends a TraceObject to .TRACEOUTPUT only when that is observable.

RVM_LOCAL=eager (read in World~init; JS reads host.getEnv in the machine's run) mounts .local when the main activity starts and disables the fast path: every SAY and stream BIF goes through the objects, exactly as native. The two modes give the same results and errors.

9.9 NAMESPACE

::REQUIRES "f" NAMESPACE ns (R-code REQUIRES with NAMESPACE "NS", see chapter 4) registers the required program in program~namespaces when the package starts (StartPackage); Package~addPackage(p, ns) does the same at run time. World~findNamespace looks the name up in the program and then up its parent chain; REXX is always the REXX package.

Source R-code Resolution Error
.ns:Cls, ns:Cls as a term NSCLASS ns name World~namespaceClass: a public class of that package (REXX: the REXX public classes) 98.987 no namespace, 98.988 no class
ns:f(...) FUNCNS RVM.World~findPublicRoutine in that package 43.902
CALL ns:f CALLNS same 43.902
::CLASS ... SUBCLASS ns:C (also MIXINCLASS, METACLASS, INHERIT) names written NS:NAME resolved only in that package by the installer 98.987/98.988

9.10 .RexxInfo

.RexxInfo is the single instance of the builtin class RexxInfo, stored in .environment['REXXINFO'] (NEW 93.967, COPY 93.970).

Group Values
NAME, LANGUAGELEVEL, DATE from PARSE VERSION (RVM.Context~VERSION; JS VERSION): REXX-RVM-ooRexx-<version> 6.06 <date> or REXX-RVM-JavaScript-...
VERSION, MAJORVERSION, RELEASE, MODIFICATION, REVISION the ooRexx release the RVM ports (5.3.0, r13237), hard-coded in both hosts
DIGITS, INTERNALDIGITS, FUZZ, FORM, INTERNALMAXNUMBER, INTERNALMINNUMBER, MAXEXPONENT, MINEXPONENT, MAXARRAYSIZE, DEBUG the native 64-bit constants
PLATFORM, ARCHITECTURE, ENDOFLINE, PATHSEPARATOR, DIRECTORYSEPARATOR, CASESENSITIVEFILES, MAXPATHLENGTH the host's: ooRexx's own .RexxInfo; Node host.rexxInfo() / systemName(); defaults in the browser
EXECUTABLE a File: RVM_EXECUTABLE (set by the launchers) if set, else the host's rexx (ooRexx) / node (JS); .nil in the browser
LIBRARYPATH a File: the directory of RVM.Objects.cls (ooRexx) / of the .mjs modules (JS)
PACKAGE the REXX package

File objects are made with World~fileObject (a synchronous .File~new).

9.11 Host differences

Topic ooRexx host JS host
Runtime compilation in-process CompileSource Node: rexx rvm.rex -s per source; browser: in-process compiler if enabled, else 93.900
Library routine CALL run at EnterRoutineCall run inside routineNative
Invocation counter RVM.Level~counter class attribute module variable levelCounter
Variable cells RVM.Var in RVM.Vars Directories { v } in frame slots, Frame.pool, aliasSlot
RVM_LOCAL Value(..., "ENVIRONMENT") in World~init host.getEnv at run start
.RexxInfo platform ooRexx's .RexxInfo host.rexxInfo()

Design notes

  • Builtin classes over existing descriptors. Method, Routine, Package, RexxContext and StackFrame wrap the structures the machine already runs (RVM.Method, RVM.Routine, RVM.Program, RVM.Level, RVM.FrameInfo) instead of parallel copies. Identity comes free (one object per descriptor, cached in it), there is nothing to keep in sync, and the reflective view is by construction what actually runs.
  • Natives never run user code. Routine CALL, Package~new and loadPackage return a request (RVM.RoutineCall, RVM.PackageRun) that the machine executes in a normal frame, as NEW delegates to INIT; the install of a source compiled by a native is such a request too, added by the machine after the native returns, so that no native has to change its result. This keeps the machine non-reentrant (see chapter 5) and gives correct tracebacks, traps and stack frames for code started from a native.
  • Runtime sources are packages of their own with a parent. Native ooRexx gives every Method~new/Routine~new its own package that sees its context's; modelling that as RVM.Program~parent, followed by every lookup, reproduces visibility without copying tables.
  • One level per activation, pushed and popped with it. Keeping levels parallel to savedActivations and closing levels in popActivation means no exit path (RETURN, EXIT, SIGNAL, error unwind) has to remember to invalidate a RexxContext. Stack frames and tracebacks come from the same walk (stackLines), so they cannot disagree (RVM_TBCHECK compares the report with the TRACEBACK).
  • Cells for variables. References need a variable that outlives its activation; sharing cells (the native RexxVariable model) also makes PROCEDURE EXPOSE and EXPOSE exact without copy-back. The ooRexx host's RVM.Var has no INIT because an INIT costs a method run per variable; only cells watched by GUARD WHEN pay for a custom VALUE= (watchBy).
  • .local lazy and invisible. Building .LocalServer and routing every SAY through monitor objects is costly and, until a program looks, not observable. The fast path keeps output identical; RVM_LOCAL=eager exists to check that claim and to run exactly as native. Sends from SAY and stream BIFs are issued from the instruction rather than by sendSync so an error in a redirected stream gets its full traceback.
  • .RexxInfo reports the ported ooRexx version, so programs and the official test suite that check versions behave as on native; PARSE VERSION still names the RVM. EXECUTABLE is the RVM launcher so that a program that spawns "the interpreter" spawns the RVM.

Known gaps

  • INTERPRETER is always 1; invocation numbers are distinct and stable but not native's values.
  • In the browser without the compiler enabled, every runtime-source method (Method~new, Routine~new, Package~new(name, source), DEFINE with source...) raises 93.900.