Module Lisp.Make

Make(Machine) creates a Lisp machine embedded into the Primus Machine.

Parameters

Signature

link_program p links the program p into the Lisp Machine. Previous program, if any, is discarded.

val program : program Machine.t

program is the current Machine program.

val types : Type.env Machine.t

types returns Primus Lisp typing environment.

val define : ?types:Type.signature -> ?docs:string -> ?package:string -> string -> closure -> unit Machine.t

define ?docs name code defines a lisp primitive with the given name and an optional documentation string doscs.

Example:

open Bap_primus.Std

type Primus.exn += Bad_abs_call

module Abs(Machine : Primus.Machine.S) = struct
  let run = function
    | [x] -> Value.abs x
    | _ -> Machine.raise Bad_abs_call
end

...

module Library(Machine : Primus.Machine.S) = struct
  module Lisp = Primus.Lisp.Make(Machine)
  let init () = Machine.sequence [
      Lisp.define "abs" (module Abs);
      ...;
    ]
end
val signal : ?params:[< Type.parameters ] -> ?doc:string -> 'a observation -> ('a -> value list Machine.t) -> unit Machine.t

signal ?params ?docs obs proj defines a new signal.

Primus Observations are reflected onto Primus Lisp signals. Each reflection is defined via the signal operator that establishes a mapping between an observation and a signal.

After the signal is defined, every time the observation obs is made, the signal (signal args) will be sent, where signal = Observation.name obs and args is a mapping from the observation value to a list of values.

The signal will match with the observation name. Though the same observation may produce signals with different arities.

  • parameter params

    optional type specification

  • parameter doc

    optional documentation string

val failf : ('a, unit, string, unit -> 'b Machine.t) Core_kernel.format4 -> 'a

failf msg a1 ... am () terminates a lisp machine, and correspondingly the Primus machine with the Runtime_error.

val eval_fun : string -> value list -> value Machine.t

eval_fun name args calls a lisp function with the given name, that is the most specific to the current context and is applicable to the specified list of arguments.

  • since 1.5
val eval_method : string -> value list -> unit Machine.t

eval_method name args invokes all methods with the given name that are applicable in the current context to the specified list of arguments.

  • since 1.5

link_primitives prims provides the primitives prims

  • deprecated [since 2018-03] use link_primitive instead