Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "index"

Index

References

ensureStack

Re-exports ensureStack

ensureStackN

Re-exports ensureStackN

unwrap

Re-exports unwrap

Variables

Let LOGGER

LOGGER: ILogger = NULL_LOGGER

Const visitArray

visitArray: (Anonymous function) = visitWithResolver(resolveArray)

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.

param

-

param

-

param

-

Const visitObject

visitObject: (Anonymous function) = visitWithResolver(resolveObject)

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.

param

-

param

-

param

-

Functions

Const beginvar

  • beginvar(id: string): (Anonymous function)
  • 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.

    Parameters

    • id: string

      -

    Returns (Anonymous function)

Const endvar

  • endvar(id: string): (Anonymous function)
  • 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).

    Parameters

    • id: string

      -

    Returns (Anonymous function)

Const ensureEnv

  • ensureEnv(env?: pf.StackEnv): any
  • 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 name

    The 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] } } ]

    Also see: loadvar, storevar, beginvar, endvar

    Parameters

    • Optional env: pf.StackEnv

      -

    Returns any

Const ffi

  • ffi(env: any, words: IObjectOf<pf.StackFn>): any
  • 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.

    Parameters

    • env: any

      -

    • words: IObjectOf<pf.StackFn>

      -

    Returns any

Const finalizeEnv

  • finalizeEnv(ctx: StackContext): StackContext
  • Copies current scope values for all vars back into main env object and removes env.__vars. Called from all run*() functions.

    Parameters

    • ctx: StackContext

      -

    Returns StackContext

Const loadvar

  • loadvar(node: ASTNode): (Anonymous function)

Const nodeLoc

Const resolveArray

  • resolveArray(node: ASTNode, ctx: StackContext): any[]

Const resolveNode

  • resolveNode(node: ASTNode, ctx: StackContext): any

Const resolveObject

  • resolveObject(node: ASTNode, ctx: StackContext): any

Const resolveSym

  • resolveSym(node: ASTNode, ctx: StackContext): any
  • Looks up given symbol (word name) in this order of priority:

    • current env.__words
    • ALIASES
    • @thi.ng/pointfree built-ins

    Throws error if symbol can't be resolved.

    Parameters

    Returns any

Const resolveVar

  • resolveVar(node: ASTNode, ctx: StackContext): any
  • 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]).

    Parameters

    Returns any

Const run

  • run(src: string, env?: pf.StackEnv, stack?: pf.Stack): StackContext
  • 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.

    Parameters

    • src: string

      -

    • Optional env: pf.StackEnv

      -

    • Default value stack: pf.Stack = []

      -

    Returns StackContext

Const runE

  • runE(src: string, env?: pf.StackEnv, stack?: pf.Stack): any
  • Like run, but returns resulting env object only.

    Parameters

    • src: string

      -

    • Optional env: pf.StackEnv

      -

    • Optional stack: pf.Stack

      -

    Returns any

Const runU

  • runU(src: string, env?: pf.StackEnv, stack?: pf.Stack, n?: number): any
  • Like run, but returns unwrapped value(s) from result data stack.

    Parameters

    • src: string

      -

    • Optional env: pf.StackEnv

      -

    • Optional stack: pf.Stack

      -

    • Default value n: number = 1

      -

    Returns any

Const runWord

  • runWord(id: string, env: pf.StackEnv, stack?: pf.Stack): StackContext
  • Executes word with given name, defined in supplied env object and with given optional initial stack. Returns resulting {@link @thi.ng/pointfree#StackContext} tuple.

    Parameters

    • id: string

      -

    • env: pf.StackEnv

      -

    • Default value stack: pf.Stack = []

      -

    Returns StackContext

Const runWordE

  • runWordE(id: string, env: pf.StackEnv, stack?: pf.Stack): any

Const runWordU

  • runWordU(id: string, env: pf.StackEnv, stack?: pf.Stack, n?: number): any
  • Like runWord, but returns unwrapped value(s) from result data stack.

    Parameters

    • id: string

      -

    • env: pf.StackEnv

      -

    • Default value stack: pf.Stack = []

      -

    • Default value n: number = 1

      -

    Returns any

Const setLogger

  • setLogger(logger: ILogger): ILogger

Const storevar

  • storevar(id: string): (Anonymous function)
  • 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.

    Parameters

    • id: string

      -

    Returns (Anonymous function)

Const visit

Const visitDeref

  • 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.

    Parameters

    Returns StackContext

Const visitStackComment

Const visitStore

Const visitSym

Const visitWithResolver

  • visitWithResolver(resolve: Fn2<ASTNode, StackContext, any>): (Anonymous function)

Const visitWord

  • 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)

    Parameters

    Returns StackContext

Generated using TypeDoc