Targets · JavaScript · Native modules
Native modules
Where a capability can only be expressed in the host language, a NATIVE function supplies a body per target. For JavaScript those bodies live in native modules: hand-written source the compiler splices in and registers, so generated code can call it by name. It is how modules like Text and Maths, and the driver-facing modules, reach real JavaScript.
Contents
How a Program becomes JavaScript, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the JavaScript target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Coding standards — the Frenzi coding standards the generated code follows, global and JavaScript-specific.
- Example — a full program using every keyword, and the JavaScript it renders to.
- Naming considerations — how Program's dotted names are carried into JavaScript.
- Entry point — the generated
main()that wires up the drivers and starts the reactive cycle. - Drivers — the native drivers that provide capabilities like the user interface and animation, draining each cycle's emissions.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written, per-platform JavaScript behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to JavaScript.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words JavaScript keeps for itself, and how a Program name that collides with one is escaped.
What a native module is
Most of a program is written in Program and rendered to JavaScript. A
NATIVE function is the exception: its body is written by
hand, once per target. For JavaScript those hand-written bodies live in native modules —
plain .js the compiler drops in wherever the native function is called.
The registry
Each native module's top-level functions and classes are gathered into a registry, so generated code can reach them by name. A rendered call to a native simply looks it up and runs it — there is no import graph to thread through the output, and nothing for user names to collide with.
Drivers live here
The drivers are native code. A module that
touches the outside world — the interface, animation, the network — provides its driver
from its own native module: Ui.Dom.Driver, Animate.Frame.Driver,
Network.Web.Driver. This is the one place the real platform — the DOM,
fetch, requestAnimationFrame — is touched, and it is kept behind the
driver contract.
The runtime is native too
Reactive and Context are themselves native modules; they are bundled first so everything else can build on them. The result is a single, dependency-free artifact — runtime, native bodies, and the rendered program, in one file a page can drop in. See the runtime and entry point.