summaryrefslogtreecommitdiff
path: root/interpret/interpret.ml
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ansys.com>2014-06-13 14:17:22 +0200
committerAlex Auvolat <alex.auvolat@ansys.com>2014-06-13 14:17:22 +0200
commitdedc98b0c14262c53e8573d7fe1dcaa370e43fb5 (patch)
treeac02f7271b054247984caa8aac13451ba98dc15b /interpret/interpret.ml
parentf7868083de2f351b5195149870e6e77398da44f9 (diff)
downloadscade-analyzer-dedc98b0c14262c53e8573d7fe1dcaa370e43fb5.tar.gz
scade-analyzer-dedc98b0c14262c53e8573d7fe1dcaa370e43fb5.zip
Move a lot of things.
Diffstat (limited to 'interpret/interpret.ml')
-rw-r--r--interpret/interpret.ml43
1 files changed, 12 insertions, 31 deletions
diff --git a/interpret/interpret.ml b/interpret/interpret.ml
index 373ed5f..6ff125c 100644
--- a/interpret/interpret.ml
+++ b/interpret/interpret.ml
@@ -1,32 +1,17 @@
open Ast
open Data
open Util
+open Ast_util
-(* Utility : find declaration of a const / a node *)
-let find_const_decl p id =
- match List.find (function
- | AST_const_decl (c, _) when c.name = id -> true
- | _ -> false)
- p with
- | AST_const_decl d -> d
- | _ -> assert false
-
-let find_node_decl p id =
- match List.find (function
- | AST_node_decl (c, _) when c.name = id -> true
- | _ -> false)
- p with
- | AST_node_decl d -> d
- | _ -> assert false
-
-(* Utility : build subscopes of equation ; extract pre declarations *)
+(* Utility : extract subscopes of equation ; extract pre declarations *)
(* subscopes :
prog -> expr ext -> (id * eqs * (id * expr ext) list) list
*)
let rec subscopes p e = match fst e with
- | AST_identifier _ | AST_int_const _ | AST_real_const _ | AST_bool_const _ -> []
+ | AST_idconst _ | AST_identifier _
+ | AST_int_const _ | AST_real_const _ | AST_bool_const _ -> []
| AST_unary (_, e') | AST_pre (e', _) | AST_not e' -> subscopes p e'
| AST_binary(_, e1, e2) | AST_binary_rel (_, e1, e2) | AST_binary_bool (_, e1, e2)
| AST_arrow(e1, e2) ->
@@ -41,7 +26,8 @@ let rec subscopes p e = match fst e with
(* extract_pre : expr ext -> (id * expr ext) list *)
let rec extract_pre e = match fst e with
- | AST_identifier _ | AST_int_const _ | AST_real_const _ | AST_bool_const _ -> []
+ | AST_identifier _ | AST_idconst _
+ | AST_int_const _ | AST_real_const _ | AST_bool_const _ -> []
| AST_unary (_, e') | AST_not e' -> extract_pre e'
| AST_binary(_, e1, e2) | AST_binary_rel (_, e1, e2) | AST_binary_bool (_, e1, e2)
| AST_arrow(e1, e2) ->
@@ -69,13 +55,13 @@ let rec eval_expr env st exp =
let sub_eval = eval_expr env in
let scope = List.hd env.scopes in
match fst exp with
- | AST_identifier (id, _) ->
+ | AST_identifier (id, _) | AST_idconst(id, _) ->
let rec aux = function
| [] ->
let st, v = get_var st env.c ("cst/"^id) in st, [v]
| sc::q ->
try let st, v = get_var st env.c (sc^"/"^id) in st, [v]
- with No_variable _ -> aux q
+ with _ -> aux q
in aux env.scopes
(* on numerical values *)
| AST_int_const (i, _) -> st, [VInt (int_of_string i)]
@@ -172,18 +158,13 @@ let rec calc_const p d st c =
| _ -> type_error ("Cannot assign tuple to constant" ^ d.name)
let program_consts p =
- let cdecl = List.fold_left
- (fun l d -> match d with
- | AST_const_decl (d, _) -> d::l
- | _ -> l)
- [] p
- in
+ let cdecl = extract_const_decls p in
let ccmap = List.fold_left
- (fun c d -> VarMap.add ("cst/"^d.name) (F (calc_const p d)) c)
+ (fun c (d, _) -> VarMap.add ("cst/"^d.name) (F (calc_const p d)) c)
VarMap.empty cdecl
in
List.fold_left
- (fun st d -> let st, _ = get_var st ccmap ("cst/"^d.name) in st)
+ (fun st (d, _) -> let st, _ = get_var st ccmap ("cst/"^d.name) in st)
VarMap.empty
cdecl
@@ -211,8 +192,8 @@ let program_init_state p root_node =
in
aux (program_consts p) p "" n.body
-(* Program execution *)
+(* Program execution *)
(* build calc map *)
let rec build_prog_ccmap p scopes eqs st =