EDAG values

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.

Three rules every module here keeps

  • 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, is error(['undefined']); a failure it receives from an operand or a callback passes through unchanged.
  • Undefined is tagged. undefined is the value ['undefined'], so an absent value and a missing one are never confused with JavaScript's own undefined.

The modules

ModuleHolds
Constructing
arrayarrays from deferred items and spreads, and joining them as strings
objectobjects from deferred properties and spreads, keys in enumeration order
functionfunctions from deferred captures and a body
Reading
propertyproperty lookup: object fields, array items and length, string code units
atat on arrays and strings, counting negative indices from the end
sliceslice on arrays and strings
entriesObject.entries, the one static no body can define
Operating
semanticstruthiness, typeof, and strict equality by node identity
numericunary +, -, ~ and Number(x)
relational<, <=, >, >=
coercion, convertobjects to primitives, primitives to strings and numbers
controlthrow, ?: and sequencing, demanding only the operands they select
Calling
callcalls of represented functions, arguments resolved left to right
methodbuilt-in method calls, resolved through the runtime the executor was given
array_methodmap, filter, sort and the other pure array methods
Checking and leaving
metadataunique, ordered object keys in data supplied from outside
closureclosure bindings, body scopes and function lengths in supplied data
to_unknowntoData: 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.

Emergent Testing

Idle. Press Run to start the suite.

  • ./array/proof.f.mjs
  • ./array_method/proof.f.mjs
  • ./at/proof.f.mjs
  • ./call/proof.f.mjs
  • ./closure/proof.f.mjs
  • ./coercion/proof.f.mjs
  • ./control/proof.f.mjs
  • ./convert/proof.f.mjs
  • ./entries/proof.f.mjs
  • ./function/proof.f.mjs
  • ./metadata/proof.f.mjs
  • ./method/proof.f.mjs
  • ./numeric/proof.f.mjs
  • ./object/proof.f.mjs
  • ./proof.f.mjs
  • ./property/proof.f.mjs
  • ./relational/proof.f.mjs
  • ./semantics/proof.f.mjs
  • ./slice/proof.f.mjs
  • ./to_unknown/proof.f.mjs