Compiler

typedef struct ml_compiler_t ml_compiler_t;

Represents a Minilang compiler. This is an opaque structure with no user accessible fields.

typedef ml_value_t *(*ml_getter_t)(void *Globals, const char *Name);

Signature for callbacks for looking up global identifiers. If Name is not found, NULL should be returned.

typedef const char *(*ml_reader_t)(void*);

Signature for callbacks for reading input for a compiler. If the end of input is reached, NULL should be returned.

ml_compiler_t *ml_compiler(ml_getter_t GlobalGet, void *Globals, ml_reader_t Read, void *Input);

Creates a new ml_compiler_t.

const char *ml_compiler_name(ml_compiler_t *Compiler);

Returns the name of the current source location of the compiler.

ml_source_t ml_compiler_source(ml_compiler_t *Compiler, ml_source_t Source);

Sets the source location of the compiler and returns the previous source location.

void ml_compiler_reset(ml_compiler_t *Compiler);

Resets the compiler by clearing any cached input and pending tasks.

void ml_compiler_input(ml_compiler_t *Compiler, const char *Text);

Sets the next input text in the compiler.

const char *ml_compiler_clear(ml_compiler_t *Compiler);

Returns any cached input and clears it in the compiler.

void ml_compiler_error(ml_compiler_t *Compiler, const char *Error, const char *Format, ...) __attribute__((noreturn));

Raises a compiler error to the latest call to the compiler.

void ml_function_compile(ml_state_t *Caller, ml_compiler_t *Compiler, const char **Parameters);

Compiles a function from the source code available to the compiler. This may be asynchronous, when complete Caller is run with the compiled function or an error value.

void ml_command_evaluate(ml_state_t *Caller, ml_compiler_t *Compiler);

Compiles and executes a single command from the source code available to the compiler. This may be asynchronous, when complete Caller is run with the result of the command.

void ml_load_file(ml_state_t *Caller, ml_getter_t GlobalGet, void *Globals, const char *FileName, const char *Parameters[]);

Creates a compiler with specified globals that reads and compiles a function from the source code in FileName. This may be asynchronous, when complete Caller is run with the compiled function or an error value.

ml_value_t MLEndOfInput[];

ml_value_t returned by a compiler when the end of input is reached.

ml_value_t MLNotFound[];

ml_value_t expected from a ml_getter_t when the given name is not found.

ml_type_t MLCompilerT[];

Compiler type. Usually made available to Minilang code as compiler.

ml_value_t *ml_stringmap_globals(stringmap_t *Globals);

Creates a Minilang function that looks up names in Globals and returns MLNotFound if not present.