Project

General

Profile

Revision 5fccce23 src/compiler_common.ml

View differences:

src/compiler_common.ml
153 153
  let new_cenv = clock_decls Basic_library.clock_env header in   (* Clock calculus *)
154 154
  header, new_tenv, new_cenv
155 155

  
156
let get_envs_from_const const_decl (ty_env, ck_env) =
157
  (Env.add_value ty_env const_decl.const_id const_decl.const_type,
158
   Env.add_value ck_env const_decl.const_id (Clocks.new_var true))
159

  
160
let get_envs_from_consts const_decls (ty_env, ck_env) =
161
  List.fold_right get_envs_from_const const_decls (ty_env, ck_env)
162

  
163
let rec get_envs_from_top_decl (ty_env, ck_env) top_decl =
164
 match top_decl.top_decl_desc with
165
 | Node nd          -> (Env.add_value ty_env nd.node_id nd.node_type,
166
			Env.add_value ck_env nd.node_id nd.node_clock)
167
 | ImportedNode ind -> (Env.add_value ty_env ind.nodei_id ind.nodei_type,
168
			Env.add_value ck_env ind.nodei_id ind.nodei_clock)
169
 | Const c          -> get_envs_from_const c (ty_env, ck_env)
170
 | TypeDef _        -> List.fold_left get_envs_from_top_decl (ty_env, ck_env) (consts_of_enum_type top_decl)
171
 | Open _           -> (ty_env, ck_env)
172

  
173
(* get type and clock environments from a header *)
174
let get_envs_from_top_decls header =
175
  List.fold_left get_envs_from_top_decl (Env.initial, Env.initial) header
176 156

  
177 157
(*
178 158
 List.fold_right
......
226 206
      Location.pp_loc loc;
227 207
    raise exc
228 208

  
229
let is_stateful topdecl =
230
  match topdecl.top_decl_desc with
231
  | Node nd -> (match nd.node_stateless with Some b -> not b | None -> not nd.node_dec_stateless)
232
  | ImportedNode nd -> not nd.nodei_stateless 
233
  | _ -> false
234

  
235
(* Beware of the side effect: reads and modifies Global.(type_env/clock_env) *)
236
let rec import_dependencies prog : dep_t list =
237
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 4>.. extracting dependencies");
238
  let dependencies = Corelang.get_dependencies prog in
239
  let (compilation_deps, type_env, clock_env) =
240
  List.fold_left
241
    (fun (compilation_dep, type_env, clock_env) dep ->
242
      let (local, s) = Corelang.dependency_of_top dep in
243
      let basename = Options_management.name_dependency (local, s) in
244
      Log.report ~level:1 (fun fmt -> Format.fprintf fmt "@ Library %s@ " basename);
245
      let lusic = Modules.import_dependency dep.top_decl_loc (local, s) in
246
      (*Log.report ~level:1 (fun fmt -> Format.fprintf fmt "");*)
247
      let lusic_deps = import_dependencies lusic.Lusic.contents in
248
      let (lusi_type_env, lusi_clock_env) = get_envs_from_top_decls lusic.Lusic.contents in
249
      let is_stateful = List.exists is_stateful lusic.Lusic.contents in
250
      let new_dep = Dep (local, s, lusic.Lusic.contents, is_stateful ) in
251
      new_dep::lusic_deps@compilation_dep,
252
      Env.overwrite type_env lusi_type_env,
253
      Env.overwrite clock_env lusi_clock_env)
254
    ([], !Global.type_env, !Global.clock_env)
255
    dependencies in
256
  Global.type_env := type_env; 
257
  Global.clock_env := clock_env;
258
  begin
259
    Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ ");
260
    compilation_deps
261
  end
262 209

  
263 210
let track_exception () =
264 211
  if !Options.track_exceptions

Also available in: Unified diff