X-Git-Url: http://git.annexia.org/?p=whenjobs.git;a=blobdiff_plain;f=lib%2Fwhenexpr.mli;h=12ba5841f637f28bb19fe29e09b0baae5b429ae3;hp=3c05826aa277d995012632656308dcb61b67481f;hb=5c7aa66dbdb32b4fc11d0f72a4cc028c7bfb1b55;hpb=76e68068f22a67c788f14a7c9404db7f7514da49 diff --git a/lib/whenexpr.mli b/lib/whenexpr.mli index 3c05826..12ba584 100644 --- a/lib/whenexpr.mli +++ b/lib/whenexpr.mli @@ -39,6 +39,7 @@ type whenexpr = | Expr_mul of whenexpr * whenexpr (** arithmetic multiplication *) | Expr_div of whenexpr * whenexpr (** arithmetic division *) | Expr_mod of whenexpr * whenexpr (** arithmetic modulo *) + | Expr_len of whenexpr (** length *) | Expr_changes of string (** changes var *) | Expr_increases of string (** increases var *) | Expr_decreases of string (** decreases var *) @@ -75,9 +76,6 @@ val rpc_of_variable : variable -> Whenproto_aux.variable type variables = variable Whenutils.StringMap.t (** A set of variables. *) -type job_private -(** Private state associated with a job, used for evaluation. *) - type job_cond = | When_job of whenexpr (** when ... : << >> *) | Every_job of periodexpr (** every ... : << >> *) @@ -87,17 +85,8 @@ type job = { job_name : string; job_cond : job_cond; job_script : shell_script; - job_private : job_private; } -(** A job. Note that because of the [job_private] field, these cannot - be constructed directly. Use {!make_when_job} or {!make_every_job} - to construct one. *) - -val make_when_job : Camlp4.PreCast.Loc.t -> string -> whenexpr -> shell_script -> job -(** Make a when-statement job. *) - -val make_every_job : Camlp4.PreCast.Loc.t -> string -> periodexpr -> shell_script -> job -(** Make an every-statement job. *) +(** A job. *) val expr_of_ast : Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.expr -> whenexpr (** Convert OCaml AST to an expression. Since OCaml ASTs are much @@ -117,14 +106,26 @@ val dependencies_of_whenexpr : whenexpr -> string list val dependencies_of_job : job -> string list (** Which variables does this job depend on? *) -val job_evaluate : job -> variables -> bool -> bool * job -(** [job_evaluate job variables onload] evaluates [job]'s condition in - the context of the [variables], and return [true] iff it should be - run now. +val eval_whenexpr : variables -> variables option -> bool -> whenexpr -> variable +val eval_whenexpr_as_bool : variables -> variables option -> bool -> whenexpr -> bool +(** [eval_whenexpr variables prev_variables onload expr] is the + evaluation function for when expressions. It full evaluates + [expr], returning its typed value. It can also throw exceptions + (at least [Invalid_argument] and [Failure]). + + [eval_whenexpr_as_bool] is the same but it forces the returned + value to be a boolean. + + The other parameters represent the current and past state: + + [variables] is the current set of variables and their values. - Note that this returns a possibly-updated [job] structure. + [prev_variables] is the set of variables from the previous + run. It is used to implement {i prev}, {i changes} etc operators. + This can be [None], meaning there is no previous state. - This is a no-op for 'every' jobs. *) + [onload] is used to implement the {i reloaded} operator. It is + true if the file is being reloaded, and false otherwise. *) val next_periodexpr : float -> periodexpr -> float (** [next_periodexpr t period] returns the earliest event of [period]