1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
18 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
20 (* ********************************************************************** *)
22 include "compiler/linearfe.ma".
24 (* ***************************** *)
25 (* PASSO 3 : da ASTFE a LINEARFE *)
26 (* ***************************** *)
29 ASTFE_STM_ASG: ∀t:ast_type.
30 astfe_var e false t → astfe_expr e t → astfe_stm e
31 | ASTFE_STM_INIT: ∀b:bool.∀t:ast_type.
32 astfe_id e b t → astfe_init e t → astfe_stm e
33 | ASTFE_STM_WHILE: astfe_base_expr e → astfe_body e → astfe_stm e
34 | ASTFE_STM_IF: ne_list (Prod (astfe_base_expr e) (astfe_body e)) → option (astfe_body e) → astfe_stm e
36 inductive astfe_to_linearfe_stm_record (fe:aux_flatEnv_type) : Type ≝
37 ASTFE_TO_LINEARFE_STM_RECORD_SINGLE: linearfe_stm fe → astfe_to_linearfe_stm_record fe
38 | ASTFE_TO_LINEARFE_STM_RECORD_MULTI: nat → jumpBlock fe → linearfe_prog fe → astfe_to_linearfe_stm_record fe.
40 let rec astfe_to_linearfe_stm fe (ast:astfe_stm fe) (nextL:nat) on ast
41 : astfe_to_linearfe_stm_record fe ≝
43 [ ASTFE_STM_ASG sType sVar sExpr ⇒
44 ASTFE_TO_LINEARFE_STM_RECORD_SINGLE fe (LINEARFE_STM_ASG fe sType sVar sExpr)
46 | ASTFE_STM_INIT sB sType sId sInit ⇒
47 ASTFE_TO_LINEARFE_STM_RECORD_SINGLE fe (LINEARFE_STM_INIT fe sB sType sId sInit)
49 | ASTFE_STM_WHILE sExpr sBody ⇒ False_rect ? daemon
51 | ASTFE_STM_IF sNelExprBody sOptBody ⇒ False_rect ? daemon
55 ASTFE_BODY: list (astfe_stm e) → astfe_body e
57 and astfe_to_linearfe_body fe (ast:list (astfe_stm fe)) (res:list (linearfe_stm fe))
58 (beginL:jumpLabel) (endJump:jumpBlock fe) (nextL:nat) on ast
59 : Prod nat (linearfe_prog fe) ≝
62 pair ?? nextL [ LINEARFE_ELEM fe beginL res endJump ]
69 let rec aux (pLStm:list (astfe_stm fe)) (pRes:list (linearfe_stm fe))
70 on pLStm : Prod nat (linearfe_prog fe) ≝
73 pair ?? nextL [ LINEARFE_ELEM fe beginL pRes endJump ]
76 match astfe_to_linearfe_stm fe h nextL with
77 [ ASTFE_TO_LINEARFE_STM_RECORD_SINGLE resStm ⇒ aux t (pRes@[ resStm ])
79 | ASTFE_TO_LINEARFE_STM_RECORD_MULTI resNextL resJumpBlock resProg ⇒
80 match astfe_to_linearfe_body fe (ASTFE_BODY fe (*t*)[]) (*N_LABEL nextL*)beginL endJump (*resNextL*)1 with
81 [ pair resNextL' resProg' ⇒
82 (*pair ?? resNextL' ([ LINEARFE_ELEM fe beginL pRes resJumpBlock ]@resProg)*)False_rect ? daemon
91 AST_ROOT: ast_decl O empty_env → ast_root
93 definition ast_to_astfe : ast_root → (Σfe.astfe_root fe) ≝
94 λast:ast_root.match ast with
95 [ AST_ROOT decl ⇒ match ast_to_astfe_decl O empty_env decl empty_map empty_flatEnv env_map_flatEnv_empty_aux with
96 [ AST_TO_ASTFE_DECL_RECORD _ resFe _ _ _ resLStm ⇒ ≪resFe,ASTFE_ROOT resFe (ASTFE_BODY resFe resLStm)≫ ]].