The interface to add arbitrary classes is the routine Tools.registerClass:
val registerClass : class * rule -> unit
Here, type class is simply synonymous to string; a class string is the name of the class to be registered. It must not contain upper-case letters:
type class = string
Type rule is a function type. It describes the rule function that CM will invoke for every member of the new class. The rule function is responsible for invoking the auxiliary mechanism necessary to bring its targets up-to-date. The function result of the rule function describes to CM what the targets are. Thus, the function maps the specification of the given member to its (partial) expansion:
type rule =
{ spec: spec,
native2pathmaker: string -> pathmaker,
context: rulecontext,
defaultClassOf: fnspec -> class option } ->
partial_expansion
The specification spec consists of the name of the member together with a function to produce its corresponding abstract path (should that be necessary), the member's optional class (in case it had been given explicitly), its tool options, and a boolean flag that tells whether this member was the result of another tool:
type spec = { name: string,
mkpath: pathmaker,
class: class option,
opts: toolopts option,
derived: bool }
type pathmaker = unit -> presrcpath
type fnspec = { name: string, mkpath: pathmaker }
datatype toolopt =
STRING of fnspec
| SUBOPTS of { name: string, opts: toolopts }
withtype toolopts = toolopt list
The nesting of SUBOPTS reflects the nesting of sub-option lists
in the member's tool option specification.
Again, names which are potentially to be interpreted as file names are
represented by their original specification string and a function
mkpath to get the corresponding abstract path, thereby taking
care of interpreting the name according to its respective syntactic
rules and its context. (Type fnspec is a slimmed-down version of
type spec. It also appears as the argument type of function
defaultClassOf. See below.)The other three arguments of a rule function are native2pathmaker, context, and defaultClassOf:
type rulefn = unit -> partial_expansion type rulecontext = rulefn -> partial_expansion
A (full) expansion consists of three lists: a list of ML files, a list of CM files, and a list of sources. A partial expansion is a full expansion together with a list of specifications that still need to be expanded further.
type expansion =
{ smlfiles: (srcpath * Sharing.request * setup) list,
cmfiles: (srcpath * Version.t option * rebindings) list,
sources: (srcpath * { class: class, derived: bool}) list }
type partial_expansion = expansion * spec list
A rule always returns a partial expansion. CM will derive a full expansion by repeatedly applying rules until the list of pending specification becomes empty.
Most rules (except those for classes sml and cm) leave the lists smlfiles and cmfiles empty. A tool that produces an ML source file or a CM description file as output should put a specification for this file into the specification list of a partial expansion, letting the rules for classes sml and cm take care of the rest. At this point we will therefore not dwell on explanations for the types of these two fields.
The sources field is used to implement CM.sources (see section 4.1.11). Therefore, the rule should include here every file that it consumes if its implementer wishes to have it reported by CM.sources. (Do not include source files that are produced by the rule because those will be reported by subsequent rules.)