C API Reference
Every public function, type, enum, and macro in mino.h. Auto-generated from the source.
Value types
mino_val_ttypedef
typedef struct mino_val mino_val_t;mino_env_ttypedef
typedef struct mino_env mino_env_t;mino_prim_fntypedef
typedef mino_val_t *(*mino_prim_fn)(mino_val_t *args, mino_env_t *env);struct mino_valstruct
| Type | Field | Description |
|---|---|---|
mino_type_t | type | |
int | b | MINO_BOOL: 0 or 1 |
long | long | MINO_INT |
double | f | MINO_FLOAT |
char | *data | |
size_t | len | |
} | s | |
mino_val_t | *car | |
mino_val_t | *cdr | |
const | char | source file (NULL if unknown) |
int | line | source line (0 if unknown) |
} | cons | |
mino_vec_node_t | *root | trie spine (NULL when len <= 32) |
mino_vec_node_t | *tail | partial leaf, 1..32 slots used |
unsigned | tail_len | number of valid slots in tail |
unsigned | shift | height of root in multiples of 5 |
size_t | len | total element count |
} | vec | |
mino_hamt_node_t | *root | HAMT root (NULL when len == 0) |
mino_val_t | *key_order | MINO_VECTOR of keys, insertion order |
size_t | len | number of entries |
} | map | |
mino_hamt_node_t | *root | HAMT root (NULL when len == 0) |
mino_val_t | *key_order | MINO_VECTOR of elements |
size_t | len | number of elements |
} | set | |
const | char | |
mino_prim_fn | fn | |
} | prim | |
mino_val_t | *params | |
mino_val_t | *body | |
mino_env_t | *env | |
} | fn | |
void | *ptr | |
const | char | static or interned; not GC-owned |
} | handle | |
mino_val_t | *val | |
} | atom | |
mino_val_t | *body | unevaluated form list (NULL after force) |
mino_env_t | *env | captured environment (NULL after force) |
mino_val_t | *cached | realized cons/nil (valid after force) |
int | realized | 0 = pending, 1 = forced |
} | lazy | |
mino_val_t | *args | |
} | recur | |
mino_val_t | *fn | |
mino_val_t | *args | |
} | tail_call |
Constructors
mino_nil
mino_val_t *mino_nil(void);mino_true
mino_val_t *mino_true(void);mino_false
mino_val_t *mino_false(void);mino_int
mino_val_t *mino_int(long long n);mino_float
mino_val_t *mino_float(double f);mino_string
mino_val_t *mino_string(const char *s);mino_string_n
mino_val_t *mino_string_n(const char *s, size_t len);mino_symbol
mino_val_t *mino_symbol(const char *s);mino_symbol_n
mino_val_t *mino_symbol_n(const char *s, size_t len);mino_keyword
mino_val_t *mino_keyword(const char *s);mino_keyword_n
mino_val_t *mino_keyword_n(const char *s, size_t len);mino_cons
mino_val_t *mino_cons(mino_val_t *car, mino_val_t *cdr);mino_vector
mino_val_t *mino_vector(mino_val_t **items, size_t len);mino_map
mino_val_t *mino_map(mino_val_t **keys, mino_val_t **vals, size_t len);mino_set
mino_val_t *mino_set(mino_val_t **items, size_t len);mino_prim
mino_val_t *mino_prim(const char *name, mino_prim_fn fn);mino_handle
mino_val_t *mino_handle(void *ptr, const char *tag);mino_atom
mino_val_t *mino_atom(mino_val_t *val);mino_is_handle
int mino_is_handle(const mino_val_t *v);Handle accessors — return NULL/0 if the value is not a handle.
mino_handle_ptr
void *mino_handle_ptr(const mino_val_t *v);mino_handle_tag
const char *mino_handle_tag(const mino_val_t *v);mino_is_atom
int mino_is_atom(const mino_val_t *v);Atom accessors — mutable reference cells.
mino_atom_deref
mino_val_t *mino_atom_deref(const mino_val_t *a);mino_atom_reset
void mino_atom_reset(mino_val_t *a, mino_val_t *val);Predicates and accessors
mino_is_nil
int mino_is_nil(const mino_val_t *v);mino_is_truthy
int mino_is_truthy(const mino_val_t *v);mino_is_cons
int mino_is_cons(const mino_val_t *v);mino_eq
int mino_eq(const mino_val_t *a, const mino_val_t *b);mino_car
mino_val_t *mino_car(const mino_val_t *v);mino_cdr
mino_val_t *mino_cdr(const mino_val_t *v);mino_length
size_t mino_length(const mino_val_t *list);mino_to_int
int mino_to_int(const mino_val_t *v, long long *out);Type-safe C extraction. Each returns 1 on success, 0 on type mismatch.
mino_to_bool uses truthiness (only nil and false are falsey).
mino_to_float
int mino_to_float(const mino_val_t *v, double *out);mino_to_string
int mino_to_string(const mino_val_t *v, const char **out, size_t *len);mino_to_bool
int mino_to_bool(const mino_val_t *v);Printer
mino_print
void mino_print(const mino_val_t *v); /* to stdout, no newline */mino_println
void mino_println(const mino_val_t *v); /* to stdout, with newline */mino_print_to
void mino_print_to(FILE *out, const mino_val_t *v);Reader
mino_read
mino_val_t *mino_read(const char *src, const char **end);Read one form from src. On success returns a value and writes a pointer
just past the consumed input to *end (when end is non-NULL). On EOF
(only whitespace / comments remaining) returns NULL with *end advanced
past the trailing whitespace. On parse error returns NULL and writes a
human-readable message via mino_last_error().
mino_last_error
const char *mino_last_error(void);Environment and evaluator
mino_env_new
mino_env_t *mino_env_new(void);Allocate a fresh root environment and register it with the collector so
every value reachable through it survives collection. The runtime holds
the returned env weakly: mino_env_free unregisters it and lets the next
sweep reclaim the frame and any closures that were reachable only from
within it. The host does not free any mino-owned pointers directly.
mino_env_free
void mino_env_free(mino_env_t *env);mino_new
mino_env_t *mino_new(void);Convenience: allocate a new env and install core bindings in one call.
Equivalent to mino_env_new() followed by mino_install_core().
mino_env_set
void mino_env_set(mino_env_t *env, const char *name, mino_val_t *val);Define or replace a binding in env.
mino_env_get
mino_val_t *mino_env_get(mino_env_t *env, const char *name);Look up name. Returns NULL if unbound.
mino_install_core
void mino_install_core(mino_env_t *env);Install the core primitive bindings into env:
arithmetic + - * / mod rem quot
bitwise bit-and bit-or bit-xor bit-not bit-shift-left
bit-shift-right
comparison = < <= > >= not=
list car cdr cons list
collection count nth first rest vector hash-map assoc dissoc get conj
keys vals
sets hash-set set? contains? disj
sequences seq realized? reduce into apply reverse sort
predicates cons? nil? string? number? keyword? symbol? vector? map?
set? fn? empty?
utility not identity
coercion int float
reflection type name doc source apropos
strings str pr-str read-string format subs split join char-at
starts-with? ends-with? includes? upper-case lower-case
trim
exceptions throw
modules require
macros macroexpand macroexpand-1 gensym
core.mino: when cond and or -> ->> map filter take drop range repeat
concat update some every? comp partial complement
Special forms (quote, quasiquote, unquote, unquote-splicing, def,
defmacro, if, do, let, fn, loop, recur, try, lazy-seq) are recognized by
the evaluator and do not need to be installed.
NOTE: no I/O primitives are installed by this function. Call
mino_install_io to opt in to println, prn, and slurp.
Safe to call on a fresh env.
mino_install_io
void mino_install_io(mino_env_t *env);Install I/O primitives: println, prn, slurp, spit, exit. These are kept
separate from mino_install_core so that sandboxed environments start with
no I/O capability; the host opts in by calling this function.
mino_eval
mino_val_t *mino_eval(mino_val_t *form, mino_env_t *env);Evaluate one form. Returns NULL on error and writes a message via
mino_last_error(). Returns mino_nil() for an explicit nil result.
mino_eval_string
mino_val_t *mino_eval_string(const char *src, mino_env_t *env);Read and evaluate all forms in src. Returns the value of the last
form, or NULL on error. An empty string returns mino_nil().
mino_load_file
mino_val_t *mino_load_file(const char *path, mino_env_t *env);Read a file at path and evaluate all forms. Returns the value of the
last form, or NULL on error (file I/O failures and parse/eval errors).
mino_register_fn
void mino_register_fn(mino_env_t *env, const char *name, mino_prim_fn fn);Shorthand: bind a C function as a primitive in env.
Equivalent to mino_env_set(env, name, mino_prim(name, fn)).
mino_call
mino_val_t *mino_call(mino_val_t *fn, mino_val_t *args, mino_env_t *env);Call a callable value (fn, macro, prim) with an argument list.
Returns the result, or NULL on error (via mino_last_error).
mino_pcall
int mino_pcall(mino_val_t *fn, mino_val_t *args, mino_env_t *env, mino_val_t **out);Protected call: same as mino_call but returns 0 on success (writing the
result to *out) or -1 on error. The error message is available via
mino_last_error(). *out is set to NULL on error.
Modules
mino_resolve_fntypedef
typedef const char *(*mino_resolve_fn)(const char *name, void *ctx);Module resolver callback. Given a module name (the argument to require),
return a file path to load, or NULL on failure. ctx is the opaque
pointer passed to mino_set_resolver.
mino_set_resolver
void mino_set_resolver(mino_resolve_fn fn, void *ctx);Register a module resolver. When mino code calls (require "name"), the
resolver is invoked to map the name to a file path. The file is loaded
once; subsequent requires of the same name return the cached value.
Pass NULL to remove the resolver.
Execution limits
MINO_LIMIT_STEPSmacro
#define MINO_LIMIT_STEPS 1 /* max eval steps per mino_eval/mino_eval_string */max eval steps per mino_eval/mino_eval_string
MINO_LIMIT_HEAPmacro
#define MINO_LIMIT_HEAP 2 /* max bytes under GC management */max bytes under GC management
mino_set_limit
void mino_set_limit(int kind, size_t value);Set a global execution limit. Pass 0 to disable a limit. Step limits
are reset at the start of each mino_eval or mino_eval_string call.
When a limit is exceeded, the current eval returns NULL and
mino_last_error() reports the cause.
In-process REPL handle
MINO_REPL_OKmacro
#define MINO_REPL_OK 0 /* form evaluated; result written to *out */Return codes for mino_repl_feed.
MINO_REPL_MOREmacro
#define MINO_REPL_MORE 1 /* line accepted; more input needed */line accepted; more input needed
MINO_REPL_ERRORmacro
#define MINO_REPL_ERROR 2 /* parse or eval error; see mino_last_error() */parse or eval error; see mino_last_error()
mino_repl_ttypedef
typedef struct mino_repl mino_repl_t;mino_repl_new
mino_repl_t *mino_repl_new(mino_env_t *env);Create a REPL handle that evaluates forms in env. The handle owns
an internal line buffer; the host drives it by feeding one line at a
time via mino_repl_feed. No thread is required: the host controls
the call cadence entirely.
env must outlive the REPL handle.
mino_repl_feed
int mino_repl_feed(mino_repl_t *repl, const char *line, mino_val_t **out);Feed one line of input to the REPL. Returns:
MINO_REPL_OK — a complete form was read and evaluated. The result
is written to *out (when out is non-NULL).
MINO_REPL_MORE — the line was accumulated; more input is needed to
complete the current form.
MINO_REPL_ERROR — a parse or eval error occurred. The error message
is available via mino_last_error(). The buffer is
reset so the next feed starts a fresh form.
Multiple complete forms on one line: only the first is evaluated per call. Feed an empty line (or call again with "") to drain remaining buffered forms.
mino_repl_free
void mino_repl_free(mino_repl_t *repl);Free the REPL handle and its internal buffer. Does not free env.