From 023c11470e32744a43b7e3c7c248f3c47ebdc687 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 21 Nov 2016 17:06:19 +0100 Subject: Use gadt for function catalog --- expression.ml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'expression.ml') diff --git a/expression.ml b/expression.ml index f516463..1feb62e 100755 --- a/expression.ml +++ b/expression.ml @@ -1,6 +1,5 @@ module C = Catalog - -module Calendar = CalendarLib.Calendar.Precise +module Tuple2 = Tools.Tuple2 let u = UTF8.from_utf8string @@ -35,7 +34,6 @@ let load content = begin try String.sub content 0 (String.index content '\000') with Not_found -> content in Basic ( - (*try ScTypes.Num (Tools.Num.of_float_string content')*) try Lexing.from_string content' |> ExpressionParser.content ExpressionLexer.read with _ -> ScTypes.Str (UTF8.from_utf8string content') @@ -47,19 +45,16 @@ let load content = begin ) end + let load_expr expr = expr + (** Extract the parameters to give to a function. return an Error if one of them is an error *) let eval expr sources = begin - let rec eval_exp: ScTypes.expression -> ScTypes.types = function - | ScTypes.Value v -> v - | ScTypes.Call (ident, params) -> C.eval ident (List.map eval_exp params) - | ScTypes.Ref r -> sources r - | ScTypes.Expression expr -> eval_exp expr - in + let eval_exp f = Evaluator.repr sources f in begin try match expr with | Basic value -> ScTypes.Result value @@ -72,7 +67,14 @@ end let collect_sources expr = begin let rec collect refs = function - | ScTypes.Ref r -> Cell.Set.union refs (Cell.Set.of_list @@ ScTypes.Refs.collect r) + | ScTypes.Ref r -> + begin match ScTypes.Refs.collect r with + | ScTypes.Refs.Single r -> Cell.Set.add r refs + | ScTypes.Refs.Array1 a1 -> + List.fold_left (fun set elt -> Cell.Set.add elt set) refs a1 + | ScTypes.Refs.Array2 a2 -> + List.fold_left (List.fold_left (fun set elt -> Cell.Set.add elt set)) refs a2 + end | ScTypes.Call (ident, params) -> List.fold_left collect refs params | ScTypes.Expression f -> collect refs f | _ -> refs -- cgit v1.2.3