This chapter describes the object core of the RVM in both hosts: how
an object is represented, how behaviours (method dictionaries) are
built, how a message is sent and a method found (scopes, the method
resolution order, SUPER, ~~, FORWARD), how classes,
metaclasses and mixins are made, the directives that define them
(::CLASS, ::METHOD, ::ATTRIBUTE,
::CONSTANT, ::ANNOTATE), object-to-string
conversion and NOSTRING, SETMETHOD and friends, HASHCODE and equality,
and the security manager. It assumes the value model of 02-values-and-arithmetic.md and
the machine loop of 05-machine.md. Method,
Routine, Package, .context, StackFrame, VariableReference
and .local are in 09-reflection.md; the prelude and the
collection classes in 10-prelude-and-classes.md; GUARD,
Message, activities and UNINIT in 07-concurrency.md.
Code: ../RVM.Objects.cls and ../js/objects.mjs (the object
model, both CPL: derived from ooRexx's RexxBehaviour.cpp,
MethodDictionary.cpp, ClassClass.cpp and the
classes' C++ code); the send path in the machine (../RVM.Machine.cls: labels
DoSend, SendLoop, SendDone,
Delegated, Deliver, NeedString,
EnterMethod; ../js/machine.mjs:
doSend, sendLoop, sendDone,
deliver, enterMethod); the directives in ../RVM.Compiler.cls
(CompileDirectives, ClassEntry,
MethodFlags, ConstantInitializer,
CompileAnnotations). The JS host has no compiler of its
own: it runs R-code made by RVM.Compiler, whether that runs
on the ooRexx host or, in the browser, on the JS RVM itself (14-javascript.md).
| Layer | What | Where |
|---|---|---|
| 0. Host leaves | strings, numbers, host maps/arrays, I/O, clock | the host language |
| 1. RVM objects | an object = behaviour + variable pools + native value; a behaviour = a method table; a method = R-code or a native | RVM.Obj, RVM.Behaviour,
RVM.Method / Obj, Behaviour,
Method |
| 2. ooRexx model | classes, metaclasses, scopes, mixins, SUPER, SETMETHOD | RVM.ClassData, RVM.World /
ClassData, World |
Layer 1 is deliberately small (a "table plus metatable" model): the ooRexx semantics live entirely in how layer 2 builds behaviours, not in the send path.
Strings and numbers are not boxed. A host string
(.String / JS string) or a number (RVM.Number
/ RexxNumber) has the instance behaviour of the String
class "by type": World~behaviourOf(v) returns
instanceBehaviour(stringClass) and
World~classOf(v) returns .String for anything
that is not an RVM.Obj. .nil is an
RVM.Obj (the world's nil, an instance of
Object named "The NIL object"), never the host's .nil.
RVM.Obj / Obj| Field | Meaning |
|---|---|
beh |
its behaviour (RVM.Behaviour); beh~cls is
its class |
native |
its native value: a class's RVM.ClassData; a
Directory's host Directory; an Array's host array (JS
RArray); a Stem's RVM.Stem; a Method's
RVM.Method; a String subclass instance's string;
.Nil for a plain object |
objName |
its OBJECTNAME, or .Nil (then defaultName:
"The X class", "an X", "enhanced X") |
pools |
its variable pools, one per scope (an IdentityTable /
Map scope → RVM.Pool), made on first use
(pool(scope)) |
oid |
identity number (IDENTITYHASH; the basis of Object's HASHCODE) |
dirMethods |
a Directory's SETMETHOD entries (RVM.DirMethods) |
The native value a new instance gets is chosen by the class's
kind (World~newInstance): OBJECT
(none), DIRECTORY, ARRAY,
SUPPLIER, TABLE, IDTABLE,
QUEUE, STEM,
LIST/SET/... (made by INIT, see 10), CLASS (a
metaclass: see Metaclasses). A subclass
inherits its superclass's kind, so a subclass of Directory is an
RVM.Obj whose native is a Directory.
In an error message an object is shown by its object name, never by
its STRING (ObjectText; the condition's ADDITIONAL holds
the object itself).
RVM.World / World is the universe of one
run (held by the context). Its init makes the primitive
classes with bareClass (Object, Class, String, Directory,
Array, Supplier, Table, IdentityTable, StringTable, List, Queue, Set,
Bag, Relation, Method, Routine, Package, RexxContext, StackFrame,
Buffer, Pointer, Stem, Message, EventSemaphore, MutexSemaphore,
MutableBuffer, VariableReference, RexxInfo), each with metaclass Class,
and defines their native methods with a compact spec:
Call Methods objectClass, "I", "HASMETHOD 1 1 O.HASMETHOD;" "SEND 1 -1 O.SEND message name;" ...
Each item is NAME min max KEY [argName] (JS
defineMethods): the argument counts checked by
CheckMethodArgs / checkArgs before the native
runs (93.902 too many; a missing required one is 88.901 naming
argName, or 93.903), and the key FAMILY.WHAT
that CallNative / callNative dispatches
on.
| Family | Natives of | Family | Natives of |
|---|---|---|---|
O |
Object | C |
Class |
S (via StringMethods) |
String | D |
Directory, StringTable, Table, IdentityTable |
V |
Array | L / H |
List, Queue / Set, Bag, Relation |
U |
Supplier | ST |
Stem |
M / RT / PK |
Method / Routine / Package | CX / SF / RI |
RexxContext / StackFrame / RexxInfo |
MS |
Message | ES / MX |
EventSemaphore / MutexSemaphore |
MB |
MutableBuffer | VR |
VariableReference |
A.GET A.SET A.CONST
A.DELEGATE |
attributes, constants, DELEGATE methods | X.f |
EXTERNAL 'LIBRARY REXX f' methods |
L (key alone) |
other EXTERNAL methods (libraries) |
ABSTRACT |
abstract methods (93.965) |
After the natives, init copies Object's instance methods
into its class methods (ooRexx's buildFinalClassBehaviour:
every class answers them), marks every primitive class
primitive, rexx (a class of the REXX package)
and its own baseClass, builds the class behaviours, and
creates .nil, .local ("The Local Directory"),
.environment ("The Environment Directory") and the
builtins table (the classes, NIL, TRUE, FALSE), which is
also copied into .environment with LOCAL, ENVIRONMENT,
ENDOFLINE and REXXINFO. Name resolution of environment symbols
(World~env, World~findClass) is described in
09-reflection.md.
RVM.Behaviour / Behaviour is a port of
RexxBehaviour plus MethodDictionary:
| Field | Meaning |
|---|---|
cls |
the class of the objects that have it |
contents |
NAME → list of methods, all the methods of that
name that were merged in, the one found first first; a hidden entry
(RVM.Behaviour~hidden / HIDDEN, ooRexx's
.nil in the table) hides the rest |
scopeList |
its scopes (classes), in the order they were added |
scopeOrders |
scope → the scopes that were before it when it was added |
instMethods |
the methods SETMETHOD added (NAME → method), or
.Nil |
enhanced |
the behaviour of an object made by ENHANCED (its default name) |
Operations: lookup(name) (first entry; hidden → none);
addMethod (a method with the same scope replaces the old
one in place, any other goes first; a hidden one always goes first);
mergeTable (a class's own table);
mergeBehaviour; addScope;
superMethod(name, start) (ooRexx's
findSuperMethod: the first method whose scope is
start or one of the scopes before it);
superScope(scope) (ooRexx's resolveSuperScope:
the last scope before it; for a method with no scope, the behaviour's
class); addInstanceMethod /
removeInstanceMethod (SETMETHOD, UNSETMETHOD);
allMethods(scope) (INSTANCEMETHODS, METHODS: shadowed
methods included, so STRING appears twice when a class redefines it);
copyBehaviour / copy.
World~createInstanceBehaviour(c, b) is
RexxClass::createInstanceBehaviour: the superclasses of
c (its superclass, then the classes it inherits, in INHERIT
order) are processed from the last to the first, each
recursively and each only once (a scope already in b is
skipped), then c's own instance methods are merged and
c is added as a scope. Because each merge puts its methods
first, the result is: the class, then its first superclass chain, with
each mixin placed just above the class that inherited it.
::class y ; ::method who; return "y"
::class m1 mixinclass y ; ::method who; return "m1>" || self~who:super
::class m2 mixinclass y ; ::method who; return "m2>" || self~who:super
::class g subclass y inherit m1 m2
::method who; return "g>" || self~who:super
::class x subclass g
::method who; return "x>" || self~who:super
.x~new~who gives x>g>m1>m2>y;
.x~new~who:.m1 gives m1>m2>y (same in
native ooRexx and both hosts).
World~createClassBehaviour(c, b) is the class side:
superclasses' class methods (last to first, recursively), then — if not
already there — the instance behaviour of c's metaclass,
then c's own class methods, scope c. Object's
class behaviour is special (buildClassBehaviour): its class
methods (which include its instance methods) plus Class's instance
behaviour. A behaviour is rebuilt in place
(clear and merge again), so every object holding it sees
the change:
| Change | What is rebuilt | Who sees it |
|---|---|---|
INHERIT, UNINHERIT (updateSubClasses) |
both behaviours of the class and of all its subclasses | existing instances too |
DEFINE, DELETE, DEFINEMETHODS (newInstanceBehaviour +
updateInstanceSubClasses) |
the class first gets a copy of its instance behaviour, then that copy and the subclasses' are rebuilt | new instances of the class; existing instances of the class keep the old one (and, being detached, later INHERITs do not reach them either); existing instances of subclasses see it |
loading the prelude (World~refresh) |
every non-bare class | everybody |
A message term compiles to one instruction, after the receiver, the
optional scope (SCOPE) and the arguments (04-rcode.md):
| Instruction | Source | Result (Deliver mode) |
|---|---|---|
SEND name n s |
o~m(...), o[...] |
on the stack (none: 91.999) |
CASC name n s |
o~~m(...) |
the receiver on the stack |
SENDI name n N / C |
message instruction o~m / o~~m |
RESULT set (dropped if none) / RESULT = receiver |
SENDA name= n s |
o~m = v, o[i] = v (value first, then the
arguments) |
discarded |
SCOPE |
~m:scope |
checks the scope (below) |
FWD, FWDOK |
FORWARD | see FORWARD |
Message names are upper-cased at compile time. The last operand
s (0/1) says whether a scope is on the stack under the
arguments; the scope is a term (environment symbol, variable — including
SUPER —, stem or compound), evaluated after the receiver and before the
arguments.
Operators are messages too: when the left operand of
an arithmetic, comparison or concatenation operator is an object, the
machine sends the operator (SendOperator; "\="
as written, abuttal "", blank concatenation
" "; a prefix operator with no argument); the result is
traced >O> (>P> for prefix). An
object on the right is converted to a string. String's
own operators are also callable as messages ('1'~'+'(2):
StringOperator). Comparison of objects with
.nil follows the rules in 02.
The parser accepts some forms that are not ooRexx 5 (invoked terms
x~(), messages without a name, trailing blocks); the
compiler emits a 93.900 "not supported" for them.
DoSend (JS doSend) receives receiver, name,
arguments, start scope and a Deliver mode.
SendLoop (JS sendLoop) then:
Lookup / lookup):
with no start scope, behaviourOf(receiver)~lookup(name);
with a start scope, 93.957 if it is not one of the receiver's scopes,
else superMethod(name, start).ensurePrelude and look again (Native and prelude methods).sendSync; not for a delegate that runs a given
method, native's method->run): PRIVATE
(P) — allowed when the sender is the receiver, or an
instance of the method's scope, or a class that is the scope or a
subclass of it (PrivateOK, native checkPrivate
with isCompatibleWith); PACKAGE (K) — allowed
when the running code is of the method's home package, or of the REXX
package (PackageOK); otherwise the method is treated as
absent (UNKNOWN, NOMETHOD, then 97.2 / 97.3). The sender
(curSender) is the receiver of the running method,
.Nil at program and routine level (the activation's
level~sender, which internal routines and INTERPRETs
share). A native's message is checked with the sender and package of the
code that called the native: native ooRexx's C++ methods have no
activation, so messageSend sees the caller's. So
.Foo~new with a private INIT is 97.2 from outside the class
and works from a class method of Foo or of a subclass; a private
ACTIVATE or INHERIT is 97.2 (the install has no sender); a private
MAKEARRAY makes DO OVER fail outside the class.R) with a security manager
in the activation: the manager gets METHOD (Security manager).processUnknown).(name, Array of args), a native one the host
argument array. Neither → the NOMETHOD condition (DESCRIPTION the
message name, ADDITIONAL the receiver; only SIGNAL ON NOMETHOD/ANY traps
it) and, untrapped, 97.1 (97.2/97.3 when the method existed but was not
accessible).key == "R")
enters a new activation (EnterMethod); a native is called
(CallNative) after its argument check, with a
RVM.NativeCall pushed on context~nativeLines
(it gives the traceback line
Compiled method "NAME" with scope "Class". and a METHOD
StackFrame; attributes and abstract methods push none, as native ooRexx
shows none).EnterMethod pushes a frame and an activation level
(EnterLevel, type METHOD; for an UNKNOWN the activation's
name is UNKNOWN), switches to the method's program if it belongs to
another package, installs an RVM.MethodFrame on the pool of
the method's scope (receiver~pool(m~scope)), sets SELF and
SUPER (behaviourOf(receiver)~superScope(m~scope),
.nil if none), traces
>I> Method "NAME" with scope "C" in package "P". when
tracing, and — unless the method is UNGUARDED (U) or
compiled — takes the scope's lock, possibly waiting (07-concurrency.md).
A native never runs user code itself. When it must send a message it
returns an RVM.Delegate /
Delegate (receiver, name, args, optional
scope, optional method to run instead of
looking up, optional result that replaces the delegated
message's result, optional then). The machine
(Delegated) sends it through the same
SendLoop; on return, SendDone pops the pending
delegates (sPend): a non-.Nil
result replaces the value, and a then object's
next(v, context) may return another delegate, so one native
can chain several messages:
| Native | Chain |
|---|---|
| Object NEW | new instance; delegate INIT with result = the
instance |
| REQUEST(c) | MAKEc, then RVM.OrNil (no result →
.nil) |
| SEND, SENDWITH | the message (with the array's scope) |
| SUBCLASS, MIXINCLASS | RVM.MakeClass: metaclass NEW → finish → INIT |
| ENHANCED | RVM.Enhance: SUBCLASS → methods → NEW |
| RUN | the method with name *UNNAMED* |
| DELEGATE methods | the same message to the object in the variable |
Every delegated message is checked for PRIVATE and PACKAGE as the
message itself (with the caller's sender and package), unless the
delegate names the method to run (RUN,
::CONSTANT initializers, the prelude's sort, a Directory's
entry methods).
Other native results the machine understands:
RVM.RoutineCall (Routine CALL), RVM.PackageRun
(run a package's prolog, or only install it before the native's result:
09),
RVM.StartMessage, RVM.Wait,
RVM.Reraise (concurrency, 07).
Where a native genuinely needs a result before it can go on (asking a
security manager; HASHCODE and == of user objects used as
hash keys; making a .File for RexxInfo), it uses
sendSync (RVM.Machine~sendSync, through
PreludeLoader~sendSync): a nested run of the machine to the
end of that one message; when it waits, the other activities run in
place (07), and its
errors propagate to the caller.
Deliver (JS deliver) routes the result by
mode: SEND/OP/PREFIX (stack,
91.999 if none, trace
>M>/>O>/>P>),
CASC, SENDI N/C,
SENDA, CASEEQ (SELECT CASE),
STRING/REQUEST (conversions, below),
WITH/WAVAIL/WSET/WPUSH
(DO WITH), FWD/FWDC (FORWARD),
BIF (stream functions sent to .local objects),
SYNC (sendSync), and
START/FAILED/UNWIND/UNINIT
(activities).
~m:scope searches from that scope along the
receiver's behaviour, not along the scope class's own
superclass chain. The SCOPE instruction checks that the
scope is a class (88.914 "SCOPE") and one of the receiver's scopes
(93.957 "Target object "a C" is not a subclass of the message override
scope (The OTHER class)."). SUPER, set on method entry, is the scope
just before the method's in the receiver's behaviour; so with mixins,
SUPER in x is g, in g is
m1, in m1 is m2 (example above).
~m:super simply reads the variable SUPER (an assignment
super = .a changes it). A method with no scope (SETMETHOD
FLOAT, ENHANCED) has the receiver's class as SUPER.
On a class object the scopes are those of its class behaviour: its class methods' chain, then the metaclass instance methods.
SEND, SENDWITH, START, STARTWITH accept as message either a name or a
2-item Array (name, scope) (MessageName: name
88.901/88.909 "message name", scope 88.914 "SCOPE", wrong size 93.946,
another object 93.972). SENDWITH's argument list is an Array (one
dimension), a collection (List and Queue: items; Set, Bag, Relation,
Directory, Table: indexes) or a string (its lines), else 88.913
(MessageArguments).
FWDOK gives 98.947 outside a method activation.
FWD pops TO, MESSAGE, CLASS, ARGUMENTS/ARRAY (defaults:
SELF, the method's name, no scope, the activation's arguments); ARRAY
must be a one-dimensional Array (98.946); CLASS must be a class (88.914)
and one of the new receiver's scopes (93.957). Without CONTINUE the
activation becomes a phantom (level~forwarded): its traps
no longer see errors, and the forwarded result is the method's result
(FWD); with CONTINUE the result goes to RESULT
(FWDC). A condition raised in the phantom itself (a
NOTREADY of the stream it forwards to, as .INPUT's Monitor
does; a NOMETHOD of the send; a HALT) is the caller's
(RVM.Context~raiseCondition → callerRaise,
ooRexx's RexxActivation::trap with
isForwarded): a SIGNAL ON trap there unwinds to it, a CALL
ON trap is queued for it, and the phantom's own traps do not see it.
Each object has one pool per scope; a method's EXPOSE binds against
the pool of the method's scope (RVM.MethodFrame~share), so
a subclass's v and its superclass's v are
different variables, and a mixin's methods have their own pool. Exposed
variables are the pool's cells themselves (every activation exposing
them shares them); an exposed compound shares the element. USE LOCAL
makes every non-local name the object's variable from its first
reference on (useLocal/resolve, ooRexx's
autoExpose). A pool is also the GUARD lock of that object and scope.
Details: 05, 07.
A class is an RVM.Obj whose native value is an
RVM.ClassData / ClassData (a port of
RexxClass) and whose behaviour is its class behaviour
(beh~cls = its metaclass).
| Field | Meaning |
|---|---|
id |
its id as given |
superclass, superclasses |
first superclass; superclass then the inherited mixins |
subclasses |
classes made from it or inheriting it, the latest first |
imethods, cmethods |
its own instance / class methods: NAME → method (.Nil:
hidden by DEFINE) |
metaclass, isMeta |
its metaclass; is it a metaclass (Class or a subclass) |
kind |
what its instances wrap (see above) |
instBeh |
its instance behaviour, made on first use |
mixin, baseClass |
MIXINCLASS; its base class (a mixin's is its superclass's) |
primitive |
made by the world, not by SUBCLASS/NEW |
bare |
made by Class's NEW: its behaviours are copies, never rebuilt |
rexx |
a class of the REXX package: DEFINE, DELETE, INHERIT... → 98.985 |
home |
the program of its ::CLASS (PACKAGE); .Nil
for dynamic classes |
abstract, annotations |
ABSTRACT; ::ANNOTATE CLASS pairs |
When a program starts (05, program state
CLASSES → READY), World~install (JS
World.prototype.install) mirrors ooRexx's
PackageClass::processInstall and
ClassDirective::install:
MergeRequired), makes RVM.Methods from the
R-code METHODS table (floating methods, instance, class and
constant-initializer methods);RVM.Installer / Installer, a state
machine fed by delegates. Per class: resolve the metaclass (98.908) and
the superclass (98.909; namespaced references through
namespaceClass; a name bound to a non-class is 99.949);
send SUBCLASS or MIXINCLASS to the superclass with the metaclass and the
class methods (so the class's class INIT runs here,
before its INHERITs and instance methods); make the
class visible; send INHERIT for each mixin (a redefined INHERIT would
run); add the instance methods (scope = the class) and rebuild; set
annotations and ABSTRACT (98.990 if the class is a metaclass);Errors carry the ::CLASS directive's clause.
World~subclass(receiver, id, meta, methods, ...) checks
the metaclass (99.927 if not a metaclass) and returns a delegate sending
NEW (with the id) to the metaclass; RVM.MakeClass then
calls finishSubclass (superclass, kind, class methods with
their scope, both behaviours, registration as a subclass, UNINIT
tracking), sends INIT again to the new class, and for
MIXINCLASS marks it a mixin after INIT. The metaclass's INIT therefore
runs twice per class — a native ooRexx behaviour the RVM reproduces. The
class methods argument and DEFINEMETHODS/ENHANCED accept any object with
a SUPPLIER (MethodTable). A class made by SUBCLASS has no
package, no annotations and is never abstract. If a redefined metaclass
NEW returns something that is not a class, the RVM raises 93.900 (native
ooRexx crashes: 17).
A metaclass instantiated through Object's NEW
(.meta~new:.object) is a plain object of that class
(newInstance), as native's RexxObject::newRexx
makes: its own methods, CLASS, ISA, its name. It has Class's instance
methods but is no class: COPY (93.970), DEFAULTNAME and HASHCODE answer
as an object's, and the others raise 93.900 (native reads a class it is
not: 17).
.class~new(id, ...) (Class's own NEW,
newClassOf) makes a bare class: an instance of
the receiving metaclass, a subclass of Object with an instance behaviour
copied from Object's (so without NEW: .class~new('Z')~new
is 97.1, as in native ooRexx), INIT sent with the remaining
arguments.
ENHANCED(methods, args...) makes a subclass "Enhanced Subclass",
gives it the methods with scope .nil, sends it NEW, and
then sets the new object's class back to the receiver (its default name
is "enhanced X").
::CLASS c METACLASS m, SUBCLASS(id, meta)
and metaclasses made by subclassing Class work as in ooRexx:
.c~class is the metaclass, its instance methods are
.c's class methods, subclasses inherit it, and its INIT
runs twice per class made. A subclass of a metaclass is a metaclass
(isMeta), and the new class's METACLASS is the receiver. A
metaclass method added later (DEFINE on the metaclass) does not reach
classes already made with it, as natively.
Partial: making an instance of a metaclass through Object's generic
NEW (e.g. .meta~new:.object) raises 93.900 "RVM: new
metaclasses are not supported yet" (World~newInstance, kind
CLASS); natively it gives an object.
DEFINE(name [, method|source]) and DELETE(name) give the class a copy
of its instance behaviour first, then change imethods
(DEFINE with no method hides the name: ~method gives
.nil, a send gives 97.1) and rebuild the subclasses. A
source is compiled with the name as given (the package is its own, named
so). Language classes are closed: any of these on a class of the REXX
package raises 98.985 (data~rexx), except while the
prelude's prolog runs (World~building). There is no
::EXTENSION (an ooRexx extension not in ooRexx 5);
.String~subclass('MyS') works.
World~inherit(c, m [, position])
(RexxClass::inherit): m must be a mixin class
(98.942); not c, not already in c's class
scopes, and c not in m's (98.944); the mixin's
base class must be among c's scopes, both class and
instance (98.943). Without a position the mixin goes last in
superclasses; with a position it is inserted
before it (98.945 if the position is not a superclass;
with .Object as position the mixin becomes the first
superclass and SUPERCLASS returns it). Then c and its
subclasses are rebuilt in place. UNINHERIT (98.945 if absent or first)
removes it and rebuilds; as in native ooRexx it removes the mixin from
the class's subclasses (not the class from the mixin's), so
m~subclasses still lists the class. BASECLASS,
SUPERCLASSES, ISSUBCLASSOF, ISA look at the scopes; ISINSTANCEOF is
ISA.
::CLASS x ABSTRACT sets abstract at the end
of the class's install (after its methods and annotations), so its class
INIT can still make instances. NEW and OF of an abstract class raise
98.989 with the class id (World~checkAbstract, called by
newInstance and by the hand-made NEW/OF of Array, List,
Queue, Set/Bag/Relation, String, Method, Routine, Package), after the
argument checks and before INIT. An abstract metaclass is 98.990. An
ABSTRACT method (::METHOD m ABSTRACT,
::ATTRIBUTE a ABSTRACT) has key ABSTRACT:
sending it raises 93.965 with the method name and no "Compiled method"
line.
CompileDirectives turns each directive into an entry of
the R-code CLASSES and METHODS tables (04-rcode.md); a method entry has a class number
(0: floating, before the first ::CLASS), I/C/K (instance,
class, constant initializer), name, flags and a kind. The loader maps
kinds to method keys:
| Directive | Kind → key | Notes |
|---|---|---|
::METHOD with body |
CODE → R |
address, labels, extent (for Method~source) |
::METHOD ... ATTRIBUTE / ::ATTRIBUTE |
GET/SET →
A.GET/A.SET |
NAME and NAME=; with a body: CODE |
... DELEGATE var |
DELEGATE → A.DELEGATE |
the message goes to the object in var |
... ABSTRACT |
ABSTRACT |
93.965 when sent |
... EXTERNAL 'LIBRARY REXX f' |
REXX f → X.f |
RVM natives (Alarm/Ticker timers, stream/file methods) |
... EXTERNAL '...' |
LIBRARY → L |
resolved when it runs (98.903, 90.998) |
::CONSTANT n v |
CONST → A.CONST |
one I and one C method |
::CONSTANT n (expr) |
CCONST → A.CONST (no value) |
value set by the initializer |
Flags (MethodFlags): P private,
R protected, K package, U
unguarded, A attribute method; - for public
guarded. Methods are guarded by default; constants are unguarded.
A.GET returns the variable of the attribute's scope pool
(its name if unset), A.SET sets it and returns nothing; a
guarded one takes the pool's lock for that moment (or waits). A stem
attribute (::ATTRIBUTE a.) is a stem variable: GET gives
its Stem object (creating the stem), SET assigns as a. = v.
Method~isAttribute is true for both methods (for EXTERNAL
attributes only the getter, as ooRexx).::CONSTANT name value (no
value: the name as written; a signed number keeps its sign).
::CONSTANT name (expr) compiles, per class, a method
"::CONSTANT" (ConstantInitializer, ooRexx's
resolveConstants) whose code evaluates each expression and
stores it with SETCONST; the installer runs it on the class
object after all the classes are made and before ACTIVATE. Sending a
calculated constant whose initializer has not run (or failed) is
97.4.::CLASS) have scope .nil and appear in
.METHODS (09).::ANNOTATE is resolved at compile time
(CompileAnnotations, ooRexx's
annotateDirective): its target must be defined by a
directive before it (a class, a routine, a method of
the active class — instance first, then class —, an attribute's GET/SET
methods, a constant's I and C methods, or the package); a missing target
is 99.945, raised by code placed before the prolog. Names and symbol
values are upper-cased, signed values keep their sign, pairs accumulate
and the last wins. At run time World~annotationsOf(h)
builds a StringTable once from the pairs (it can then be changed);
ANNOTATION(n) looks up Upper(n)
(.nil if absent). A copied method gets a copy of the
table.
There are three conversions, as in native ooRexx
(RexxObject::requestString, stringValue,
primitiveMakeString):
Method (RVM.Obj / Obj) |
ooRexx | Gives |
|---|---|---|
stringValue / string() |
requestString |
a MutableBuffer's text; a String subclass's string; an Array's
lines; a Rexx MAKESTRING's result; otherwise stringOnly
and the NOSTRING condition |
stringOnly |
stringValue |
STRING: native → object name (a Stem: its default, a VariableReference: its value's; a StackFrame: its line; a name made in Rexx: STRING is sent, as a Rexx STRING); Rexx STRING → its result |
requestString |
REQUEST STRING | MAKESTRING's result, or .Nil when it has none |
What the trace shows (string in the ooRexx host,
traceText in JS) is ooRexx's stringValue,
never its STRING: a MutableBuffer's text, a StackFrame's line, a stem's
default, a VariableReference's value, otherwise the object's name. The
same text goes into error messages and into the items of an Array's
MAKESTRING/TOSTRING. Where each conversion is used (index of List/Queue
and EQUALS: MAKESTRING else STRING; String method arguments and
SORT/COMPARETO: MAKESTRING or 88.909) is detailed in 10.
A name made in Rexx. ooRexx's
stringValue of an object sends OBJECTNAME, and Object's
OBJECTNAME, when no name was set (objectName=), sends
DEFAULTNAME: a class may define either in Rexx (nameInRexx,
defaultNameInRexx). Then Object's STRING and OBJECTNAME
delegate that message (RVM.Delegate), a conversion (SAY,
concatenation) sends STRING by re-execution (below), and where no
instruction can run again — the trace, an error message, an Array's
items — stringName asks for it now with
sendSync. For an error message it is "safe", as ooRexx's
messageSubstitution: one at a time (naming),
and an error there gives the default name.
Conversion by re-execution. When a conversion needs
a STRING or MAKESTRING written in Rexx, the host method cannot run it.
It records the object (.RVM.Obj~pending,
pendingMessage) and raises RVM.NeedString (JS:
throws a NeedString). The machine abandons the instruction
(which has changed nothing yet: its stack pointer and pc are restored),
sends STRING (mode STRING) or MAKESTRING (mode
REQUEST), stores the result in
.RVM.Obj~conversions / requests (JS
CONVERSIONS, REQUESTS) keyed by the object,
and runs the instruction again, which now finds the cached string. An
instruction that converts several objects repeats this once per object;
the caches of an outer instruction are saved while STRING runs
(convSaved, RestoreConversions). A STRING
returning nothing gives the object's stringValue (ooRexx's
requestString): its name, or the OBJECTNAME message again
when Rexx makes the name, and nothing from that is 91.999
(Message "STRING" did not return a result); a non-string
result is made a string with PrimitiveString
(.nil's name if it has none).
NOSTRING. stringValue calls the
reporter context's noString(v, obj) (the context of the
running activity: .RVM.Obj~reporter, JS
REPORTER.ctx, set by the machine before each launch and
saved around runSync/sendSync). The condition
(DESCRIPTION the string used, ADDITIONAL the object) is raised only if
trapped by SIGNAL ON NOSTRING/ANY, or as 98.973 under
::OPTIONS NOSTRING SYNTAX; otherwise nothing happens. It
arises in concatenation, SAY, BIF and String-method arguments, PARSE
VALUE, IF, INTERPRET, stems, VariableReferences, and for objects such as
.nil, classes, Directory, List, Package; not for
comparisons with .nil, .nil~string, SELECT
CASE, Array items, or classes with a MAKESTRING (File, DateTime,
TimeSpan, CircularQueue). A Stem used as a whole number (NUMERIC, BIF
positions) uses its default without NOSTRING. A program's exit value is
not converted in the activation (QuietString,
stringValue(.False)).
REQUEST(c) sends MAKEc if the object has it (no
result → .nil), else returns the object if its class id is
c, else .nil.
String subclasses. String~NEW of a
subclass makes an object whose native is the string (INIT gets the other
arguments). Its conversions are the string unless the subclass defines
STRING/MAKESTRING in Rexx; String's methods and operators use it;
operations return plain strings (.myS~new('abc') || 'd' is
a String); HASHCODE is the string's. What native's
stringValue gives (the trace, error messages, an Array's
MAKESTRING) is the string even when the subclass defines STRING.
CheckRestricted,
using the sender the machine stores in .RVM.Obj~sender /
REPORTER.sender). It gives the object a
copy of its behaviour
(defineInstanceMethod), with the method first; later class
changes no longer reach the object. FLOAT (default) leaves the method's
scope .nil (its EXPOSE uses a pool of its own; its SUPER is
the object's class); OBJECT gives it the object's class as scope
(NewScope copies a method that already has a scope). A
method with no method argument hides the name. UNSETMETHOD removes only
what SETMETHOD added. A string (not boxed, so it has no behaviour of its
own) passes the restriction only from a method whose SELF is that
string, and no program can run one: the REXX classes refuse DEFINE and
INHERIT (98.985). The machine keeps a 93.900 after the check for that
case, so FORWARD of SETMETHOD to a string from another object gives
native's 98.991..nil) on the receiver as
*UNNAMED*; error order 88.901 "method", 93.974, 93.952,
88.901 "argument style", 93.915, 88.901 "argument array", 93.902.RVM.Method
(World~methodObject), so identity holds (09).RVM.DirMethods, DirMethodsNative).Object's =/== and
\=/\==/<>/><
compare identity (O.EQ, O.NE). Stem and
VariableReference hide these operators (hidden entries in
imethods), so they go to UNKNOWN and on to the default
value / the variable's value. String comparison is in 02.
HASHCODE: a string's (and a String subclass instance's) is
getStringHash (the ooRexx host uses the host string's
HASHCODE; JS ports it, stringHash); any other object's is
its identity number as 8 bytes, little endian (natively, its address).
In Table, Set, Bag and Relation (not Directory, StringTable,
IdentityTable) an object index whose class defines HASHCODE or
== in Rexx is hashed with its HASHCODE
(getObjectHashCode: "" → 1, 8+ bytes → the first 8, else a
short; none → 91.999) and compared with its == (identity
first). The ooRexx host wraps such an index in RVM.HashKey,
whose hashCode and == call
sendSync (the host collection then calls them as it would
for any object), and unwraps on the way out (Unhashed,
UnhashedArray). A String subclass instance as an index (or
a Set's or Bag's item) is kept as the object and is the same index as
its string, as natively: the ooRexx host wraps it in
RVM.StringKey, a subclass of the host's String, which the
host collection hashes and compares as its string, as ooRexx does; JS's
TableMap finds it by its string (strObjs,
stringKey) and hashes it by its string; item comparisons
use RVM.ItemKey / ItemMatch. JS detects it
with customIndex and locates entries through
HashShadow (mapLocate,
equalIndex). Items (hasItem,
index, removeItem) compare with
equalValue (identity for objects, == for
strings). Details per collection: 10.
As natively, a manager belongs to the package
(setSecurityManager on a Package, Method or Routine sets it
on the package; no argument removes it; on the REXX package 98.984;
Method/Routine return 1 for Rexx code, 0 for natives). An activation
copies it when created (RVM.BaseContext~secMgr, from the
program in applyOptions; saved with the activation;
internal CALL and INTERPRET inherit the copy); only LOCAL and
ENVIRONMENT read the package's own each time. So setting it in a running
program affects LOCAL and ENVIRONMENT at once but other events only in
new activations.
World~security(mgr, event, entries) sends the event name
to the manager with a Directory of entries (via sendSync);
result 0 → go on, 1 → handled (the Directory as the manager left it), no
result 91.999, anything else 34.903.
| Event | Where | Entries | When handled |
|---|---|---|---|
| METHOD | SendLoop |
OBJECT, NAME, ARGUMENTS | RESULT is the message's result; only PROTECTED methods (user ones and the protected natives: Class BASECLASS, INHERITINSTANCEMETHODS, DELETE, METACLASS, SUBCLASSES, SUPERCLASSES, SUPERCLASS, UNINHERIT; Directory SETMETHOD/UNSETMETHOD; Method SETPROTECTED, SETSECURITYMANAGER; Routine and Package SETSECURITYMANAGER; Package OPTIONS and DEFAULTOPTIONS) |
| CALL | CallRoutine |
NAME, ARGUMENTS | RESULT is the routine's; asked after ::ROUTINEs and
public routines, before macros, REXXUTIL and files |
| COMMAND | IssueCommand |
COMMAND, ADDRESS | RC (0 if absent); FAILURE/ERROR raise the condition; asked after the redirections are evaluated |
| LOCAL, ENVIRONMENT | World~env |
NAME | RESULT is the value; asked after the package's classes, REXX public
classes and the package's local; .CONTEXT,
.RS, .LINE ask both |
| STREAM | stream BIFs (SecureStream) |
NAME (qualified) | STREAM is a replacement object, then used through messages; once per
name per method activation (streamScope), forgotten on
close |
| REQUIRES | RequiresProgram |
NAME, SECURITYMANAGER | asked with the short then the resolved name when not yet loaded;
NAME may be changed (removed → 43.901); SECURITYMANAGER gives the loaded
package one; covers ::REQUIRES,
Package~new(file), loadPackage |
With a manager present World~env loads the prelude
first, so that classes found there do not reach the manager.
Method implementations come from three sources:
CallNative /
callNative (and the *Native routines), one per
key. Natives receive their arguments already checked for count; String
methods also check each argument's type in ooRexx's order
(RVM.StringArgs / STRING_ARGS, 10).CoreClasses.orx
and StreamClasses.orx (trimmed; prelude.orx,
prelude-streams.orx), compiled to R-code and loaded
lazily by World~ensurePrelude the first
time something is not found (a lookup in SendLoop, an
environment symbol, INSTANCEMETHOD, HASMETHOD, ISA, REQUEST, SETMETHOD,
DEFINE...) or .environment is asked (a message to it, its
COPY, DO OVER it), so a program that uses no objects never pays for it.
The prelude's classes are installed with no machine
(installNow + RunNatives: every message must
find a native; one that needs Rexx code is deferred to the machine as
world~deferred and resent after it,
RVM.Resend), marked rexx, then its prolog runs
(runProlog, as in ooRexx's image build: the mixin INHERITs
of the primitive classes, String's class methods in Rexx, the public
classes in .environment), the setup-only natives
DEFINECLASSMETHOD and INHERITINSTANCEMETHODS are removed, and every
behaviour is rebuilt (refresh). The collection mixins
(MapCollection, OrderedCollection...), Comparable, Orderable, DateTime,
File, Stream and the rest live there.prelude-rvm.orx: methods that are
natives in ooRexx but must call Rexx code (Array's
SORTWITH/STABLESORTWITH and SORT/STABLESORT of objects).
World~bootstrap copies them into Array with
compiled = .True: they show as a single "Compiled
method" traceback line, are not traced and take no guard lock.| Aspect | ooRexx host | JS host |
|---|---|---|
| Object, behaviour, class data | RVM.Obj, RVM.Behaviour,
RVM.ClassData (host Table/IdentityTable/Array) |
Obj, Behaviour, ClassData
(Map, arrays) |
| A String subclass instance's native | a host .String |
a JS string |
| Send path | labels inside RVM.Machine~execute
(Signal) |
methods
doSend/sendLoop/sendDone/deliver |
| Conversion request | Raise Syntax ... "RVM.NeedString" |
throw new NeedString(obj, message) |
| Reporter / sender | class attributes .RVM.Obj~reporter,
~sender |
REPORTER.ctx, REPORTER.sender |
| User hash keys | host collections + RVM.HashKey wrapper |
ported hashing (RHash, HashShadow,
customIndex) |
| Collections | host List/Queue/Set/Bag/Relation/Table | ports (RArray, RList, RQueue,
RHash) |
| Install | RVM.World~install, RVM.Installer |
World.prototype.install, Installer |
Behaviour is the same on the probes in this chapter (native ooRexx, both hosts).
~m:scope,
INSTANCEMETHODS (which lists shadowed methods) and in-place rebuilds
after INHERIT must give native results.RVM.Delegate
(with then chains for multi-step natives like SUBCLASS)
keeps all user code on the one machine loop. sendSync is
the narrow exception where a result is needed immediately (security
managers, user hash keys), and its waits run the scheduler in
place.Deliver mode says where the result goes. This gives one
place for lookup, access checks, UNKNOWN, NOMETHOD and traceback
lines.CoreClasses.orx so that Rexx-level
behaviour (and its line numbers in tracebacks) matches native.RexxCode::setSecurityManager,
RexxActivation), because programs (including ooRexx's own
test suite) depend on exactly which activations see it.