Skip to content

Source: MoonLiveBuiltins.h

MoonLiveBuiltins

The neutral seam a host fills with its own vocabulary.

Enumerations

Name Description
CtrlType
InlineOp
BuiltinKind
SysVarKind A name the host defines and the script only reads.

CtrlType

enum CtrlType
Value Description
Int
Byte
Bool
Fixed
Str

InlineOp

enum InlineOp
Value Description
StoreElem
StoreFirst
FillElems

BuiltinKind

enum BuiltinKind
Value Description
Call
Inline

SysVarKind

enum SysVarKind

A name the host defines and the script only reads.

Value Description
Arena
Arg

Typedefs

Return Name Description
uint32_t(*)(const uintptr_t *args, uint32_t argc, const uint8_t *arena) HostCallFn

HostCallFn

using HostCallFn = uint32_t(*)(const uintptr_t *args, uint32_t argc, const uint8_t *arena)

Functions

Return Name Description
constexpr uint8_t ctrlWidth constexpr Bytes one array element occupies.
constexpr uint8_t ctrlSlotBytes constexpr Bytes a scalar occupies, which is always four whatever its type.
constexpr size_t codeCapFor constexpr Bytes to reserve for a script of tokens tokens.
constexpr uint8_t scriptArgOffset constexpr The arena byte offset of argument i.

ctrlWidth

constexpr

constexpr constexpr uint8_t ctrlWidth(CtrlType t)

Bytes one array element occupies.


ctrlSlotBytes

constexpr

constexpr constexpr uint8_t ctrlSlotBytes(CtrlType)

Bytes a scalar occupies, which is always four whatever its type.


codeCapFor

constexpr

constexpr constexpr size_t codeCapFor(uint32_t tokens)

Bytes to reserve for a script of tokens tokens.


scriptArgOffset

constexpr

constexpr constexpr uint8_t scriptArgOffset(uint8_t i)

The arena byte offset of argument i.

Variables

Return Name Description
constexpr uint8_t kCtrlBytes static constexpr Bytes the script's own members may occupy.
constexpr uint8_t kMaxCtrls static constexpr
constexpr size_t kCodeCap static constexpr
constexpr uint8_t kMaxSysVars static constexpr
constexpr uint8_t kSysVarBytes static constexpr Bytes per system variable.
constexpr uint8_t kDepthSlot static constexpr Where the emitted code keeps its recursion depth.
constexpr uint8_t kMaxCallDepth static constexpr The depth at which a call is refused, so 31 activations execute and the 32nd returns.
constexpr uint8_t kMaxScriptArgs static constexpr Where a script call's arguments are passed.
constexpr uint8_t kScriptArgBytes static constexpr
constexpr uint8_t kScriptArgBase static constexpr Where the argument block starts, aligned to four bytes because these are 32-bit slots.
constexpr uint8_t kArenaBytes static constexpr How many bytes the whole arena holds.

kCtrlBytes

static constexpr

constexpr uint8_t kCtrlBytes = 64

Bytes the script's own members may occupy.


kMaxCtrls

static constexpr

constexpr uint8_t kMaxCtrls = 8

kCodeCap

static constexpr

constexpr size_t kCodeCap = 16384

kMaxSysVars

static constexpr

constexpr uint8_t kMaxSysVars = 8

kSysVarBytes

static constexpr

constexpr uint8_t kSysVarBytes = 4

Bytes per system variable.


kDepthSlot

static constexpr

constexpr uint8_t kDepthSlot = kCtrlBytes + kMaxSysVars * kSysVarBytes

Where the emitted code keeps its recursion depth.


kMaxCallDepth

static constexpr

constexpr uint8_t kMaxCallDepth = 32

The depth at which a call is refused, so 31 activations execute and the 32nd returns.


kMaxScriptArgs

static constexpr

constexpr uint8_t kMaxScriptArgs = 4

Where a script call's arguments are passed.


kScriptArgBytes

static constexpr

constexpr uint8_t kScriptArgBytes = 4

kScriptArgBase

static constexpr

constexpr uint8_t kScriptArgBase = static_cast<uint8_t>((kDepthSlot + 1 + 3) & ~3)

Where the argument block starts, aligned to four bytes because these are 32-bit slots.


kArenaBytes

static constexpr

constexpr uint8_t kArenaBytes = kScriptArgBase + kMaxScriptArgs * kScriptArgBytes

How many bytes the whole arena holds.

Builtin

struct Builtin
src/core/moonlive/MoonLiveBuiltins.h:48

Public Attributes

const char * name = nullptr : The script-visible name, owned by the host.

uint8_t argc = 0 : How many arguments the builtin takes.

bool returns = false : Whether the call produces a value rather than acting as a statement.

BuiltinKind kind = BuiltinKind::Call : Whether this lowers to a host call or an inline op.

HostCallFn fn = nullptr : The host function a Call targets.

InlineOp inlineOp {} : The neutral opcode tag an Inline op carries.

uint8_t byRef = 0 : Which arguments are passed by reference, a bit per position.

uint8_t byStr = 0 : Which arguments must be a string literal, a bit per position.

uint8_t fixedArgs = 0 : Which arguments are fixed-point rather than whole numbers, a bit per position.

bool fixedReturn = false : Whether the result is fixed-point.

BuiltinTable

struct BuiltinTable
src/core/moonlive/MoonLiveBuiltins.h:86

Public Attributes

Builtin items : The registered builtins.

uint8_t count = 0 : How many builtins are registered.

bool overflowed = false : Set when an add was dropped for lack of room.

Public Methods

inline bool add(const Builtin & b) : Register one builtin, returning false when the table is full.

inline bool full() const : True when a registration was dropped for lack of room.

inline uint8_t registered() const : Every registered name, for the overflow diagnostic. Not used on any hot path.

inline const Builtin * find(const char * name, size_t len) const : The builtin registered under name, or null when there is none.

Public Static Attributes

constexpr uint8_t kMax = 96 : How many builtins one table holds.

SysVar

struct SysVar
src/core/moonlive/MoonLiveBuiltins.h:174

Public Attributes

const char * name = nullptr : The script-visible name, owned by the host.

SysVarKind kind = SysVarKind::Arena : Whether the value lives in the arena or in an argument register.

uint8_t where = 0 : The arena byte offset, or the argument register, by kind.

SysVarTable

struct SysVarTable
src/core/moonlive/MoonLiveBuiltins.h:184

The system variables one host domain defines, which the compiler resolves names against.

Public Attributes

SysVar items : The registered system variables.

uint8_t count = 0 : How many system variables are registered.

Public Methods

inline bool add(const SysVar & v) : Register one system variable, returning false when it cannot be held.

inline const SysVar * find(const char * name, size_t len) const : The system variable registered under name, or null when there is none.

Public Static Attributes

constexpr uint8_t kMax = kMaxSysVars : How many system variables one table holds.

More info

The core compiler knows only that a name maps to a descriptor, owning no function names and no domain semantics.

What a descriptor decides

A descriptor says how a call lowers. A Call is a pure host helper, lowered to a generic call. An Inline is a routine the backend emits without per-call overhead, carrying a neutral opcode tag the per-ISA lowering knows, which the core threads through without interpreting.

Macros

Name Description
MM_ASSERT_NO_BUILTIN_OVERFLOW Assert a host's builtin table did not silently drop a registration.

MM_ASSERT_NO_BUILTIN_OVERFLOW

MM_ASSERT_NO_BUILTIN_OVERFLOW()

Assert a host's builtin table did not silently drop a registration.