Suite 144/144; self-hosting fixpoint OK
(image 2,310,300 bytes). master, tree clean except the user's
uncommitted compiler/toto.mod.
This session completed the Clarion OOP story by adding dynamic dispatch, then showcased it.
| Step | Tag | Commit | What |
|---|---|---|---|
| VIRTUAL dispatch | v3-virtual-dispatch |
98d3067 |
per-class vtables + subtype pointer assignment |
| Showcase | v3-showcase18 |
(this commit) | polymorphic Shape hierarchy |
VIRTUAL methods now resolve at run time. A base-class pointer
holding a derived object calls the derived override:
TYPE
CLASS Shape; VIRTUAL PROCEDURE Area() : INTEGER; END Shape;
CLASS Circle (Shape); VIRTUAL PROCEDURE Area() : INTEGER; END Circle;
...
VAR b : POINTER TO Shape; c : POINTER TO Circle;
BEGIN
NEW(c); b := c; (* subtype pointer assignment *)
ExitCode := b^.Area() (* Circle.Area, decided at run time *)
END
vslot.data $vt_<typeindex> = { l $Method_uid, … };
a declared-but-unimplemented method is l 0.NEW store the vptr.POINTER TO Derived assigns to POINTER TO Base
(IsSubclass), which lets a base pointer hold a derived object.Docs: docs/summary_virtual-dispatch.md.
compiler/tests/showcase18.mod (Showcase18, exit 42): a Shape
hierarchy (Circle, Square) with a virtual Area(); an array of
POINTER TO Shape holds objects of both kinds and each area is
resolved at run time; the sum is asserted and printed:
showcase18 areas sum=139
(The number is built with Conversions.IntToStr + CHAR-array +,
tying in the earlier stdlib/string work.)
New: t_virtual (3) and Showcase18 (42).
cd .../m2compiler-V3
./bootstrap/fixpoint.sh # FIXPOINT OK
cd compiler && ./build.sh && ./run_tests.sh # 144/144
BEGIN … END init body, multiple parents.VAL(LONGINT|REAL, x) and long→int narrowing.SysClock, richer Strings/Math).