aboutsummaryrefslogtreecommitdiff
path: root/expression.ml
diff options
context:
space:
mode:
Diffstat (limited to 'expression.ml')
-rwxr-xr-xexpression.ml22
1 files changed, 12 insertions, 10 deletions
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