Previous: , Up: Web deployment   [Contents][Index]


3.2 JavaScript API reference

The Scheme class is used to load a Hoot binary, start the program, and initialize reflection.

Class: Scheme

A Scheme runtime environment.

Static method on Scheme: load_main path [abi] [reflect_wasm_dir "."] [user_imports {}]

Fetch and execute the Hoot Wasm binary at the URL path and return an array of Scheme values produced by the program.

The reflection library requires the assistance of some Wasm helper modules, which are looked up in reflect_wasm_dir.

The abi parameter is for more advanced usage where multiple Hoot binaries share a single application binary interface (ABI). This should be set to {} when loading the first Scheme binary. It is better to use the load_extension method for subsequent binaries, though.

The user_imports parameter is for providing concrete implementations of functions declared using the Foreign function interface. It uses a two-tier nested object structure to map import names to the functions that implement them.

For example, this Scheme code:

(define-foreign make-text-node
  "document" "createTextNode"
  (ref string) -> (ref null extern))

Could be instantiated like so:

Scheme.load_main("hello.wasm", {
  user_imports: {
    document: {
      createTextNode: Document.prototype.createTextNode.bind(document)
    }
  }
});
Method on Scheme: load_extension path [user_imports {}]

Fetch and load an additional Hoot binary at the URL path that shares the ABI of this. Optionally, a set of user-defined imported functions can be specified with the user_imports parameter.

All of the fundamental Scheme types have an associated JavaScript class that can reflect their values. Calling the repr function on an instance of a reflected Scheme object will return a Scheme-like printing of the object.

repr(pair) // => "(1 . 2)"
Class: Char

A Unicode character.

Class: Eof

End-of-file object.

Class: Null

The empty list.

Class: Unspecified

The unspecified value.

Class: Complex real imag

Complex number with real part real and imaginary part imag.

Class: Fraction num denom

An exact fraction with numerator num and denominator denom.

The HeapObject class is the parent class of all of the remaining Scheme types.

Class: HeapObject

A Scheme heap object.

Instance Variable of HeapObject: reflector

The reflector for this, an instance of the Scheme class.

The reflector property can be used in conjuction with the load_extension method to load additional Hoot binaries that share the same ABI.

heapObject.reflector.load_extension("/helper.wasm")
Class: Procedure

A Scheme procedure.

Procedure instances can be invoked with the call method to perform a Javascript to Scheme function call.

Method on Procedure: call args…

Call procedure with args and return an array of result values.

Method on Procedure: call_async args…

Call procedure with args in an async context and return a promise to an array of result values. Before the procedure is called, args is prepended with two additional arguments: a function that resolves the promise, and a function that rejects the promise. It is up to the underlying Scheme procedure to use these values appropriately to settle the promise.

Class: Pair

An immutable cons cell.

Class: MutablePair

A mutable cons cell.

Class: Vector

An immutable vector.

Class: MutableVector

A mutable vector.

Class: Bytevector

An immutable bytevector.

Class: MutableBytevector

A mutable bytevector.

Class: Bitvector

An immutable bitvector.

Class: MutableBitvector

A mutable bitvector.

Class: MutableString

A mutable string.

Class: Sym

A symbol.

Class: Keyword

A keyword.

Class: Variable

A mutable variable.

Class: AtomicBox

A mutable box with atomic updates.

Class: HashTable

A hash table.

Class: WeakTable

A weak key hash table.

Class: Fluid

A dynamic variable.

Class: DynamicState

A set of fluids.

Class: Syntax

A syntax object.

Class: Port

An I/O port.

Class: Struct

A user-defined structure.


Previous: Web server setup, Up: Web deployment   [Contents][Index]