summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interpret/interpret.ml25
1 files changed, 15 insertions, 10 deletions
diff --git a/interpret/interpret.ml b/interpret/interpret.ml
index 4584fa4..3b4796f 100644
--- a/interpret/interpret.ml
+++ b/interpret/interpret.ml
@@ -23,10 +23,10 @@ let find_node_decl p id =
(* Expression evaluation *)
(*
- eval_expr : calc_map -> state -> string -> expr ext -> (state * value)
+ eval_expr : prog -> calc_map -> state -> string -> expr ext -> (state * value)
*)
-let rec eval_expr c scope st exp =
- let sub_eval = eval_expr c scope in
+let rec eval_expr p c scope st exp =
+ let sub_eval = eval_expr p c scope in
match fst exp with
| AST_identifier (id, _) ->
begin try let st, v = get_var st c (scope^"/"^id) in st, [v]
@@ -110,12 +110,17 @@ let rec eval_expr c scope st exp =
| [VBool false] -> sub_eval st b
| _ -> type_error "Invalid condition in if."
end
- | AST_instance((f, _), args, id) -> not_implemented "instance"
+ | AST_instance((f, _), args, nid) ->
+ let (n, _) = find_node_decl p f in
+ List.fold_left
+ (fun (st, vs) (_, (id,_), _) -> let st, v = get_var st c (scope^"/"^nid^"/"^id) in
+ st, vs @ [v])
+ (st, []) n.ret
(* Constant calculation *)
-let rec calc_const d st c =
- match eval_expr c "cst" st d.value with
+let rec calc_const p d st c =
+ match eval_expr p c "cst" st d.value with
| st, [v] -> VarMap.add ("cst/"^d.name) v st
| _ -> type_error ("Cannot assign tuple to constant" ^ d.name)
@@ -127,7 +132,7 @@ let program_consts p =
[] p
in
let ccmap = List.fold_left
- (fun c d -> VarMap.add ("cst/"^d.name) (F (calc_const d)) c)
+ (fun c d -> VarMap.add ("cst/"^d.name) (F (calc_const p d)) c)
VarMap.empty cdecl
in
List.fold_left
@@ -174,7 +179,7 @@ let rec build_prog_ccmap p scope eqs st =
let add_eq c eq = match fst eq with
| AST_assign(vars, e) ->
let calc st c =
- let st, vals = eval_expr c scope st e in
+ let st, vals = eval_expr p c scope st e in
List.fold_left2
(fun st (id,_) v -> VarMap.add (scope^"/"^id) v st)
st vars vals
@@ -190,7 +195,7 @@ let rec build_prog_ccmap p scope eqs st =
in
let add_v c ((_, (id, _), _), eq) =
let calc st c =
- let st, vals = eval_expr c scope st eq in
+ let st, vals = eval_expr p c scope st eq in
match vals with
| [v] -> VarMap.add (scope^"/"^ss_id^"/"^id) v st
| _ -> type_error "invalid arity"
@@ -224,7 +229,7 @@ let extract_next_state active p scope eqs st ccmap =
| AST_assign(vars, e) ->
let st, nst = add_subscopes active (st, nst) (subscopes p e) in
List.fold_left (fun (st, nst) (pn, pe) ->
- let st, v = if active then eval_expr ccmap scope st pe
+ let st, v = if active then eval_expr p ccmap scope st pe
else st,
try match VarMap.find (scope^"/"^pn) st with VPrevious x -> x | _ -> []
with Not_found -> []