@r47onfire/backolon - v0.0.0
    Preparing search index...

    Class NativeModule

    Native module container for Backolon builtins, syntax, and operators.

    Index

    Constructors

    Properties

    env: Thing<env>
    funcs: Record<string, NativeFunctionDetails> = {}
    ops: Record<string, Partial<Record<number, OperatorOverload[]>>> = {}
    applicators: Partial<Record<ThingType | string, CustomApplicator>> = {}
    name: string

    Methods

    • Defines a variable in the module's environment.

      Parameters

      Returns void

    • Defines a native function in the module.

      If the function needs to call into Backolon code, it can do so by updating the current cookie on the task to remember where it is in execution and then calling task.enter(code, loc, env) with the appropriate code, location, and environment.

      The function should "return" its result by calling task.out(result). If the Javascript function does not call task.out() and just returns, the scheduler will call the implementation again until it does, so it's important to call task.out() at some point to avoid infinite loops.

      Parameters

      • name: string
      • signature: string

        The string describing the function signature, the same way as in lambda headers in Backolon code. For example, "_:map" for a function taking a single map argument, or "x y" for a function taking two arguments of any type.

      • body: (task: Task, state: StackEntry) => void
      • defvar: boolean = true

        Whether to also define a variable with the function's name pointing to the function itself (thus making the function accessible from Backolon code).

      Returns void

    • Defines a new pattern syntax. The handler can be either a native function implementation, or a Backolon function defined in the same module (in either case the handler will be called with the pattern variables as a single map argument).

      Parameters

      • pattern: string

        The pattern string, in the same format as in Backolon patterns. For example, "x:roundblock" for a pattern matching a single round block and binding it to x, or "x:number y:string" for a pattern matching a number followed by a string and binding them to x and y respectively.

      • precedence: number
      • right: boolean

        Whether the pattern is right-associative (only matters for patterns that can be chained, like infix operators).

      • when: ThingType[] | null

        Which block types may contain this pattern. null is equivalent to [ThingType.roundblock, ThingType.topblock].

      • handler: string

        The name of the native function implementing the pattern rewriter.

      • OptionalhandlerBody: (task: Task, state: StackEntry) => void

        If present, the native function implementation of the pattern rewriter. If not present, the handler is expected to be defined elsewhere (e.g. by a call to defun in the same module) and this function will just reference it by name.

      Returns void

    • Defines a new operator overload native function, mapping to the given operator name.

      Parameters

      • builtin: string

        The name to give the builtin function implementing the operator overload (e.g. "__add" for overloading the "add" operator).

      • name: string

        The operator name to overload (e.g. "add").

      Returns void

    • Defines a new operator overload for the given operator name and argument types. The handler will be called with the operator arguments as an array, and should return the result of the operator application.

      Type Parameters

      • const T extends (string | ThingType | null)[]

      Parameters

      • name: string
      • types: T

        List of argument types for this overload, where each type can be a ThingType, a string representing a type class, or null for any type. The length of this list determines the arity of the operator overload.

      • cb: (opTrace: LocationTrace, argv: MapValues<T>) => Thing

      Returns void

    • Defines a custom applicator for a given type of functor. The applicator will be called with the functor, arguments, and callsite information whenever an apply form with a functor of the given type is evaluated in Backolon code.

      Parameters

      Returns void