From 112ab4b1c396fc2117191297227d8e411f9b9bb3 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 19 Jan 2018 11:24:29 +0100 Subject: Better memory management --- src/evaluator.ml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/evaluator.ml') diff --git a/src/evaluator.ml b/src/evaluator.ml index ed384e6..05b975f 100755 --- a/src/evaluator.ml +++ b/src/evaluator.ml @@ -108,33 +108,35 @@ let eval mapper value = begin end in (** Extract the value from an expression. - [extract typ expr] will evaluate the expression and return it. If the - result cannot be evaluated (because of references pointing to missing - values) a default value of type [typ] will be returned. + [extract expr] will evaluate the expression and return it. If the result + cannot be evaluated (because of references pointing to missing values) a + default value of type [typ] will be returned. *) let rec extract = begin function (* For a reference to an external we first extract the value pointed *) | ScTypes.Ref r -> ScTypes.Refs.( begin match ScTypes.Refs.get_content @@ mapper r with - | C (Value (format, f)) -> begin match format with + | Value (format, f) -> begin match format with | ScTypes.Date -> Result (Data.Num (format, f)) | ScTypes.Number -> Result (Data.Num (format, f)) | ScTypes.String -> Result (Data.String f) | ScTypes.Bool -> Result (Data.Bool f) end - | C (List (format, l)) -> Result (Data.List (format, l)) - | C (Matrix (format, l)) -> Result (Data.Matrix (format, l)) + | List (format, l) -> Result (Data.List (format, l)) + | Matrix (format, l) -> Result (Data.Matrix (format, l)) end) (* Evaluate the expression *) | ScTypes.Expression e -> extract e | ScTypes.Value v -> extract_value (ScTypes.Result v) | ScTypes.Call (name, args) -> + (* The function is not tail recursive, but I don't think we will have + more than 100 nested functions here... *) let args' = List.map extract args in call name args' end in - let Result r = ((extract[@tailrec]) value) in + let Result r = extract value in begin match r with | Data.Bool b -> ScTypes.Result (ScTypes.boolean b) | Data.String s -> ScTypes.Result (ScTypes.string s) -- cgit v1.2.3