Eval.Prims
Functions for creating new primitives.
You can define your own TINT primitives with Prims.make
and add them to the default primitives in prims
with Prims.prims
.
val prims :
Types.prim Types.M.t ->
(Types.M.key * Types.prim) list ->
Types.prims
(prims prims alist)
returns a new Types.prims
consisting of prims
with the new primitives in alist
added.
Each element of alist
is a pair (name,impl)
(such as the pair returned by make
) where name
is the name of the primitive, and impl
is the function implementing it.
val make :
?defaults:string Stdlib.List.t ->
string ->
(Types.state -> string list -> string) ->
string * Types.prim
(make ?defaults name f)
returns a TINT primitive named name
whose implementation is f
.
defaults
is a list of default values for name
's parameters. If name
takes n parms but is called with m <
n, the values for the missing parms are taken from defaults
starting at position m. name
returns an error if called with fewer parms than defaults
provides for.
An OCaml TINT primitive is just a function that takes a Types.state
and a list of string parameters, and returns a string. An error is indicated by raising Prim
; any other exception is a fatal error that terminates the TINT evaluator.