# Reverse-engineering REBOL/View 2.7.8 and building a clone

This document records how the REBOL/View 2.7.8 Windows executable was
analysed with [REA](https://github.com/morluto/rea), how its complete
application source was recovered from the binary, and how a working
clone was reconstructed.

## 1. Target

| | |
|---|---|
| File | `rebol-view-278-3-1.exe` |
| Source | <https://www.rebol.com/downloads/v278/rebol-view-278-3-1.exe> |
| SHA-256 | `215e28f9660472b6271a9902573c9d190e4d7ccca33fcf8d6054941d52a3ab85` |
| Format | PE32 GUI, Intel 80386, 864 256 bytes |
| Version | REBOL/View 2.7.8.3.1 (Win32 x86), 1-Jan-2011 |

REBOL 2 was never open-sourced (only REBOL 3 is). The only way to clone it
is to reverse-engineer the shipped executable.

## 2. Static analysis with REA

REA was installed and driven from the command line:

```bash
npm install --global rea-agents@latest
rea doctor
rea inspect-artifact reference-rebol-view-278-3-1.exe
rea inspect-pe-imports   reference-rebol-view-278-3-1.exe
rea inspect-pe-resources reference-rebol-view-278-3-1.exe
rea inspect-managed-artifact reference-rebol-view-278-3-1.exe
```

Findings (retained as Evidence JSON in `evidence/`):

* **PE identity** — `pe32`, machine 332 (i386), 32-bit, 4 sections
  (`.text`, `.rdata`, `.data`, `.rsrc`).
* **Imports** — 12 DLLs, 260-byte import directory,
  `imphash md5 = 0f5b28309e56412e191bdf8157a0a524`.
  `KERNEL32 USER32 GDI32 comdlg32 ADVAPI32 SHELL32 ole32 ODBC32
  WSOCK32 COMCTL32 WINMM MSVCRT`.
* **Resources** — 13 resource entries, 6 448 bytes, icon groups present.
* **Managed** — classified as native (no CLI metadata), so the deep native
  provider (Ghidra) is the correct follow-up. `system/modules` etc. are
  compiled C, not .NET.

The most valuable discovery was not in the code section but in `.data`.

## 3. Recovering the application source from the binary

REBOL stores its whole "boot image" — the native specs, the mezzanine
library, the View/VID system and every bundled module — inside the
executable as **zlib (DEFLATE) streams**. Scanning `.data` for zlib
headers (`78 9c`, `78 da`, `78 01`, `78 5e`) and inflating each stream
recovered 21 files, 440 KB of original REBOL source:

| Offset | Bytes | Module |
|---|---:|---|
| `0x0a2c8c` | 83 463 | core boot image (native/action specs + core mezzanines) |
| `0x0a8e10` | 96 | Big Numbers |
| `0x0a8e80` | 152 | Encryption |
| `0x0a8f14` | 99 | Encryption Level 2 |
| `0x0a8f9c` | 1 118 | DH/DSA Encryption |
| `0x0a915c` | 315 | Draw System |
| `0x0a925c` | 4 291 | Network Auto-Configure |
| `0x0a9898` | 1 180 | Graphics |
| `0x0a9af4` | 17 970 | Windows Installer |
| `0x0ab274` | 104 | Dynamic Library Access |
| `0x0ab2e0` | 26 917 | REBOL Mezzanine Extensions |
| `0x0ad608` | 90 | ODBC Access |
| `0x0ad668` | 65 573 | REBOL Internet Protocols |
| `0x0b1c90` | 1 320 | Windows Registry Access |
| `0x0b1e7c` | 674 | RSA Encryption |
| `0x0b1fe4` | 677 | Command Shell Access |
| `0x0b2158` | 311 | Sound |
| `0x0b224c` | 183 | Secure Socket Layer |
| `0x0b22f8` | 194 | System Port |
| `0x0b23c8` | 6 281 | **View and VID** |
| `0x0b2c28` | 165 901 | **View Desktop** |

The core boot image begins:

```rebol
; Copyright (C) REBOL Technologies 1-Jan-2011/16:39:07-8:00
[
[
add: action [
"Returns the result of adding two values."
value1 [number! pair! char! money! date! time! tuple!]
value2 [number! pair! char! money! date! time! tuple!]
]
...
```

It defines **184 primitive natives/actions/ops** and **83 core mezzanine
functions**; the module streams add the View/VID system, the Internet
protocols, codecs and the full desktop.  The extraction script is
`tools/extract_boot.py` (see the clone source).

## 4. Building the clone

With the application source recovered, the only missing piece was the
interpreter core.  A clean-room REBOL 2 interpreter was written in C
(`clone-source/`):

* `value.c` — values, series, contexts, interning, error handling
* `scan.c`  — lexer/parser (`load`/`mold`/`form`)
* `eval.c`  — evaluator: words, set/get/lit-words, paths, infix ops,
               refinements, user functions, lexical contexts
* `native.c`— native function library
* `view_win.c` — the View/VID GUI on native Win32 controls
* `main.c`  — startup, environment, REPL

The interpreter is cross-compiled to a Windows PE with
`i686-w64-mingw32-gcc` and runs under Wine for verification.

### Design notes

* Operators (`+ - * / = <> < > <= >= and or xor`) are infix natives.
* Function specs are parsed into positional args, refinements and their
  args, so `view/new` and `copy/part` dispatch correctly.
* Literal-word arguments (`repeat i 3 [...]`) are not evaluated.
* Word resolution walks a lexical parent chain, so function locals and
  globals resolve correctly.

## 5. Coverage

**The recovered R2 boot image is embedded in the clone and loaded at
startup** (sections 1-4), so the clone runs with the real REBOL 2 native
specs and the core mezzanine library rather than hand-written
approximations.  All 184 primitive natives from the boot image are
implemented (a handful are compatibility stubs); the scanner, evaluator,
case-insensitive word lookup, bitset/`charset`, and a `parse` engine were
added to support it.

Implemented and verified (Linux build and Windows build under Wine):

* The recovered R2 boot image is embedded and loaded at startup (native
  specs + core mezzanines).
* Proper REBOL lexical **binding**: words carry their context, function
  bodies are bound once at creation, and each call uses the function's own
  context (args, refinement args, and `/local` words) with save/restore so
  recursion works.
* Proper REBOL **series positions**: every string/block/binary value
  carries an index, and `head tail next back skip at index? head? tail?`
  return positioned series, so `append insert find copy length? remove`
  behave as in R2 (this is what made the boot mezzanines work).
* The `10-REBOL_Mezzanine_Extensions` module loads on top (extract, split,
  repend, map, ...).

* Datatypes: none, logic, integer, decimal, char, tuple, pair, string,
  binary, block, paren, word/set/get/lit/refine, path, file, url, issue,
  tag, object, function, native, datatype, error.
* Parser: strings, braces, binaries, chars, issues, files, urls, emails,
  tags, numbers, pairs, tuples, times, dates, money, paths.
* Control: `do if either unless while until loop repeat foreach forall
  for forever reduce compose attempt try comment quit halt`.
* Series: `first second third fourth fifth last length? pick poke head tail
  next back skip at index? head? tail? append insert remove clear copy
  reverse find select sort unique`.
* Math: `+ - * / ** // add subtract multiply divide remainder power negate
  absolute minimum maximum square-root exp log-e log-10 log-2 sine cosine
  tangent random even? odd? zero? positive? negative?`.
* Comparison/logic: `= <> < > <= >= equal? not-equal? lesser? greater?
  same? strict-equal? not and or xor`.
* Conversion/codecs: `to-integer to-decimal to-string to-block to-binary
  to-char to-logic to-word to-file to-tuple to-pair to-hex type? and all
  type predicates enbase debase`.
* I/O: `print prin probe read write save load mold form exists? now`.
* Networking: `read http://...`/`read https://...` (WinHTTP/TLS on Windows;
  plain HTTP with redirects on other platforms), passive-mode FTP
  (`read`/`read/binary`/`read/lines`/`write`/`dir?`), POP3/IMAP mailbox
  reads and SMTP sending (`send`/ESMTP ports).
* `parse` with charset/bitset rules and the standard charsets; `collect`/
  `keep`; the boot mezzanines `help context funct array build-markup` etc.
* `case switch catch throw break return exit use unset remove-each`.

* View: `view view/new unview do-events get-face set-face layout
  stylize alert`, the recovered 120-style View Desktop sheet, working
  Win32 controls, and window/face rendering.
* Console: `help` / `help word`.

The current build implements all of the above and passes the golden suite
(§5a).  Remaining gaps are listed at the end of §6a.

## 5a. Golden-output conformance suite

`tests/` is a 103-case conformance suite.  Each case is a deterministic
REBOL 2 script; `tests/expected/` is generated by running the **original
REBOL/View 2.7.8.3.1 executable** under Wine (the oracle).  The suite
currently passes **103/103 on the native Linux build and 103/103 on the
Windows PE build under Wine**.

```bash
python3 tests/tools/run.py test          # Linux clone vs goldens
python3 tests/tools/run.py test --wine   # Windows build under Wine
python3 tests/tools/run.py test --diff
python3 tests/tools/run.py gen           # regenerate from the reference
```

The runner wraps each case with a `print`/`prin`/`probe` capture layer and
an `either error? try [...]` guard.  (In R2, storing a raw error value with
`err: try [...]` re-raises it, so the inline form is required.)  Cases use
only R2-defined words: R2's `try` does **not** catch "has no value", and an
undefined word drops the reference oracle into its interactive error
console.  See `tests/README.md` for the full list of R2 quirks.

## 6. Reproducing

```bash
# extract the application source from the reference binary
python3 tools/extract_boot.py reference-rebol-view-278-3-1.exe r2-extracted

# build the native Linux clone
cd r2clone && make

# build the Windows clone (all modules, including zlib.c and the vendored zlib)
for f in value scan eval native view_win net boot_image modules main image draw hash zlib ffi; do
  i686-w64-mingw32-gcc -O2 -std=gnu99 -c $f.c -o /tmp/rel-$f.o
done
for f in deflate trees adler32 crc32 zutil; do
  i686-w64-mingw32-gcc -O2 -std=gnu99 -DZ_SOLO -DNO_GZIP -Ivendor/zlib \
    -c vendor/zlib/$f.c -o /tmp/rel-z-$f.o
done
i686-w64-mingw32-gcc -O2 -s -o rebol-view.exe /tmp/rel-*.o \
  -lm -luser32 -lgdi32 -lwinhttp -lmsimg32 -lcomdlg32
```

## 6a. Current state (this session)

The following were added on top of the foundation described above:

### Generic port system (demo19)

The reference implements network/file ports natively (the recovered protocol
modules only build port specs).  Reverse-engineering the port object layout
and actor behaviour in the oracle under Wine produced a concrete model, now
implemented in `r2clone/port.c`:

* A port is an object value with R2's **45-field** port spec plus hidden
  `__kind`/`__sys` fields; `port?`, `type?` → `port!`, `mold` →
  `make port! [...]` (byte-identical, including the nested `state` object),
  `form` → the field lines terminated by a newline.  Ports are numbered like
  R2 (`state/misc/1` starts at 172 and steps by 4).
* `open` accepts URL, file, block (`[scheme: 'tcp host: … port-id: …]`) and
  object specs with the reference's refinement slots (`/binary /string
  /direct /seek /new /read /write /no-wait /lines`).  TCP: connect or
  listen; UDP: bind or remote; file: read/write/new/direct/seek with the
  reference's `state/flags` and `state/misc` mode bits; console.
* Actors: `insert`/`write` (TCP flush-on-write, UDP `sendto` incl.
  broadcast, `/lines` CRLF termination), `copy`/`read` (buffered data,
  `none` at EOF, `copy/part`, `/binary`, `/lines`, `/seek` binary
  positions), `first` (accept; errors when the port cannot accept),
  `close`, `read-io`/`write-io`, `length?`, `get-modes`/`set-modes`,
  `wait`/`wait/all` with timeouts and `port/timeout`.
* **Port specs**: `read`/`write` accept the documented `[file! url! object!
  block!]` target, so a spec block like `[scheme: 'file target: %f]` or
  `[scheme: 'http host: h port-id: n target: %p]` is resolved to a file or a
  URL (and `tcp`/`udp`/`console` specs to the port layer).  `form` of words
  was also corrected to match R2 (bare names; `mold` keeps the marks).
* **Formatted MOLD**: line breaks in the source are kept as per-element
  markers (`Series.nl`), and MOLD reproduces R2's layout (space + newline +
  4 spaces per nesting level; a multi-line block closes on its own line).
  The markers are copied by `copy`/`reduce`/`compose`/function creation and
  shifted by `insert`/`remove`.  Indentation is computed from an explicit
  block depth (element breaks at 4*(depth+1), closing bracket at 4*depth) and
  a nested block keeps a leading break only when it does not start the line.
  Known cosmetic limit: one `stylize`-built style object (the scroller feel)
  still molds without its breaks.
* **Script path**: `system/script/path` (WHAT-DIR) is set to the absolute
  directory of the running script in R2's `file!` form (`%/Z/dir/` on
  Windows); the file layer maps that form back to `Z:/dir/` for the C
  library.  Previously the clone left it as `"./"`.
