Updated Obc Ast

This commit is contained in:
Cédric Pasteur 2010-07-07 11:17:18 +02:00
parent 72ee834641
commit 587ed634ea

View file

@ -11,6 +11,7 @@
open Misc
open Names
open Ident
open Types
type var_name = ident
type type_name = longname
@ -21,13 +22,6 @@ type obj_name = name
type op_name = longname
type field_name = longname
type ty =
| Tint
| Tfloat
| Tbool
| Tid of type_name
| Tarray of ty * static_exp
type type_dec =
{ t_name : name;
t_desc : tdesc }
@ -37,54 +31,61 @@ and tdesc =
| Type_enum of name list
| Type_struct of (name * ty) list
type lhs =
| Var of var_name
| Mem of var_name
| Field of lhs * field_name
| Array of lhs * exp
type lhs = { l_desc : lhs_desc; l_ty : ty }
and exp =
| Lhs of lhs
| Const of static_exp
| Op of op_name * exp list
| Struct_lit of type_name * (field_name * exp) list
| Array_lit of exp list
and lhs_desc =
| Lvar of var_name
| Lmem of var_name
| Lfield of lhs * field_name
| Larray of lhs * exp
and exp = { e_desc : exp_desc; e_ty : ty }
and exp_desc =
| Elhs of lhs
| Econst of static_exp
| Eop of op_name * exp list
| Estruct of type_name * (field_name * exp) list
| Earray of exp list
type obj_call =
| Context of obj_name
| Array_context of obj_name * lhs
| Oobj of obj_name
| Oarray of obj_name * lhs
type method_name =
| Mreset
| Mstep
| Mother of name
(* act list au lieu de Comp *)
type act =
| Assgn of lhs * exp
| Call of lhs list * obj_call * exp list
| Case of exp * (longname * act list) list
| For of var_name * static_exp * static_exp * act list
| Reinit of obj_name
| Aassgn of lhs * exp
| Acall of lhs list * obj_call * method_name * exp list
| Acase of exp * (longname * block) list
| Afor of var_name * static_exp * static_exp * block
and block = act list
type var_dec =
{ v_ident : var_name;
v_type : ty;
(*v_controllable : bool*) }
v_type : ty; (*v_controllable : bool*) }
type obj_dec =
{ o_name : obj_name;
o_method : fun_name;
o_class : instance_name;
o_size : int; }
o_size : static_exp; }
type method_def =
{ f_name : fun_name;
f_inputs : var_dec list;
f_outputs : var_dec list;
f_locals : var_dec list;
f_body : act list }
f_body : act list; }
type class_def =
{ c_name : class_name;
c_mems : var_dec list;
c_objs : obj_dec list;
c_methods: method_def list; (*Map ?*) }
c_methods: method_def list; }
type program =
{ p_pragmas: (name * string) list;
@ -92,28 +93,21 @@ type program =
p_types : type_dec list;
p_defs : class_def list }
(*
type step_fun =
{ inp : var_dec list;
out : var_dec list;
local : var_dec list;
controllables : var_dec list; (* GD : ugly patch to delay controllable
variables definition to target code
generation *)
bd : act }
type reset_fun = act
*)
let mk_var_dec name ty =
{ v_ident = name; v_type = ty }
let mk_exp ?(ty=invalid_type) desc =
{ e_desc = desc; e_ty = ty }
let mk_lhs ?(ty=invalid_type) desc =
{ l_desc = desc; l_ty = ty }
let rec var_name x =
match x with
| Var x -> x
| Mem x -> x
| Field(x,_) -> var_name x
| Array(l, _) -> var_name l
| Lvar x -> x
| Lmem x -> x
| Lfield(x,_) -> var_name x
| Larray(l, _) -> var_name l
(** Returns whether an object of name n belongs to
a list of var_dec. *)
@ -129,5 +123,5 @@ let rec vd_find n = function
if vd.v_ident = n then vd else vd_find n l
let lhs_of_exp = function
| Lhs l -> l
| Elhs l -> l
| _ -> assert false