220 "srn_kleene_node_t's union should be word sized"
Error handling for the runtime.
size_t srn_kleene_print(const srn_kleene_module_t *module, char *buf, size_t cap)
Write module back out as Kleene text into the buffer buf of size cap.
@ SRN_KL_GLOBAL
top level name reference
@ SRN_KL_CTOR
constructor: integer tag + atom fields
@ SRN_KL_LIT
literal (int, string, char)
@ SRN_KL_VAR
local variable reference
@ SRN_KL_PRIM
primitive op on atoms
@ SRN_KL_FN
closure: params, body
@ SRN_KL_LABEL
define a label that can jump to
@ SRN_KL_APP
function application
@ SRN_KL_JUMP
jump to a label with atom args
@ SRN_KL_CASE
branch on a scrutinee's constructor tag
@ SRN_KL_LET
bind one expression, then continue
@ SRN_KL_PAPP
partial application
srn_error_t * srn_kleene_read(srn_context_t *ctx, const char *src, srn_kleene_module_t *out)
Parse the Kleene source in src (of length len) into *out.
struct srn_value_t srn_value_t
struct srn_metadata_t srn_metadata_t
A runtime error, a tag classifying the failure and a human-readable message.
SRN_KL_APP and SRN_KL_PAPP: fn applied to args.
srn_kleene_node_t ** args
size_t binder_count
Number of fields the constructor carries.
srn_kleene_node_t * body
The body of the case.
int32_t tag
Constructor tag this arm matches.
const char ** binders
Names bound to the constructor's fields, in order.
SRN_KL_CASE: match scrutinee against arms.
srn_kleene_arm_t * arms
The arms, one per matched constructor tag.
srn_kleene_node_t * scrutinee
The atom being matched.
size_t arm_count
Number of arms.
SRN_KL_CTOR: build a value with constructor tag from atom fields.
srn_kleene_node_t ** fields
Atom fields.
int32_t tag
Constructor tag, relative to the value's type.
size_t field_count
Number of fields.
A single top-level definition, (def name body).
const char * name
the global this definition binds
srn_kleene_node_t * body
the definition's value, often an FN
const char ** params
Parameter names, in order.
SRN_KL_GLOBAL: a reference to a top-level definition by name.
SRN_KL_JUMP: hand args to the label named label.
size_t arg_count
Number of arguments.
const char * label
Name of the target label.
srn_kleene_node_t ** args
Atom arguments handed to the label's parameters.
SRN_KL_LABEL: a label name taking params, whose body runs when jumped to, in scope of cont.
srn_kleene_node_t * cont
The continuation in scope of the label.
const char * name
The label's name, referenced by a matching jump.
size_t param_count
Number of parameters.
const char ** params
Parameter names the jump supplies.
srn_kleene_node_t * body
The code run when the label is jumped to.
SRN_KL_LET: evaluate rhs, bind it to name, then evaluate body.
srn_kleene_node_t * body
The continuation, evaluated with name in scope.
const char * name
Name the result of rhs is bound to.
srn_kleene_node_t * rhs
The expression to evaluate and bind.
SRN_KL_VAR: a reference to a bound local by name.
A parsed Kleene module, the unit the reader returns and the builder consumes.
srn_kleene_def_t * defs
top-level definitions in source order
size_t def_count
number of definitions
A node of the Kleene tree. tag selects the active union member.
srn_kleene_case_t * scase
SRN_KL_CASE.
srn_kleene_local_t * var
SRN_KL_VAR.
srn_value_t * lit
SRN_KL_LIT: a literal the reader has already boxed.
union srn_kleene_node_t::@021011016321007233225152122132222022262256275064 as
Every member is one word, a pointer or an immediate, so the union stays word sized.
srn_kleene_label_t * label
SRN_KL_LABEL.
srn_kleene_prim_t * prim
SRN_KL_PRIM.
srn_metadata_t * metadata
Source metadata for diagnostics, may be NULL.
srn_kleene_fn_t * fn
SRN_KL_FN.
srn_kleene_ctor_t * ctor
SRN_KL_CTOR.
srn_kleene_jump_t * jump
SRN_KL_JUMP.
srn_kleene_app_t * app
SRN_KL_APP and SRN_KL_PAPP.
srn_kleene_let_t * let
SRN_KL_LET.
srn_kleene_global_t * global
SRN_KL_GLOBAL.
srn_kleene_node_tag_t tag
Which variant as holds.
SRN_KL_PRIM: primitive op over atom args.
const char * op
Name of the primitive operation.
srn_kleene_node_t ** args
Main memory manager structure that will own all the allocated blocks and data.