What an EDAG evaluates to, and every operation on it. A value is data or a function: data is a primitive, or an array or object node whose items are values; a function keeps its evaluated captures and its body as an unevaluated EDAG expression. module.f.mjs holds the shape schemas, types.ts the EdagValue type, and the directories below hold the operations both interpreters, memo and amnesia, share.
The contracts these modules keep (identity, failure, runtime compilation) are written once in ../values.md, and the root README.md walks through the larger ones.
- Identity is kept. An array, object or function value is a node, and two values are the same value only when they are the same node. A constructor makes a fresh node; every other operation passes nodes through.
- Failure is a value. An operation answers
Result<EdagValue, EdagValue>. Its own failure, such as calling a non-function, iserror(['undefined']); a failure it receives from an operand or a callback passes through unchanged. - Undefined is tagged.
undefinedis the value['undefined'], so an absent value and a missing one are never confused with JavaScript's ownundefined.
| Module | Holds |
|---|---|
| Constructing | |
array | arrays from deferred items and spreads, and joining them as strings |
object | objects from deferred properties and spreads, keys in enumeration order |
function | functions from deferred captures and a body |
| Reading | |
property | property lookup: object fields, array items and length, string code units |
at | at on arrays and strings, counting negative indices from the end |
slice | slice on arrays and strings |
entries | Object.entries, the one static no body can define |
| Operating | |
semantics | truthiness, typeof, and strict equality by node identity |
numeric | unary +, -, ~ and Number(x) |
relational | <, <=, >, >= |
coercion, convert | objects to primitives, primitives to strings and numbers |
control | throw, ?: and sequencing, demanding only the operands they select |
| Calling | |
call | calls of represented functions, arguments resolved left to right |
method | built-in method calls, resolved through the runtime the executor was given |
array_method | map, filter, sort and the other pure array methods |
| Checking and leaving | |
metadata | unique, ordered object keys in data supplied from outside |
closure | closure bindings, body scopes and function lengths in supplied data |
to_unknown | toData: values as ordinary JavaScript values, sharing kept; toUnknown compiles functions |
The checks in metadata and closure are for EDAG that arrives as data, at an explicit boundary. A VM that builds values with the constructors above keeps the invariants by construction and does not check every result again.