aboutsummaryrefslogtreecommitdiff
path: root/src/expressions/evaluate.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/expressions/evaluate.ml')
-rw-r--r--[-rwxr-xr-x]src/expressions/evaluate.ml80
1 files changed, 42 insertions, 38 deletions
diff --git a/src/expressions/evaluate.ml b/src/expressions/evaluate.ml
index ff44097..fbf2a18 100755..100644
--- a/src/expressions/evaluate.ml
+++ b/src/expressions/evaluate.ml
@@ -26,12 +26,6 @@ type 'a value =
type existencialResult =
| Result : 'a value -> existencialResult [@@unboxed]
-type t = (Functions.C.t * (int * int -> ScTypes.Result.t option))
-
-type repr = existencialResult
-
-type obs = ScTypes.Result.t
-
module T:Sym_type.SYM_TYPE with type 'a obs = existencialResult = struct
type 'a t = 'a value
@@ -50,6 +44,12 @@ module T:Sym_type.SYM_TYPE with type 'a obs = existencialResult = struct
end
+type dic = (Functions.C.t * (int * int -> ScTypes.Result.t option))
+
+type t = dic -> existencialResult
+
+type obs = dic -> ScTypes.Result.t
+
module R = Eval_ref
(** Extract the type and the content from a value *)
@@ -97,63 +97,67 @@ let ref r (_, mapper) = begin
| R.Matrix (t, l) -> Result (Matrix(t, l))
end
+let observe repr catalog = begin
+ let Result r = repr catalog in match r with
+ | Bool b -> ScTypes.Result.Ok (ScTypes.Type.boolean b)
+ | String s -> ScTypes.Result.Ok (ScTypes.Type.string s)
+ | Num (format, n) ->
+ begin match format with
+ (* We can only match numeric formats here *)
+ | ScTypes.DataFormat.Date -> ScTypes.Result.Ok (ScTypes.Type.date n)
+ | ScTypes.DataFormat.Number -> ScTypes.Result.Ok (ScTypes.Type.number n)
+ end
+ | _ -> raise Errors.TypeError
+end
+
+let expression e = e
+
let call0 ident (catalog, _) =
let name' = UTF8.to_utf8string ident in
- let arg1 = (Functions.t_unit, ()) in
+ let (arg1:(unit Functions.C.argument * unit)) = (Functions.t_unit, ()) in
wrap_call
(Functions.C.eval1 catalog name' arg1)
(fun () -> raise Errors.TypeError)
-let call1 ident p1 (catalog, _) =
+let call1 ident p1 ((catalog, _) as c) =
let name' = UTF8.to_utf8string ident in
- let (Result r1) = p1 in
+ (* Evaluate here p1 expression *)
+ let (Result r1) = p1 c in
let arg1 = get_argument r1 in
wrap_call
(Functions.C.eval1 catalog name' arg1)
- (fun () -> build_format_list [p1])
+ (fun () -> build_format_list [Result r1])
-let call2 ident p1 p2 (catalog, _) =
+let call2 ident p1 p2 ((catalog, _) as c) =
let name' = UTF8.to_utf8string ident in
- let (Result r1) = p1 in
- let (Result r2) = p2 in
+ let (Result r1) = p1 c in
+ let (Result r2) = p2 c in
let arg1 = get_argument r1
and arg2 = get_argument r2 in
wrap_call
(Functions.C.eval2 catalog name' arg1 arg2)
- (fun () -> build_format_list [p1; p2])
+ (fun () -> build_format_list [Result r1; Result r2])
-let call3 ident p1 p2 p3 (catalog, _) =
+let call3 ident p1 p2 p3 ((catalog, _) as c) =
let name' = UTF8.to_utf8string ident in
- let (Result r1) = p1 in
- let (Result r2) = p2 in
- let (Result r3) = p3 in
+ let (Result r1) = p1 c in
+ let (Result r2) = p2 c in
+ let (Result r3) = p3 c in
let arg1 = get_argument r1
and arg2 = get_argument r2
and arg3 = get_argument r3 in
wrap_call
(Functions.C.eval3 catalog name' arg1 arg2 arg3)
- (fun () -> build_format_list [p1; p2 ; p3])
+ (fun () -> build_format_list [Result r1; Result r2; Result r3])
-let callN ident params (catalog, _) =
- let signature = List.map (fun (Result r) ->
+let callN ident params ((catalog, _) as c) =
+
+ let map_params expression = begin
+ let (Result r) = expression c in
let formatter = Format.str_formatter in
Functions.repr formatter (fst @@ get_argument r);
- Format.flush_str_formatter ()) params in
+ Format.flush_str_formatter ()
+ end in
+ let signature = List.map map_params params in
raise (Errors.Undefined (ident, signature))
-let expression e _ = e
-
-let observe repr = begin
- let Result r = repr in match r with
- | Bool b -> ScTypes.Result.Ok (ScTypes.Type.boolean b)
- | String s -> ScTypes.Result.Ok (ScTypes.Type.string s)
- | Num (format, n) ->
- begin match format with
- (* We can only match numeric formats here *)
- | ScTypes.DataFormat.Date -> ScTypes.Result.Ok (ScTypes.Type.date n)
- | ScTypes.DataFormat.Number -> ScTypes.Result.Ok (ScTypes.Type.number n)
- end
- | _ -> raise Errors.TypeError
-
-end
-