OBJ visitor for object literals. If state.word
is true, pushes call to resolveObject on temp word stack, else calls resolveObject and pushes result on stack.
HOF word function used by visitWord to create local variables. Pops TOS and adds it as value for a new scope in stack of bindings for given var.
-
HOF word function used by visitWord to end local variables. Removes scope from given var's stack of bindings. Throws error if for some reason the scope stack has become corrupted (i.e. no more scopes left to remove).
-
Prepares a the given environment object and if needed injects/updates these keys:
__words
: dictionary of user defined and FFI words__vars
: individual stacks for each defined var nameThe user pre-defines variables at the root level of the env object, e.g. {a: 1}
. For each defined var a stack is built inside the __vars
sub-object, which only exists during runtime and will be removed before returning the env back to the user (handled by finalizeEnv). The name stacks are used to implement dynamic scoping of all variables.
// foo uses local var `a` with same name as global
// foo also writes to `b` (a new global)
// b=12 because foo's local `a` takes precedence over global `a`
// during `foo` execution the stack for var `a` is:
// {... __vars: {a: [2, 1]}}
run(`: foo ^{ a } @a 10 + b!; 2 foo`, {a: 1});
// [ [], [], { a: 1, b: 12, __words: { foo: [Function] } } ]
-
Takes an environment object and injects given custom word definitions. words
is an object with keys representing word names and their values {@link @thi.ng/pointfree#StackFn}s. See {@link @thi.ng/pointfree# | @thi.ng/pointfree} package for more details about stack functions.
-
-
Copies current scope values for all vars back into main env object and removes env.__vars
. Called from all run*()
functions.
-
HOF word function. Calls resolveVar and pushes result on stack.
-
Constructs an array literal (quotation) from given AST node.
-
-
Resolves given node's value. Used by resolveArray & resolveObject to process internal values (and in the latter case also their keys).
-
-
Constructs object literal from given AST node.
-
-
Looks up given variable in current env.__vars
object and returns its value. Throws error if var can't be resolved, either because it's undefined or there's scoping error. Each var uses its own (reverse) stack of scopes (prepared in ensureEnv
), and the current scope's value is always at the TOS element (scopes[0]
).
-
Main user function. Takes a string w/ DSL source code and optional env and stack. Prepares env using ensureEnv
, parses, compiles and executes source, then returns resulting {@link @thi.ng/pointfree#StackContext} tuple.
-
-
-
Like run, but returns resulting env object only.
-
-
-
Like run, but returns unwrapped value(s) from result data stack.
-
-
-
-
Executes word with given name, defined in supplied env
object and with given optional initial stack. Returns resulting {@link @thi.ng/pointfree#StackContext} tuple.
-
-
-
Like runWord, but returns resulting env object only.
-
-
-
Like runWord, but returns unwrapped value(s) from result data stack.
-
-
-
-
HOF word function. Pops TOS and stores value in current scope of var's stack of bindings, i.e. scopes[0] = val
. Creates new scope stack for hitherto unknown vars.
-
Main AST node visitor dispatcher.
-
-
-
VAR_DEREF visitor. If state.word
is true, pushes loadvar(id)
on (temp) stack (created by visitWord), else attempts to resolve var and pushes its value on stack. Throws error if unknown var.
-
-
-
-
-
-
SYM visitor. Looks up symbol (word name) and if state.word
is true, pushes word on (temp) stack (created by visitWord), else executes word. Throws error if unknown word.
-
-
-
WORD visitor to create new word definition. Sets state.word
to true, builds temp stack context and calls visit for all child nodes. Then calls word to compile function and stores it in env.__words
object.
root: {a: 1, b: 2} word1: {a: 2, b: 2} (a is local, b from root) word2: {c: 3, a: 2, b: 2} (c is local, called from w1, a from w1, b: from root)
-
-
-
Generated using TypeDoc
ARRAY visitor for arrays/quotations. If
state.word
is true, pushes call to resolveArray on temp word stack, else calls resolveArray and pushes result on stack.-
-
-