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.

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.