alice
library
manual.

Alice Project

The COMPONENT_MANAGER signature


________ Synopsis ____________________________________________________

    signature COMPONENT_MANAGER
    structure ComponentManager : COMPONENT_MANAGER
    functor Component.MkManager (val resolver : Resolver.t) : COMPONENT_MANAGER
    functor Sandboox.MkManager (Policy : POLICY) : COMPONENT_MANAGER

A component manager is responsible for loading and linking components. To this aim, every component manager maintains its component table, which is a mapping from URLs to components. All loading, linking, evaluating, and signature matching is performed lazily. For this reason components are initially returned as lazy futures, which either get replaced by the component export (on success) or failed. See the description of exception Component.Failure to see how these "asynchronous" exceptions are handled.

URLs given to any of the functions below are first resolved with respect to the current working directory and stripped of their query and fragment constituents.

The structure ComponentManager is the root component manager. User-defined managers can be created through the Component.MkManager or the Sandbox.MkManager functors.

See also: Component, Sandbox, Url


________ Import ______________________________________________________

    import signature COMPONENT_MANAGER from "x-alice:/lib/system/COMPONENT_MANAGER-sig"
    import structure ComponentManager from "x-alice:/lib/system/ComponentManager"

________ Interface ___________________________________________________

    signature COMPONENT_MANAGER =
    sig
	exception Conflict

	val logger : (string -> unit) ref

	val load : Url.t -> Component.t
	val eval : Url.t * Component.t -> package
	val link : Url.t -> package
	val enter : Url.t * Component.t -> unit
	val lookup : Url.t -> Component.t option

	functor Eval (val component : Component.t
		     val url : Url.t
		     signature S) : S

	functor Link (val url : Url.t
		     signature S) : S

	functor Enter (val url: Url.t
		      signature S
		      structure X : S) : any
    end

________ Description _________________________________________________

exception Conflict

indicates an attempt to enter a component in the component table while some component was already registered under that name.

val logger

set to a function that receives logging information from the component manager. The default activity is ignore, but can be configured using the environment variable ALICE_TRACE_COMPONENT, see structure Component.

load url

localizes url and loads a first-class component from the file found, without evaluating or linking it. Raises Component.Failure with IO.Io as cause if resolving, loading or unpickling fails.

eval (url, com)

evaluates com, rooted at url, in the context of the component table managed by this component manager, and returns the computed module as a package. No entry for url is created in the component table, but entries may be created for components imported (directly or indirectly) by com. Relative import URLs in com are resolved using url as a base url, which should be absolute. Raises Component.Failure if evaluation of the component fails.

Note that, while most components may export a single structure, their export is not simply that structure, but a structure that contains that structure (cf. link).

link url

loads, evaluates and links the component from url. Returns a package representing the export of the component. If the component table has no entry for url yet, a new entry is created immediately.

Note that, while most library components export a single structure, their export is not simply that structure, but a structure that contains that structure. For instance, in order to link the TextIO component manually, the returned package has to be unpacked as follows:

	structure TextIOComp = unpack link(Url.fromString "x-alice:/lib/system/TextIO")
	                            : (structure TextIO : TEXT_IO)
	open TextIOComp

The open declaration will pull the actual TextIO structure into scope.

enter (url, com)

enters com into the component table, under name url. Raises Conflict if the component table already had an entry for url.

lookup url

returns SOME com, if the component table has an entry mapping url to com, or NONE otherwise.

Eval (val component = com val url = url signature S = S)

like the function eval, but matches the component's export against the signature S and returns the export module itself. Raises Component.Failure with Component.Mismatch as cause if the component does not match S.

Note that, while most components may export a single structure, their export is not simply that structure, but a structure that contains that structure (cf. Link).

Link (val url = url signature S = S)

like the function link, but matches the component's export against the signature S and returns the export module itself. Raises Component.Failure with Component.Mismatch as cause if the component does not match S.

Note that, while most library components export a single structure, their export is not simply that structure, but a structure that contains that structure. For instance, in order to link the TextIO component manually, the following call to Link is necessary:

	structure TextIOComp = Link (val url = Url.fromString "x-alice:/lib/system/TextIO"
	                             signature S = (structure TextIO : TEXT_IO))
	open TextIOComp

The open declaration will pull the actual TextIO structure into scope.

Enter (val url = url signature S = S structure X = X)

enters the moduleX of signature S as an evaluated component into the component table, under name url. Raises Conflict if the component table already had an entry for url. Equivalent to

	enter (url, Component.fromPackage (pack X : S))


last modified 2007/Mar/30 17:10