Keywords · ROOT

ROOT

The ROOT is the whole program — the outermost scope, the one thing every other keyword sits inside. It is not written: there is no ROOT line in source, only the program file itself. Anything not nested inside another keyword is at the Root.

Format

ROOT has no keyword of its own. It is the top of the tree: the lines with no indentation are its direct members.

ROOT ::= { MODULE | NATIVE | runStatement }
runStatement ::= CALL | LET | STATE | WITH | COMMENT
The Root holds declarations (MODULE, NATIVE) and the statements of the run body, in source order.

In the canonical form the Root is the value Code.Language.Program.Structure: three arrays — its modules, its natives, and its run body.

Usage

The ROOT has no container — it is the program. Everything below is one of the three kinds it holds.

Modules

A MODULE at the Root opens the outermost namespace its members are named under.

MODULE App
  FUNCTION Text Greeting
    = "Hello"
A module declared at the Root, opening the App namespace.

Native setup

A NATIVE block at the Root is per-target setup that runs once as the program starts.

NATIVE js "globalThis.__boot = Date.now()"
Native setup recording the program's start time on the JavaScript target.

The run body

Lines that are neither a module nor native setup make up the run body — the code that actually executes. A bare CALL is the usual entry point.

App.Show "ready"
A call on its own line at the Root: the program's entry point.

Can Contain

The Root holds three kinds of line, in any order.

Containing a MODULE

A module at the Root, opening a root namespace for the declarations inside it.

MODULE Code
  TYPE Value
    OPTION Text text
A module at the Root, naming everything inside it under Code.

Containing a NATIVE

Per-target setup that runs once as the program starts — the only place native setup lives outside a module.

NATIVE js "console.log('starting')"
A Root-level native setup block on the JavaScript target.

Containing a CALL

A function called on its own line: a statement in the run body. This is how a program does anything.

App.Start
A bare call in the Root's run body.

Containing a LET

A binding in the run body, computed as the program runs.

LET Text greeting = App.Greeting
A LET at the Root, part of the run body.

Targets

How the Root renders.

JavaScript

// modules become namespace objects, native setup runs at load,
// and the run body executes as the entry point
globalThis.__boot = Date.now();
App.Show();

JSON

["ROOT",
  [ ["MODULE", "App", [], [], [], [], [], []] ],
  [ ["NATIVE", "js", "globalThis.__boot = Date.now()"] ],
  [ ["CALL", "App.Show", [], []] ]
]

Related

The Root holds MODULE declarations, NATIVE setup, and a run body whose entry point is a CALL. Its canonical shape is Code.Language.Program.Structure. Back to the language.