|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
In admiration of Stephen Cole Kleene. More...
Go to the source code of this file.
Data Structures | |
| struct | srn_kleene_arm_t |
| One arm of a case. More... | |
| struct | srn_kleene_local_t |
| SRN_KL_VAR: a reference to a bound local by name. More... | |
| struct | srn_kleene_global_t |
| SRN_KL_GLOBAL: a reference to a top-level definition by name. More... | |
| struct | srn_kleene_fn_t |
| SRN_KL_FN: a closure. More... | |
| struct | srn_kleene_app_t |
| SRN_KL_APP and SRN_KL_PAPP: fn applied to args. More... | |
| struct | srn_kleene_prim_t |
| SRN_KL_PRIM: primitive op over atom args. More... | |
| struct | srn_kleene_ctor_t |
| SRN_KL_CTOR: build a value with constructor tag from atom fields. More... | |
| struct | srn_kleene_let_t |
| SRN_KL_LET: evaluate rhs, bind it to name, then evaluate body. More... | |
| struct | srn_kleene_case_t |
| SRN_KL_CASE: match scrutinee against arms. More... | |
| struct | srn_kleene_label_t |
| SRN_KL_LABEL: a label name taking params, whose body runs when jumped to, in scope of cont. More... | |
| struct | srn_kleene_jump_t |
| SRN_KL_JUMP: hand args to the label named label. More... | |
| struct | srn_kleene_node_t |
| A node of the Kleene tree. tag selects the active union member. More... | |
| struct | srn_kleene_def_t |
| A single top-level definition, (def name body). More... | |
| struct | srn_kleene_module_t |
| A parsed Kleene module, the unit the reader returns and the builder consumes. More... | |
Typedefs | |
| typedef struct srn_mm_t | srn_mm_t |
| typedef struct srn_context_t | srn_context_t |
| typedef struct srn_value_t | srn_value_t |
| typedef struct srn_metadata_t | srn_metadata_t |
| typedef struct srn_sexp_tree_t | srn_sexp_tree_t |
| typedef enum srn_kleene_node_tag_t | srn_kleene_node_tag_t |
| typedef struct srn_kleene_node_t | srn_kleene_node_t |
| typedef struct srn_kleene_arm_t | srn_kleene_arm_t |
| One arm of a case. | |
| typedef struct srn_kleene_local_t | srn_kleene_local_t |
| SRN_KL_VAR: a reference to a bound local by name. | |
| typedef struct srn_kleene_global_t | srn_kleene_global_t |
| SRN_KL_GLOBAL: a reference to a top-level definition by name. | |
| typedef struct srn_kleene_fn_t | srn_kleene_fn_t |
| SRN_KL_FN: a closure. | |
| typedef struct srn_kleene_app_t | srn_kleene_app_t |
| SRN_KL_APP and SRN_KL_PAPP: fn applied to args. | |
| typedef struct srn_kleene_prim_t | srn_kleene_prim_t |
| SRN_KL_PRIM: primitive op over atom args. | |
| typedef struct srn_kleene_ctor_t | srn_kleene_ctor_t |
| SRN_KL_CTOR: build a value with constructor tag from atom fields. | |
| typedef struct srn_kleene_let_t | srn_kleene_let_t |
| SRN_KL_LET: evaluate rhs, bind it to name, then evaluate body. | |
| typedef struct srn_kleene_case_t | srn_kleene_case_t |
| SRN_KL_CASE: match scrutinee against arms. | |
| typedef struct srn_kleene_label_t | srn_kleene_label_t |
| SRN_KL_LABEL: a label name taking params, whose body runs when jumped to, in scope of cont. | |
| typedef struct srn_kleene_jump_t | srn_kleene_jump_t |
| SRN_KL_JUMP: hand args to the label named label. | |
Enumerations | |
| enum | srn_kleene_node_tag_t : size_t { SRN_KL_VAR , SRN_KL_LIT , SRN_KL_GLOBAL , SRN_KL_FN , SRN_KL_APP , SRN_KL_PAPP , SRN_KL_PRIM , SRN_KL_CTOR , SRN_KL_LET , SRN_KL_CASE , SRN_KL_LABEL , SRN_KL_JUMP } |
Functions | |
| 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. | |
| 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. | |
In admiration of Stephen Cole Kleene.
The first layer of IR of the compiler. Any source level language should elaborate to this IR.
The tree is deliberately small and already in A-normal form. Every operand is an atom, a variable, a literal, or a global reference, and anything compound is named by an enclosing let. The reader checks that shape and rejects input that breaks it. Nodes carry no source level types.
Definition in file kleene.h.
| typedef struct srn_kleene_app_t srn_kleene_app_t |
SRN_KL_APP and SRN_KL_PAPP: fn applied to args.
Each arg is an atom node (VAR, LIT, or GLOBAL).
| typedef struct srn_kleene_arm_t srn_kleene_arm_t |
One arm of a case.
Matches a constructor tag and binds that constructor's fields to fresh locals before running the body.
| typedef struct srn_kleene_case_t srn_kleene_case_t |
SRN_KL_CASE: match scrutinee against arms.
The reader guarantees the tags are distinct.
| typedef struct srn_kleene_ctor_t srn_kleene_ctor_t |
SRN_KL_CTOR: build a value with constructor tag from atom fields.
| typedef struct srn_kleene_fn_t srn_kleene_fn_t |
SRN_KL_FN: a closure.
Free variables are captured implicitly by the lowering, the source lists only the parameters.
| typedef struct srn_kleene_global_t srn_kleene_global_t |
SRN_KL_GLOBAL: a reference to a top-level definition by name.
| typedef struct srn_kleene_jump_t srn_kleene_jump_t |
SRN_KL_JUMP: hand args to the label named label.
| typedef struct srn_kleene_label_t srn_kleene_label_t |
SRN_KL_LABEL: a label name taking params, whose body runs when jumped to, in scope of cont.
| typedef struct srn_kleene_let_t srn_kleene_let_t |
SRN_KL_LET: evaluate rhs, bind it to name, then evaluate body.
| typedef struct srn_kleene_local_t srn_kleene_local_t |
SRN_KL_VAR: a reference to a bound local by name.
| typedef enum srn_kleene_node_tag_t srn_kleene_node_tag_t |
| typedef struct srn_kleene_prim_t srn_kleene_prim_t |
SRN_KL_PRIM: primitive op over atom args.
| enum srn_kleene_node_tag_t : size_t |
Definition at line 48 of file kleene.h.
| 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.
Returns the number of bytes the full text needs, not counting a terminating NUL. When that exceeds cap the buffer holds a truncated result, call again with a large enough buffer. Reading then printing a module yields equivalent text, which makes the format usable as a golden-test artifact.
| 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.
Nodes are allocated from mm and remain valid for that arena's lifetime. On success returns NULL and writes the module to *out. On a syntax or shape error returns an error built on ctx, describing the offending offset, and leaves *out untouched.