package bap-knowledge

  1. Overview
  2. Docs

Context variables.

Context variables could be used to implement stateful analyses. They are not part of the knowledge base per se, but enable convience that is otherwise achieavable through adding a state to the knowledge monad using a monad transformer.

It is important to keep in mind that the contex variables are not a part of the knowledge and that every knowledge computation starts with a fresh set of variables, i.e., variables are not persistent.

The data type of the context variable is not required to have the domain structure or be comparable. The only requirement is that when a variable is declared it should be initialized.

  • since 2.4.0
type 'a var

an abstract type denoting a context variable and its name.

val declare : ?inspect:('a -> Core_kernel.Sexp.t) -> ?package:string -> string -> 'a knowledge -> 'a var

declare ~package name init declares a new context variable.

The declared variable has the initial value init. The inspect function could be used for debugging and instrospection.

val set : 'a var -> 'a -> unit knowledge

set v x assings to the variable v a new value x.

val get : 'a var -> 'a knowledge

get v is the current value assigned to v.

val update : 'a var -> ('a -> 'a) -> unit knowledge

update v f applies f to the current value of v and assigns the result back.

val with_var : 'a var -> 'a -> (unit -> 'b knowledge) -> 'b knowledge

with_var v x f dynamically binds v to x while f is run.

OCaml

Innovation. Community. Security.