* **Text metrics**: `size-text` (and therefore text wrapping, caret
  geometry and VID face sizing) now uses a table of Arial advance widths and
  line heights measured from the reference at every printable ASCII char and
  point size 8–48 — the numbers come from the oracle itself, so Linux and
  Wine agree with it.  Grey areas: R2's inter-character spacing (about 2 px
  per gap, more at some sizes) makes long strings differ by a few pixels.
* **Images**: `mold`/`form`/`to-string` of an image reproduce R2's
  `make image! [WxH #{rgb} #{alpha}]` text (10 pixels per line, alpha block
  only when some pixel is not opaque) and `to-binary` returns the raw
  `B,G,R,A` bytes.  Face effects are a portable filter shared by the window
  renderer and `to-image`: `flip` (default/`1x0`, `0x1`, `1x1`),
  `rotate 90|180|270` (the reference's 180° rotation of an odd-sized image
  leaves the centre pixel transparent — matched), `invert`, `grayscale`
  (0.3/0.59/0.11, truncated), `key`, `colorize`, `crop`, `luma` (add n per
  channel), `multiply` (v·c/128) and `blur`/`sharpen` 3×3 convolutions
  (`{0,1,0,1,1,1,0,1,0}/5` and `{0,-1,0,-1,8,-1,0,-1,0}/4`, truncated,
  edge-clamped; kernels confirmed against the oracle's delta response).
  `contrast`, `tint`, `hsv`, `reflect`, `merge`, `grid`, `shadow`, `scale`,
  `extend` and `aspect`/`fit` placement remain unimplemented or approximate;
  chaining two convolutions in one effect block also diverges from the
  reference (documented in tests/README.md).
* **Event model**: `port/awake` is called with the port itself (R2 has no
  event object here) when a `wait` that includes the port finds it ready;
  one event per `wait`, `wait/all` dispatches every ready port and returns a
  block, timeouts return `none` without firing the handler, `wait <time>`
  and `wait []` do not process port events, and EOF arrives as a read event.
  `tools/ports_smoke.py` proves wire interoperability with the reference in
  both directions (TCP, UDP, async server) on Linux and under Wine.
* Two reference quirks were matched deliberately: TCP data written by a
  port is only flushed when that port is closed or the event loop runs, and
  `copy` on a file port returns the whole buffered file image each time.
  One deliberate deviation: `read port` returns available data in the
  clone where R2 2.7.8.3.1 raises (R2 programs use `copy port`).

* The **View Desktop module is embedded and evaluated**, so `system/view/vid`
  is the original 120-style style sheet and `LAYOUT`, `STYLIZE`,
  `MAKE-FACE`, `SET-STYLE`/`GET-STYLE`, the window face, and `VIEW` are the
  recovered REBOL implementations rather than C approximations.
* Dysfunctions exposed by running that source were fixed in the interpreter:
  function creation inherits the *binding* of its spec/body (not the
  `func` helper's context); `bind block word` actually binds; set-words
  evaluate full infix expressions; `forall`/`forskip` use series positions;
  `set [a b] block` destructuring; datatype-aware `find`/`switch`; paths
  call functions reached through objects (`obj/fn arg`) and index
  tuples/pairs/images; `copy/part` with a position; block `make series`
  creates an empty series; component-wise `maximum`/`minimum` of pairs;
  refinement flags default to `none` (R2) rather than `false`.
* `parse` was extended with literal word/char/string/number/bitset
  matching, datatype rules, correct `set`/`copy` offsets, sub-rules and
  paren actions.
* Added the Graphics (07) and Draw System (05) modules; base64 `64#{...}`
  binary literals; image! values with GIF/PNG/BMP/JPEG header detection;
  `to-<type>` conversions for every datatype; the complete standard
  datatype set (`hash!`, `list!`, `typeset!`, `end!`, paths, `email!`, ...).
* The Win32 renderer now accepts real VID faces and places them by VID
  offset/size, honours colours, fonts and simple edges, draws decoded
  images (with alpha compositing over the face colour), and dispatches
  both block and function actions.  The event loop is driven by the
  `wait []`/`wait n` natives (message pump).
* Real image decoding was added with the public-domain **stb_image**
  single-header decoder (GIF/PNG/JPEG/BMP/TGA), so stock images and
  `load` of image files produce true pixels.  A subset of AGG `draw`
  (`pen`, `fill-pen`, `line`, `box`, `circle`, `triangle`, `image`,
  `gradient`, `color`, `flood`) rasterises into image! values.
* The VID dialect `size` word now works: `parse`'s `set`/`copy` resolve
  variables in the *rule word's* binding context rather than the current
  context.
* `parse` gained `into` (nested series), `copy`/`set`, `to`/`thru`
  semantics (including R2's automatic whitespace skipping without `/all`),
  `/case`, `/all` (including the delimiter-splitting form), integer rule
  repetition, and case-insensitive literal matching by default.  R2's
  parse dialect has no `insert`/`change`/`remove` commands; the suite and
  clone follow the reference here.
* The Win32 renderer now composites decoded images with per-pixel alpha
  (`AlphaBlend`), applies `fit`/`tile`/`colorize`/`gradient` effects, and
  paints window/panel gradient backdrops behind transparent faces.
* `draw` gained a scalable embedded 8x8 bitmap font (`text` + `font
  [size: N]`), so labels can be rasterised into images on any platform.
* Implemented `find/with` custom wildcards, `select/part`/`select/with`,
  `sort/compare` (function or record offset) and case-insensitive `sort`.
* `draw` gained `scale`/`rotate`, `clip`, and `polygon` (scan-line fill).
  The clone also exposes a convenience push/pop/translate stack, which is
  not part of R2's dialect.
* `date!`, `time!` and `money!` are now real values: civil-date storage,
  correct `mold`, comparison, arithmetic, path facets, ISO/`d-Mon-yyyy`
  parsing and the full `now` refinement set.
* `case` was rewritten to evaluate full condition expressions (calls with
  arguments), and `second`/`third`/`length?` now work on function values,
  fixing `body-of`/`spec-of`. `try`/`attempt`/`catch` restore `Current`
  after a longjmp (no more leaked evaluation contexts).
* Set-paths into components (`size/x:`, `block/1:`, `image/1:`) and
  get-word path components (`val/:axis`) were implemented; `to-pair`,
  `to-tuple`, `to-integer` and `to-decimal` gained their full R2 forms.
* `parse` set-word rules capture the current input position, and `exit`
  returns from the current function rather than unwinding the script.
* Object binding was reworked: `bind` works on objects/functions,
  `make object!` keeps explicit outer bindings (e.g. `bind ctx-text
  system/view`) while binding instance fields, and style functions are
  cloned/rebound per instance — this made sliders, scrollers and the
  themed requestors work.
* The truthiness rule was corrected (only `none`/`false` are false), which
  fixed VID ratio/scroll logic and many mezzanines.  `first`/`second`/
  `third`/`pick` work on pairs/tuples/times/dates; associative block
  paths (`blk/key`, `blk/key: val`) work; `set` accepts any word type.
* Complex VID styles (slider, scroller, progress, list, text-list, area,
  choice, rotary) now construct, using cloned/rebound per-instance
  functions and `layout/parent/origin/styles`.
* Requestor support: `request/ok` and `request-text` render as themed
  VID popups; `request-file` calls the native Windows dialog via the
  new `local-request-file` (`GetOpenFileName`); `alert` uses a native
  message box.

### Fidelity work driven by the golden suite (this session)

The 66-case oracle suite exposed and fixed, among others:

* `form` vs `mold` for datatypes (`integer`/`integer!`), files
  (`file.txt`/`%file.txt`), issues, times (`1:30` not `1:30:00`),
  dates, money, tuples (length-aware), binaries (hex), bitsets
  (`make bitset! #{...}` with R2's bit layout), strings (brace molding
  when they contain quotes) and user functions (`func [spec][body]`).
* `load` returns a single value for a one-value script, preserves R2's
  implicit end-of-line marker, and `to-block` loads strings.
* Real base64 `enbase`/`debase`, `to-hex` issues, tuple/pair binary
  conversions, zlib-compatible `compress`/`decompress` (including
  R2's trailing little-endian length), and every `checksum` variant:
  the default 24-bit PRZ CRC (`Compute_CRC`, seeded with `len + first
  byte`), `/tcp`, and `/method 'md5`/`'sha1`/`/secure` binary digests.
* R2 image pixels are always 4-component RGBA; `draw` on a user image
  produces coverage (white fills, pen-coloured lines, alpha 0), which the
  clone now matches.  VID font metrics use `size-text` Arial width tables
  (12 normal / 24 bold).
* Case-preserving word interning (R2 molds `slider`, not `SLIDER`), while
  lookup remains case-insensitive.
* Functions reached through a path (`obj/fn`) are always called, even
  when followed by a set-word or the end of a block.
* Object field order follows the spec (including chained set-words);
  `first object` is `[self ...]`; `words-of`/`values-of` exclude `self`;
  `with` is a facet dialect (`doc [...] effect [...]` as well as
  `field: value`).
* Generic `for` over decimal/money/time/date/char ranges; `round` with all
  R2 refinements; `difference` is the symmetric difference; `find/match`
  returns the tail of the match; `same?` is series identity.
* The recovered View Desktop module now loads completely (it had been
  failing on `to-lit-word`), so the real 120-style VID sheet and correct
  layout offsets/sizes are available.
* A language-edge-case oracle pass fixed `series?` for file/URL/email/
  image values, `join`/`append`/`insert` type preservation, `select` on
  strings, `make date! [y m d]`, `opt`/`any` rule skipping, and
  zero-length `parse copy`.
* A VID/parse pass fixed `case` with non-block results (the boot
  `replace` depends on it), `second`/`third`/`pick` on positioned
  series (stock-image loading), `change/part` string replacement,
  `replace/all`, and bold 12pt text metrics.
* A reflection/I-O pass fixed `body-of`/`words-of`/`third` on objects and
  functions, nested `mold` indentation, degree-based trig, `make time!`,
  `read`/`write /part`, `size?`/`dir?`/`make-dir`, `to-local-file`,
  `sort/all`, dynamic set-paths, pair+integer arithmetic, money negation,
  and structured `disarm` metadata (cannot-use / past-end).
* A GUI regression case exercises `editor %test.txt` (with a dummy window
  so it returns), and the suite grew to 43 cases.  File/URL path extension
  (`file/word/word`), `system/script/path`, and the default script title
  "Untitled" were added, which also makes the recovered editor usable.
* A second oracle pass added the exact default 24-bit PRZ `checksum`
  (and `/tcp`, `/method 'md5`/`'sha1`, `/secure`), `mold/only`,
  `find/reverse`, `reverse/part`, `uppercase`/`lowercase /part`,
  `read`/`write` `/lines`/`/binary`, and fixed path-refinement flags
  leaking into nested argument evaluation.

### Static recovery of `checksum/hash` (disassembly pass)

`checksum/hash` was the last unknown codec.  Its native branch does not call
`Hash_String` (`0x493a86`, the case-insensitive word hash over the 24-bit PRC
CRC); it calls an unexported routine at `0x482c0b`.  That routine is Bob
Jenkins' **lookup2** hash with three REBOL-specific changes:

* every byte is folded through REBOL's `Upper_Case` table at `0x4c31e8`
  (so `hash "HELLO"` = `hash "hello"`, including the Latin-1 foldings
  `0xe9 -> 0xc9` and `0xff -> 0x9f`);
* the accumulators start at only the golden ratio (`a = b = c = 0x9e3779b9`,
  no `initval`) and the full length is added to `c` before the tail;
* the final 1-11 byte tail is summed in *reverse* byte order (the jump table
  at `0x482e88` shows the c/b/a accumulation order).

The 32-bit result is reduced with `% size` (size <= 1 clamps to 1) and the
`size` refinement argument is mandatory (`expect-arg checksum size integer`).
The C port (`hash.c: R2_Hash_String`) reproduces every probed value, including
empty strings, positioned series and the 256-value single-byte table.

The same pass added `checksum/key` (HMAC-MD5/HMAC-SHA1) and R2's error-object
shapes for `expect-arg` (word args plus a datatype block) and `invalid-arg`.

### Identity, tuples, dates and image transparency

* The boot image's `System` spec declares `version: 0.0.0`; the native build
  fills in `2.7.8.3.1` / core `2.7.8` / build `1-Jan-2011/16:39:07-8:00` /
  product `View`.  Doing this before the Graphics module loads makes
  `system/version/4 = 3`, so the default VID font is Arial (as on Win32).
* Tuples hold up to ten components and preserve their length (a 5-tuple
  `2.7.8.3.1` molds with five components; `length?` reports it).  `to-tuple`
  pads short blocks to three components, `pick`/paths index any component and
  component maths follows R2 (`+`/`-`/`*` truncate the scalar, `/` divides in
  floating point).
* Dates carry a time-zone offset and a "has time" flag: `date/zone` returns a
  `time!`, `date/date` drops the time, `date/time` returns `none` when the
  date has no time, `mold` prints `/h:mm[:ss]` plus a `±h:mm` zone, and
  comparison is absolute (zone-adjusted).
* R2 image pixels store **transparency**, not alpha: 0 is opaque and 255 is
  transparent, fully transparent pixels have their RGB zeroed, and a
  three-component `poke` value means opaque.  The stb_image decoder, `poke`,
  `draw` fills/strokes and the Win32 `AlphaBlend` compositing all use this
  convention.  `draw` fills with the `fill-pen` colour and outlines with the
  `pen` colour (white by default), matching the oracle's pixels.
* VID buttons are owner-drawn from the face colour/font/edge (R2's blue
  buttons with white bold labels) and window captions use `REBOL - <title>`.

### Zlib-compatible COMPRESS (byte parity)

`compress` was a fixed-Huffman literal-only deflate: valid, but larger than
the reference and not byte-identical.  Probing the oracle across 181 KB of
varied inputs (all byte values, runs, random data, text, and 70–80 KB
repetitive streams) showed that R2's `compress` is exactly **zlib level 6**
(`Z_DEFAULT_COMPRESSION`, header `78 9C`) followed by the original length as
a little-endian 32-bit word.  The clone now vendors zlib 1.2.11's deflate
path (`deflate.c`, `trees.c`, `adler32.c`, `crc32.c`, `zutil.c` under
`r2clone/vendor/zlib/`, built with `Z_SOLO`/`NO_GZIP` and a caller-supplied
allocator) and calls `deflateInit(..., 6)`; the stream is byte-identical to
the reference on every probe.  The existing inflater is unchanged and still
handles stored/fixed/dynamic blocks.  Golden case `59-compress-zlib` pins
repetitive LZ77 output plus round-trips.

### Anti-aliased DRAW and curve commands

R2's `draw` native is backed by AGG.  The clone now uses an AGG-style
coverage rasteriser: draw coordinates are mapped to pixel *centres*
(`x + 0.5`), paths are flattened, and each shape is rasterised with 32
vertical subpixel rows and exact horizontal area coverage.  Fills use
non-zero winding and a stroke of width `w` is a quad with butt caps by
default (`line-cap` selects `butt`/`square`/`round`).  On a 45-degree
1-pixel line the reference produces `117/63/234` at end/side/centre while
the clone produces `117/64/233` — within one AGG quantisation step.  Axis-
aligned edges are exact (255).  `anti-alias off` restores hard-edged
rendering.

The dialect also gained `curve` (quadratic Bezier for three points, cubic
for four) and `spline` (quadratic B-spline, `closed` and knot forms, which
stays inside the control polygon), plus real `arc` (clockwise elliptical
arc, optional `closed` wedge), `line-pattern` (dashed foreground/background
pens) and `emboss` (per-channel edge kernel).  `56-ffi-library` is joined by `57-draw-aa` (coverage
ranges, caps, curve/spline ink, polygon fill) and `58-first-series` (the
`first`/`second`/`third`/`last`/`pick` semantics discovered while comparing
DRAW pixels: a date is `[year month day]`, a time `[hour minute seconds]`,
tuples/pairs by component and binary bytes as integers).

### DLL FFI (`load/library`, `routine!`, `struct!`)

The Windows dynamic loader is exposed the same way R2 exposes it:

* `lib: load/library %kernel32.dll` — `LoadLibraryA` on Win32, `dlopen` on
  POSIX.  The returned value is a distinct `library!` type; `mold` prints
  `library` and `free lib` calls `FreeLibrary`/`dlclose`.
* `make routine! [a [integer!] b [integer!] return: [integer!]] lib "MulDiv"`
  — resolves the export with `GetProcAddress`/`dlsym`, parses positional
  arguments and `return:` (integer!/char!/logic!/string!/decimal!/struct!),
  and stores a callable `routine!` value.  Calls pass up to 16 integer-sized
  arguments (integers, chars, logic, NUL-terminated strings, struct pointers)
  through a `__stdcall` function-pointer table on Win32 (cdecl on POSIX).
  `routine!` is a first-class value: `type? :r` is `routine!`, `mold` prints
  `routine`, and the evaluator calls it wherever it calls a native.
* `make struct! [a [integer!] b [char!]] none` — a packed byte buffer with
  `integer!` (4 bytes), `char!` (1), `logic!`/`pair!` (4/8), `decimal!` (8)
  and pointer-sized `string!`/opaque `struct!` fields.  `s/field` reads and
  writes, `third s` returns the raw `binary!`, `first`/`second` expose field
  names and values, and `mold` produces
  `make struct! [a [integer!] b [char!]] [42 #"Z"]`.

`get-func` is *not* a word in this 2.7.8.3.1 build (`value? 'get-func` is
false in the oracle); routines are always built with `make routine!`.

On POSIX the well-known Windows DLL names (`user32`, `kernel32`, `winmm`,
`avicap32`, …) resolve to a headless stub library; a few deterministic
exports (`MulDiv`, `lstrlenA`) are implemented so examples and the golden
case behave identically on both platforms.  The golden case
`56-ffi-library` exercises library identity, a real `MulDiv` call, routine
reflection and struct get/set/`third`/`mold` against the oracle.

### The 10-app demo (`examples/demo.r`)

The minified 2890-character demo (Paint, Game, Puzzle, Calendar, Video, IPs,
Email, Days, Sounds, FTP) now runs.  Getting it running exposed and fixed
several View/interpreter behaviours:

* **RATE timers** — `WM_TIMER` is dispatched to every face with a `rate`
  (integer events/sec, decimal, or `time!`; `rate 0` uses 50 ms).  Game and
  Video depend on `time` events reaching `feel/engage`.
* **Face-relative mouse offsets** — `feel/engage` events subtract the
  cumulative face/parent offsets, so Paint's `effect/draw` coordinates line
  up with the mouse; every `WM_MOUSEMOVE` sends `over` (not just the first
  entry), which makes freehand drawing continuous.
* **Input faces with an effect are canvases**, not native EDIT controls; the
  canvas painter applies `effect [draw ...]` (both a literal block and a
  word/block reference, as in the Game's `effect [draw b]`).
* **`to-image` of a face** renders background colour, face image + colorize,
  draw effect, edge, text and child panes into an `image!`; **`save/png`**
  writes a valid RGBA PNG (R2 transparency → PNG alpha).  Paint's Save now
  produces a real picture.
* **Cloned style/feel functions keep global bindings** — free words inside
  functions of a copied face object were being rebound to the face context,
  hiding the demo's globals (`s`, `b`, `d`, `w`, `cnt`, ...) from its feels.
* **`random` matches R2** — integer n → 1..n, pair → 1..n per component,
  tuple → 0..(n−1) per component.
* **Script title** — a `REBOL [title: ...]` header is applied when the
  script is run (`-s`/command line), giving `REBOL - Demo`; `load` only
  strips the header (R2 behaviour).
* **Window placement** — `view/new` windows were all created at (60,60),
  ignoring `center-face`'s offset.  The menu therefore sat on top of every
  demo window and intercepted the mouse/keys (Paint could not draw, Game got
  no input, Puzzle tiles did not click, Days' Start button was swallowed).
  Windows are now created at `face/offset`.
* **Activation/raise** — a new window is raised and activated after the
  creating action returns (`WM_APP+2`), so its first click is not consumed by
  window activation.
* **Canvas-style actions** — custom styles (`style p button ...`) are
  canvases; their `feel` runs the action.  After mouse up/down (and key
  actions) all controls are repositioned, so the Puzzle tile swap is visible.
* **Custom FEEL ⇒ canvas** — an `area`/`field` whose `feel` is not the shared
  `ctx-text/edit` object is drawn by the View engine even if the `effect`
  facet is not visible when the control is created.  This keeps Paint and
  Game from falling back to a native EDIT control on real Windows.
* **Build marker** — `rebol-view.exe -v` prints
  `REBOL/View 2.7.8.3.1 (demo19-2026-11-14)`; if the marker is missing the
  binary is an older download.
* **Popup-aware `wait []`** — `INFORM` shows a requestor and calls
  `DO-EVENTS` (`WAIT []`).  The clone's wait used to run until *all* windows
  closed, so `request-date`/`request-list` hung when the main window stayed
  open (Calendar/Days).  `VIEW_WAIT_POPUP` now waits only until the newest
  popup is removed.
* **Modal timer guard** — `ALERT` uses a native MessageBox whose modal loop
  re-entered the Game's `rate` timer repeatedly (`SCORE`/`unview` recursion,
  crash).  `WM_TIMER` is ignored while an alert is modal.
* **`arrow` effect** — Calendar's month arrows draw a filled rotated arrow
  polygon (previously blank buttons).
* **R2 file paths** — relative file values resolve against
  `SYSTEM/SCRIPT/PATH` (set by `CHANGE-DIR`), and `%/c/...` maps to the
  Windows `C:` drive.  `TO-FILE` also NUL-terminates its series (a missing
  terminator corrupted long result paths when `fopen` read past the end).

`read dns://` (local host name) and `read dns://host` (resolve to an IP)
are implemented for the IPs demo.  `parse`'s `copy`/`set` now create
previously undefined words in the word's binding context (string `copy`
and block `set`; string `set` is an R2 error).  The network demos improved
further this round: HTTP redirects are followed (Video/tinyurl), `load` of a
URL decodes images, FTP supports listing/files/upload and `dir?`, POP3 and
IMAP feed mailbox readers, and SMTP powers `send`.  IPs still depends on an external page,
and Email/FTP need real credentials/sites.

### Running the re-bol.com examples

`tools/examples_corpus.py fetch|extract|validate` downloads
<https://re-bol.com/examples.txt> (638 KB of prose + examples), splits it
into paragraph-sized snippets, keeps the ones that start with a known REBOL
function or set-word and that bracket-balance, validates them with the
clone's own `load`, and writes them to `examples-corpus/cases/`.
`tools/examples_sections.py` then replays each *section* in order (so examples
that build on earlier definitions behave like a user pasting them into the
console), with a prelude that stubs the interactive/GUI functions and a
native `R2_LOOP_LIMIT` cap so endless examples terminate, and reports every
snippet that errors.  325 snippets are extracted;
the sweep runs them all except network/interactive-port, third-party and
TUI cases.

The sweep found and fixed real gaps:

* **compact tokenization** — R2 ends a word at `{`, `}` as well as `[`, `(`,
  `"` and `;`, so `print"hi"`, `a[1]`, `foreach i [1 2 3][prin i]` and
  `find txt{do decompress }` all tokenize; the scanner's delimiter set was
  missing the brace characters.
* **directory reads** — `read %.` / `read %dir/` return a block of `file!`
  names (sub-directories keep a trailing `/`); `read %dir` (no slash) raises
  `cannot-open` like R2; `load` of a directory returns the same block (it used
  to crash on directories).
* **sorting files/URLs** — `sort` compares any-string values
  case-insensitively (`sort [%b %A %c]` -> `[%A %b %c]`), with `/case`
  honouring case.
* **mixed-type arithmetic** — R2 accepts either operand order for
  number/time (`2 * 0:00:01`, `0:00:01 + 2`, `0:00:03 - 2`), number/date
  (`2 + 1-Jan-2030`), time/date (`0:00:01 + date`) and number/money
  (`2 * $2.50`, `2 - $2.50`); `time / time` is an *integer* ratio while
  `money / money` is a decimal and `money * money` errors.
* **binary APPEND/INSERT** — like strings: binaries and strings append their
  bytes, chars append themselves, everything else appends its FORM
  (`append #{41} 66` -> `#{413636}`).
* **`system/options/binary-base`** — `mold` of binaries emits hex (16), bits
  (2) or base64 (64), wrapping base64 at 64 characters inside `64#{ ... }`.
* **cycle-safe `mold`** — R2 molds a self-referential object as
  `make object! [...]`; the molder now tracks the object stack, so molding a
  VID face (whose `parent-face`/`pane` links form cycles) no longer hangs or
  segfaults.

### The View event model and a working editor

`editor %file` now opens a functional editor.  The recovered View Desktop
drives everything through *event objects* passed to face `feel` functions
(`detect` for windows, `engage` for faces), so the renderer now builds R2
event objects (`type offset key face window value shift control alt
double-click time`) and dispatches them:

* `WM_KEYDOWN`/`WM_CHAR` -> `key` events (chars for printable and control
  keys, words for `home`/`end`/`page-up`/`page-down`/`insert`/`delete`/`f1..f12`),
  first to the window face's `feel/detect` (the editor's keymap: Ctrl-S,
  Ctrl-Q, Ctrl-O, Ctrl-F, ...), then to any face whose `keycode` matches;
  native edit controls still receive the keys when REBOL does not consume
  them;
* `WM_LBUTTONDOWN`/`UP`/`MOUSEMOVE`/`LEAVE` on canvas faces -> `down`/`up`/
  `over`/`away` events for `feel/engage` (R2's `sensor` runs the face action
  on `up`), which makes VID text hot-spots, checkboxes and the editor
  toolbar work;
* `WM_SIZE` -> a `resize` event (offset = new size) after the window face
  size is updated, but only for windows created with `/options [resize]`
  (the editor re-lays-out its area/scroller from it);
* `WM_CLOSE` -> a `close` event, so the editor can prompt/refuse to close;
* `focus`/`unfocus` bridge to Win32 `SetFocus` via `system/view/focal-face`.

Two renderer bugs blocked this: every `show` re-created child controls without
destroying the old ones (duplicate areas/fields stacked on top of each other),
and `show` of any face with a `pane` created a new top-level window (a
`show s1` on the editor's scroller popped up a blank `REBOL` window).  Only
faces that are direct children of `system/view/screen-face` become OS
windows now.

Window closing is now R2's default `unview/only`: a `WM_CLOSE` that no face
feel handles removes the window's face from `system/view/screen-face/pane`
before the HWND is destroyed.  Without that, a closed Help window stayed in
the pane, was re-created by the next `show`, and left the editor without an
event pump.  Child faces also get `parent-face` (the help Close button does
`unview/only face/parent-face`), and the screen face is sized to the display
(`GetSystemMetrics`) so VID's default face sizes match the reference.

The editor's **F5 / Ctrl-E "execute"** now works: the keymap runs `do-file`,
which saves and calls `launch/secure-cmd`; `LAUNCH` is implemented as R2's
"start a new REBOL interpreter process" (CreateProcess of
`rebol-view.exe -s <file>`, with `/install`/`/uninstall` flags and a
ShellExecute fallback), `RUN` opens a file/URL with the OS association, and
the command line understands `-s file`, `-q`, `--do code`, `-v` and `-h`.

Text faces gained full block rendering (newlines, `para/origin`,
`para/margin`, tab stops, wrapping, `font/align`, `valign`, shadows) and a
matching multi-line `size-text`; `trim/auto` now de-indents every line
relative to the first non-blank line, and `mold` follows R2's string rule
(quote up to 50 chars with no quote and fewer than three newlines, otherwise
braces).  Brace strings also process caret escapes.

Re-opening the editor (or any window) used to hang: destroying the last
window left a `WM_QUIT` in the thread queue (`PostQuitMessage` in
`WM_DESTROY`), so the *next* `do-events` returned immediately and left the
new window with no message pump.  The loop is now driven by the window list,
ignores stale `WM_QUIT` and waits with `WaitMessage`.

Character fidelity found along the way: R2 caret escapes were not implemented
(`#"^A"` parsed as `#"A"`, `#"^["` as `#"[`), and molding of control
characters produced raw bytes.  The scanner and molder now follow R2:
`^/ ^- ^M ^A..^Z ^[ ^\ ^] ^_ ^~ ^^`, `^(1B)` hex and `^(tab)`/`^(line)`/
`^(esc)`/`^(null)`/`^(del)`/`^(back)` names, with `#"`/`^{` escapes only in
char literals and brace molding for strings containing quotes.  `tail`/`head`
no longer dereference non-series values (a `tail` of a number crashed the
editor's focus code), and new natives `caret-to-offset`, `offset-to-caret`,
`textinfo`, `rgb-to-hsv` and `hsv-to-rgb` complete the text/colour API used
by the desktop (RGB<->HSV matches the oracle's byte-exact tables, including
red reported as hue 360).

Known gaps: exact AGG gamma/quantisation (the clone is within one
intensity step, not bit-exact on AA edges; emboss is close but border
pixels differ) and a few rarer DRAW features; advanced requestor
behaviour (live filters are untested); and memory reclamation.

`SOUND://` is implemented: `open sound://` returns a `port!`, `insert` accepts
the R2 sound object produced by `load` of a RIFF/WAVE file (or a WAV binary)
and starts asynchronous playback (`PlaySoundA` with `SND_MEMORY`), `wait`
pumps the event loop for the sample duration, and `close` stops it.  The WAV
codec parses RIFF chunks into the reference sound object
(`type/rate/channels/bits/volume/data`).  View nested panes are rendered and
hit-tested: block panes, object panes, and function panes called with an
index (TEXT-LIST's `text-pane`), including per-row `feel/redraw` selection
highlighting and row actions.

`arc` follows the reference syntax (`center radius angle-begin
angle-length [closed]`, clockwise, 0° to the right) and fills wedges when
`closed` is present; `line-pattern` alternates foreground/background pen
segments (and stays solid when no background pen is set), and `emboss`
applies the reference-style per-channel edge kernel.  Case
`68-draw-arc-pattern` covers all three.

The themed `request-list` and `request-dir` popups now work: nested-list rows
render and hit-test, `chg-dir` navigates, and Open returns the directory.
Doing that exposed a View-level composition bug (nested viewport origins were
reset instead of accumulated), plus R2 file/url/tag series semantics that the
requestors rely on (`last`, `length?`, `pick`, `find`, `remove`, `copy` and
file-key path append such as `path/:dir`).  Case `67-file-series-ops` covers
the series layer.  The editor Find dialog now focuses its field (`SYSTEM/VIEW/
FOCAL-FACE` was being read from the wrong context), Enter in a native FIELD
runs its action, and `unview/only`/`unview/all` remove just the intended
windows (the native re-registration avoids the boot function's stale-pane
behaviour).

Network support now includes passive-mode FTP and POP3 in `net.c`.  FTP
parses `MLSD` and falls back to Unix `LIST` (sub-directories keep their
trailing slash), supports `RETR`/`STOR`/`APPE`, binary/line reads and
`dir?`; POP3 performs `USER`/`PASS`/`STAT`/`RETR` with dot-unstuffing and
returns a block of message strings.  IMAP performs `LOGIN`/`SELECT` and
fetches message literals; SMTP implements `EHLO`, `AUTH PLAIN`/`LOGIN`,
`MAIL`/`RCPT`/`DATA`, so both direct ESMTP ports and the mezzanine `send`
function work.  HTTP redirects (301/302/303/307/308) are followed by both
WinHTTP and the POSIX client, and `load http://...` decodes image/sound
bodies.  `tools/net_smoke.py` starts local HTTP/FTP/POP/SMTP/IMAP servers
and verifies these paths on Linux and under Wine.

### MOLD flags, loop binding and CONTRAST (demo29)

The last formatted-`mold` gap (VID style objects losing their line breaks) was
not a style bug but a modelling error: **R2 stores the break as a flag on the
value**, plus one flag for the position just before the closing bracket.

* `mold` emits a break before *every* flagged value, including the first one
  of a block and the first one of a sub-series (`next`/`find`/`skip`/`at`),
  and puts the closing bracket on its own line when a break was emitted at
  that level or the tail flag is set.
* `copy`/`reduce`/`compose` keep the per-value flags and drop the tail flag;
  `insert`/`append` of a block carry the source's flags; `poke` clears the
  flag of the value it replaces.
* R2 keeps the integers `0` and `1` in a shared table, so `load "[^/1 2]"`
  loses the break that `load "[^/2 2]"` keeps — reproduced in the scanner.
* `compose` splices a block result (`/only` keeps it, `/deep` composes nested
  blocks) — both refinements were missing.

The internal deep copies used by `make object!` (style prototypes, inherited
feel/render functions) and by `make function!` now keep the markers, so
`mold select system/view/vid/vid-styles 'scroller` matches the reference
byte-for-byte (golden 85).

**Loop variables** are local to their loop yet visible inside nested blocks:
R2 binds the loop word in a temporary context and rebinds that name in the
body (paths included), so `repeat i 3 [append s rejoin [i " "]]` works inside
a function and does not leak.  The clone previously set the word through the
current context, which made any nested `rejoin`/`reduce` argument fail.

**`contrast n`** is a per-channel stretch around that channel's *image mean*
(`mean + trunc((v-mean)*num/den)`, `num/den = (18+n)/18` for `n>=0` and
`18/(25+|n|)` for `n<0`, `n` clamped to ±128, integer truncation).  This also
explains the earlier "contrast colours a neutral grey" observation: the probe
image's per-channel means were not equal.  `tint` (integer, a lossy
colour-space rotation) and `hsv` (tuple) remain unimplemented; the evidence
file records what they do.

`to-image` now paints an edge only when it is bevelled (or has an edge
image): R2 leaves the base face's plain `2x2` colour edge unpainted, which is
what the effect goldens expect.

### Evaluator set-paths and function copies (demo30)

Two R2 evaluation rules that the VID engine depends on were missing:

* **`obj/func/ref: value`** calls `func` with the refinements after it and
  `value` as the argument (`sld/resize/y: size/y`).  `obj/func: value` is
  still a plain assignment.
* **`obj/series/n/field: value`** indexes a block/paren first, then sets the
  field (`pane/2/size: 16x90`), which is how VID positions faces inside a
  pane block.

`make function!` now **copies** its spec and body (deep for nested blocks and
paths, keeping MOLD's break flags) — verified against the oracle — so a
function is immune to the later in-place binding of a shared module or style
block.  Without that, a style's `with [...]` function kept a prototype
binding for its facets and `make-face 'slider` raised `invalid-path`.
`make <object-prototype>` also rebinds the block fields it copies, so
`do inst/init` acts on the instance (R2 parity).

Consequence visible in the GUI: the TEXT-LIST/REQUEST-LIST `scroller` now
runs its `resize`, which calls `do pane/2/init`/`do pane/3/init`; the ARROW
style then builds `effect: [fit arrow <colour> 0.7 rotate 0|180]` and the
up/down scrollbar buttons are drawn (row selection highlight sits between
them).  `tests/gui-baseline/text-list.png` was renewed and golden 88 pins the
evaluator forms.

### Effect-dialect words and exact GRADIENT ramps (demo31)

The effect dialect resolves its words, so `EFFECT [gradient 1x0 blue gold]`
interpolates the tuples `blue`/`gold`.  The clone read the raw words, which
made such a face paint nothing (a gradient box was simply missing from the
widgets screenshot).

GRADIENT's ramp was pinned byte-exactly: each component moves from colour 1
toward colour 2 with `c1 + trunc((c2-c1)*i/n)`, `i` in `0..n-1`, `n` the
width (`1x0`) or height (`0x1`), negative components reversing the order and
a diagonal pair projecting on the vector.  The clone used an `(n-1)` lerp
scaled through 255 (one or two steps off) and ignored the direction (always
vertical).  `draw.c`'s `Img_Gradient` is now shared by `to-image` and the
draw-dialect `gradient` command, and `view_win.c` uses the same maths on
screen; golden 89 pins seven ramps and the widgets GUI baseline was renewed.
Buttons/fields still lack R2's stock-image look (needs `extend`/`fit`
placement parity) — documented.

### Face image placement (demo32)

R2 blits a face's image at the **top-left at its natural size and clips it**;
it never centres and never scales unless the effect contains `fit`/`aspect`
(nearest-neighbour).  The clone centred smaller images, centre-clipped larger
ones and `to-image` stretched everything to the face size — now both
renderers match (golden 90, and the image-effects GUI baseline was renewed
because its `rotate 90` tile is clipped like R2).  `extend` (the stock button
image is 7x14 and the BTN style stretches it with `extend 14`) is still
unimplemented: an integer argument pins the last column/row at the far edge
and fills the gap with the column before it, but the pair forms behave
differently, so buttons keep the clone's flat look for now.

### Corpus differential sweep taken to one line (demo34)

demo34's job was to drive the differential harness to zero.  The whole
`examples.txt` document (28146 compared output lines) now differs in **one**
line: a text face's private layout cache (`state: 1052x821` in the reference
vs `state: 1x1`) inside a moulded `layout` face — that field is recomputed
when the face is shown, and the GUI screenshot regression stays at 0.00 %.
Everything else in the corpus is byte-identical, which required these
reverse-engineered behaviours (all pinned by goldens 94-103):

* **PARSE split mode.**  With `none` or a string as the rules, PARSE splits
  into strings.  Delimiters = the rule's characters + R2's whitespace class,
  which is *not* `isspace()`: every byte `<= 0x20` except NUL, plus `0x7F`
  (DEL) and `0xA0` (Latin-1 no-break space).  A run of `k` whitespace-free
  delimiters produces `k-1` empty fields; whitespace inside a run is
  absorbed; the field before a run is always emitted (empty at the start of
  the series) and the field after a trailing run is not
  (`parse "a,,b" ","` -> `["a" "" "b"]`, `parse ",a,b," ","` ->
  `["" "a" "b"]`, `parse "a  b" " "` -> `["a" "b"]`, `parse "a , , b" ","`
  -> `["a" "" "b"]`).  `/ALL` removes the whitespace delimiters from the set.
  Binary input yields a block of strings, and a char rules argument raises
  `script/expect-arg` (`rules [block! string! none!]`).
* **`load` of a binary** sniffs images and WAV sounds and otherwise returns
  the binary *unchanged* — no header or text parsing, for every refinement.
* **The MOLD line-break flag lives on the VALUE**, not on the series.  That
  refactor (the clone used to keep it per series position) fixed a whole
  class of cosmetic mold differences: `reduce`/`compose`/`to-*` carry the
  flags of the values they produce, `poke`/`change`/`insert` keep the new
  value's flag, and the VID style sheet now moulds byte-identically.
  R2's `reduce` carries only the flags *on the resulting value*, not the
  source position's; `compose` drops a paren's position flag.
* **`form` of an object** is `name: mold value` per field, newline
  terminated, with no `make object!` wrapper (`form make object! []` is `""`).
* **Word equality vs `find`**: `=`/`same?` treat word/lit-word/set-word/
  get-word/refinement with the same name as equal, but `find`/`select`
  require the same word type (VID's `here/1 <> 'none` test depends on the
  first rule, `select style-sheet 'style-name` on the second).
* **`type?/word`** returns a word (moulds with the bang); `type?` returns the
  datatype (moulds without).
* **`at` is relative and 1-based** (`at s 1` = `s`, `at s 2` = `next s`,
  `at tail s -2` = two positions back), and **`copy/part` with a negative
  length copies backwards** from the position (clamped at the head).
* **`trim` modifies its series in place** for every refinement; the blank
  class is space/tab/CR/LF; `/lines` joins lines with single spaces, `/auto`
  removes the common indentation.
* **`set` with a block of words**: element-wise for a block value, the same
  value for every word otherwise, and missing values are padded with `none`
  even without `/pad`.
* **`min`/`max` promote to decimal** when either argument is decimal
  (`min 1 1.0` -> `1.0`), which is what makes the SLIDER style's
  `ratio: min 1 max 0 val` mould as `1.0`.
* **`sort/compare`**: the comparator answers "should x come before y?", so
  TRUE means "less"; blocks compare lexicographically, text series compare
  case-insensitively and from the current index.
* **`find` works on binaries** with string/binary/char patterns (and
  `/tail`, `/last`, `/reverse`).
* **`foreach`** iterates the characters of *any* string series (file!, url!,
  tag!, issue!) and the bytes of a binary.
* **Argument checking and access errors**: `index?`/`head`/`tail`/`next`/
  `back`/`skip`/`at` reject non-series values with `script/expect-arg` whose
  arg3 is the accepted-types block (`[series! port!]`); `read`/`write`/
  `exists?`/`delete`/`size?`/`dir?`/`rename` check their arguments; a missing
  file raises `access/cannot-open` with the absolute path, `delete`/`rename`
  raise `no-delete`/`no-rename` with the **file** as arg1, `make-dir` raises
  `no-make-dir`, an unknown port scheme (or a block that is not a port spec)
  raises `access/invalid-spec`, and `disarm` of a non-error raises
  `expect-arg`.  The strict series checks are enabled once the boot modules
  are loaded (the boot phase itself relies on the lenient helpers).
* **`set-modes`/`get-modes`** follow R2 2.7.8: the real file-permission modes
  (`world-read:` ...) are rejected with `script/invalid-arg` whose arg1 is the
  offending set-word, `get-modes` only answers a port's own modes
  (`lines`/`binary`/`direct` ...) and rejects everything else.
* **PNG alpha**: R2 converts the file's alpha to its transparency byte with
  `n=0 -> 255`, `n=1..127 -> 256-n`, `n=128..255 -> 255-n` (measured with a
  PNG carrying every alpha value), and fully transparent pixels lose their
  colour.  The stock button images carry alpha 50, so this off-by-one was
  visible in the style sheet.
* **Bold text metrics**: a second Arial advance table measured from the
  reference (`layout [text bold ...]` at every size 8..48) plus a per-size
  inter-character gap table.  Single characters are exact; long bold strings
  can still be a pixel or two off because GDI kerns bold text per pair.

### Corpus differential harness and the bugs it found (demo33)

`tools/examples_sections.py --diff` replays a section in both the reference
and the clone and diffs the output (the result file is rewritten after every
snippet so a stalled reference still leaves a comparable prefix, and the
reference gets a relative result path because it cannot write `to-file
"Z:/..."`).  The first sweep found four real divergences, now fixed:

* **`change` on strings** replaces `length? new-text` characters by default
  (`change copy "Tom" "Phil"` -> `"Phil"`, `change copy "abcdef" [1 2 3]` ->
  `"123def"`), while blocks still replace one element and `/part` overrides.
* **Paths with paren components** (`b/(i)`, `o/(w)`, `m/(j)/(1)`): the paren
  is evaluated (including in set-paths, which previously broke the scanner).
* **Directory listings** from `read %dir/` are sorted case-insensitively.
* **User-function argument type checking**: R2 enforces a spec's `[types...]`
  block at call time (`f1 expected a argument of type: integer`), rejects
  `none` unless allowed, checks refinement arguments, and errors on a missing
  argument.  Datatype words in a spec are normalised to datatype values,
  which is why HELP prints `(Type: integer)` without the `!`; R2's typeset
  names (`series!`, `number!`, `any-string!`, ...) are matched by name.

Goldens 91-93 pin the path forms, the type checks and `change`.

## 7. Limitations and ethics

The reference executable is freeware and remains the property of REBOL
Technologies.  This project is an interoperability / preservation effort:
it recovers the publicly distributed binary's embedded REBOL source and
re-implements the interpreter.  The recovered source is retained for
study and completion of the clone.
