266
266
267
267
{[
268
268
let () =
269
- Theory.declare "my-constant-tracker"
270
- Theory.instance ~require:["bap.std:constant-tracker"] >>=
269
+ Theory.declare "my-constant-tracker" @@
270
+ Theory.instance ~require:["bap.std:constant-tracker"] >>=
271
271
Theory.require >>|
272
272
fun (module Base) : Theory.core -> (module struct
273
273
include Base
@@ -3030,29 +3030,39 @@ module Theory : sig
3030
3030
(module Core ) knowledge ->
3031
3031
unit
3032
3032
3033
- (* * [instance ()] creates an instance of the Core Theory.
3033
+ (* * [instance ()] returns the current or creates a new instance of
3034
+ the core theory.
3034
3035
3035
- The instance is built from all theories that match the context
3036
- specified by the [features] list and provide features specified
3037
- by the [requires] list. If any theory is subsumed by other
3038
- theory, then it is excluded.
3036
+ If no parameters of the [instance] function were specialized
3037
+ and there is an instance of the current theory then this
3038
+ instance is returned.
3039
3039
3040
- If no instances satisfy this requirement than the empty theory
3040
+ Otherwise, the instance is built from all theories that match
3041
+ the context specified by the [context] list and provide features
3042
+ specified by the [requires] list. If any theory is subsumed by
3043
+ other theory, then it is excluded.
3044
+
3045
+ If no instances satisfy this requirement then the empty theory
3041
3046
is returned. If only one theory satisfies the requirement, then
3042
3047
it is returned. If many theories match, then a join of all
3043
3048
theories is computed, stored in the knowledge base, and the
3044
3049
resulting theory is returned.
3045
3050
3046
- To manifest a theory into an structure, use the [require] function.
3051
+ To manifest a theory into an structure, use the [require]
3052
+ function. The [current] function is equivalent to the
3053
+ composition [instance >=> require], use this function, if you
3054
+ want to use the current theory.
3047
3055
3048
- @param features is a set of features that define the context,
3056
+ @param context is a set of features that define the context,
3049
3057
only those theories that have a context that is a subset of
3050
3058
provided will be instantiated.
3051
3059
3052
3060
@param requires is a set of semantic features that are
3053
3061
required. Defaults to the set of all possible features, i.e., if
3054
3062
unspecified, then all instances applicable to the context will
3055
3063
be loaded.
3064
+
3065
+ @since 2.4.0 respects the currently set theory.
3056
3066
*)
3057
3067
val instance :
3058
3068
?context : string list ->
@@ -3062,15 +3072,19 @@ module Theory : sig
3062
3072
(* * [require theory] manifests the [theory] as an OCaml structure.
3063
3073
3064
3074
It is only possible to create an instance of theory using the
3065
- {!instance} function. For example, the following will create an
3066
- theory that is a join all currently declared theories (which are
3067
- not specific to any context),
3075
+ {!instance} function, but see also {!current}.
3076
+
3077
+ For example, the following will create an theory that is a join
3078
+ all currently declared theories (which are not specific to any
3079
+ context),
3068
3080
3069
3081
{[
3070
- Theory.(instance>=>require) () -> fun (module Core) ->
3082
+ let* (module CT) = Theory.(instance>=>require) () in
3071
3083
]}
3072
3084
3073
- To a create an instance for a specific context and requirements,
3085
+ where [let*] comes from [KB.Let].
3086
+
3087
+ To create an instance for a specific context and requirements,
3074
3088
3075
3089
{[
3076
3090
Theory.instance ()
@@ -3089,6 +3103,41 @@ module Theory : sig
3089
3103
*)
3090
3104
val require : theory -> (module Core ) knowledge
3091
3105
3106
+
3107
+
3108
+ (* * [current] returns the current core theory structure.
3109
+
3110
+ This function is the same as [instance >=> require].
3111
+
3112
+ If there is no current theory set in the contex (via the
3113
+ {!with_current} function) then a new structure is created,
3114
+ otherwise returns the current selected theory.
3115
+
3116
+ An example of usage,
3117
+
3118
+ {[
3119
+ let add x y =
3120
+ let* (module CT) = current in
3121
+ CT.add x y
3122
+ ]}
3123
+
3124
+ @since 2.4.0
3125
+ *)
3126
+ val current : (module Core ) knowledge
3127
+
3128
+ (* * [with_current t f] sets [t] as the current theory in the scope of [f].
3129
+
3130
+ Evaluates compuation [f] in the theory of [t]. After [f] is
3131
+ evaluated the current theory is restored. This function could be
3132
+ safely called recursively, i.e., in a scope of another call to
3133
+ [with_current]. Effectively, [with_current], which uses
3134
+ [KB.Context.with_var] underneath the hood, creates a dynamic
3135
+ scope for the theory variable.
3136
+
3137
+ @since 2.4.0
3138
+ *)
3139
+ val with_current : theory -> (unit -> 'a knowledge ) -> 'a knowledge
3140
+
3092
3141
(* * Sorts implementing IEEE754 formats.
3093
3142
3094
3143
This module provides an infinite set of indexed sorts for
0 commit comments