Skip to content

MoonLive

Source: MoonLive.h

MoonLive

class MoonLive
src/core/moonlive/MoonLive.h:22

Compiling a script to native code and running it over a host-supplied buffer.

Public Methods

MoonLive() = default : An engine with nothing compiled, until a compile call fills it.

inline ~MoonLive() : Release the exec block and the control arena.

MoonLive(const MoonLive &) = delete : Never copied: each scripted module holds its own engine.

bool compile(uint8_t r, uint8_t g, uint8_t b) : Compile a fixed-color program direct from the emitter.

bool compile(const char * source, const BuiltinTable & table, const SysVarTable & sysvars) : Compile source text, resolving calls against the host's registered builtins.

bool compileAnimated() : Compile the animated routine, whose color derives from the per-frame t.

inline bool ok() const : Whether a program is compiled and callable.

inline CtrlFn entry(const char * name) const : The compiled function named name, or null when the script defined none.

inline RetType retTypeOf(const char * name) const : What a named entry point declared it returns, or Void when the script has no such function.

inline const uint8_t * entryCode(const char * name) const : The address of a named entry point, with no signature attached.

inline const char * entryName(uint8_t i) const : The name of the function at index i, or null past the end.

inline uint8_t entryCount() const : How many functions the script defined.

inline const char * error() const : The diagnostic from the last compile, or an empty string.

inline uint16_t errorPos() const : Where the last compile failed, as a character offset into the source.

inline bool hasErrorPos() const : Whether errorPos means anything, which only a parse failure gives.

inline void run(uint8_t * buf, uint32_t nLights, uint8_t cpl, uint32_t t, const char * name = nullptr) const : Run the entry point called name, or the whole program when name is null.

inline uintptr_t runValue(const char * name, RetType want, uintptr_t fallback = 0, uint8_t * buf = nullptr, uint32_t nLights = 0, uint8_t cpl = 0, uint32_t t = 0) const : Run the entry point called name and return its answer, or fallback when it has none.

inline int32_t readSlot(uint8_t offset) const : Read a member's 4-byte slot, little-endian.

inline void writeSlot(uint8_t offset, int32_t v) : Write a member's 4-byte slot, little-endian.

inline void addDeclaredControl(const char * name, uint8_t offset, int32_t lo, int32_t hi, CtrlType type = CtrlType::Int) : Append a control the running defineControls() declared.

inline void clearDeclaredControls() : Forget the controls a previous defineControls() declared, so re-running it rebuilds.

inline bool hasEntry(const char * name) const : Does the script define this entry point? A binding asks before reporting "no tick() to run".

void free() : Release the exec block and the control arena.

void freeCode() : Drop the compiled code, keeping the control arena.

inline size_t codeLen() const : How many bytes of machine code the current program is.

inline size_t codeCap() const : The allocated exec-block size, which is the heap held.

inline size_t heapBytes() const : Every heap byte this engine holds: the exec block plus the control arena.

inline void describe(char * out, size_t cap) const : Write the program's size and the one budget it is closest to exhausting into out.

inline const DeclaredControl * declaredControls(uint8_t & count) const : The controls the last compile declared, which the binding turns into real module controls.

inline uint8_t * controlSlot(uint8_t offset) : The live byte at an arena offset, or null for an offset the arena does not hold.

More info

A compile turns a program into native code and places it in executable memory, and a run calls it. The path is emit, allocate, call, write, and it is the same on Xtensa, RISC-V and the host.

The engine is domain-neutral by construction: it includes the compiler and platform seams and never a light type. The binding is what wraps it as a MoonModule.