heptagon/compiler/obc/obc.ml

127 lines
3.5 KiB
OCaml
Raw Normal View History

2010-06-15 10:49:03 +02:00
(**************************************************************************)
(* *)
(* Heptagon *)
(* *)
(* Author : Marc Pouzet *)
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
(* *)
(**************************************************************************)
(* Object code internal representation *)
2011-03-08 13:41:28 +01:00
(** { 3 Semantics }
Any variable is a reference to a constant memory.
Thus [p = e] is not the change of the reference,
but a recursive copy of what is referenced (deep copy).
As an example, [x = 3] but also [x = \[3; 4; 5\]]
and [t1 = t2] with the content of the array [t2] copied into the array [t1].
Obc is also "SSA" in the sens that a variable is assigned a value only once per call of [step] etc.
Thus arguments are passed as constant references to a constant memory.
One exception to the SSA rule is through the [mutable] variables.
Theses variables can be assigned multiple times.
Thus a [mutable] argument is passed as a reference to a constant memory.
*)
2010-06-15 10:49:03 +02:00
open Misc
open Names
open Idents
2010-07-07 11:17:18 +02:00
open Types
open Signature
2010-07-08 17:17:00 +02:00
open Location
2010-09-13 09:03:15 +02:00
type class_name = qualname
type op_name = qualname
2011-01-20 23:05:18 +01:00
type obj_ident = var_ident
2010-06-15 10:49:03 +02:00
type type_dec =
2011-01-20 23:05:18 +01:00
{ t_name : type_name;
t_desc : tdesc;
2010-07-08 17:17:00 +02:00
t_loc : location }
2010-06-15 10:49:03 +02:00
and tdesc =
| Type_abs
| Type_alias of ty
2010-09-13 13:44:26 +02:00
| Type_enum of constructor_name list
| Type_struct of structure
2010-06-15 10:49:03 +02:00
2010-07-08 17:17:00 +02:00
type const_dec = {
2010-09-13 09:03:15 +02:00
c_name : qualname;
2010-07-08 17:17:00 +02:00
c_value : static_exp;
c_type : ty;
2010-07-08 17:17:00 +02:00
c_loc : location }
type pattern = { pat_desc : pat_desc; pat_ty : ty; pat_loc : location }
2010-07-07 11:17:18 +02:00
and pat_desc =
| Lvar of var_ident
| Lmem of var_ident
| Lfield of pattern * field_name
| Larray of pattern * exp
2010-07-07 11:17:18 +02:00
2010-07-08 17:17:00 +02:00
and exp = { e_desc : exp_desc; e_ty : ty; e_loc : location }
2010-06-15 10:49:03 +02:00
2010-07-07 11:17:18 +02:00
and exp_desc =
2011-01-24 16:07:26 +01:00
| Epattern of pattern
2010-07-07 11:17:18 +02:00
| Econst of static_exp
| Eop of op_name * exp list
| Estruct of type_name * (field_name * exp) list
| Earray of exp list
type obj_ref =
2011-01-20 23:05:18 +01:00
| Oobj of obj_ident
| Oarray of obj_ident * pattern
2010-07-07 11:17:18 +02:00
type method_name =
| Mreset
| Mstep
2010-06-15 10:49:03 +02:00
type act =
| Aassgn of pattern * exp
| Acall of pattern list * obj_ref * method_name * exp list
| Acase of exp * (constructor_name * block) list
2011-01-24 16:07:26 +01:00
| Afor of var_dec * static_exp * static_exp * block
2011-03-08 13:41:28 +01:00
| Ablock of block
2010-07-07 11:17:18 +02:00
and block =
{ b_locals : var_dec list;
b_body : act list }
2010-06-15 10:49:03 +02:00
and var_dec =
{ v_ident : var_ident;
v_type : ty;
2010-07-08 17:17:00 +02:00
v_loc : location }
2010-06-15 10:49:03 +02:00
type obj_dec =
2011-01-20 23:05:18 +01:00
{ o_ident : obj_ident;
o_class : class_name;
o_params : static_exp list;
2011-01-20 23:05:18 +01:00
o_size : static_exp option; (** size of the array if the declaration is an array of obj *)
2010-07-08 17:17:00 +02:00
o_loc : location }
2010-07-07 09:44:23 +02:00
type method_def =
2010-07-09 09:31:12 +02:00
{ m_name : method_name;
2010-07-08 17:17:00 +02:00
m_inputs : var_dec list;
m_outputs : var_dec list;
m_body : block; }
2010-07-07 09:44:23 +02:00
type class_def =
2010-07-08 17:17:00 +02:00
{ cd_name : class_name;
2011-03-21 14:30:19 +01:00
cd_stateful : bool; (** when false, the class is a function with static parameters
calling other functions with parameters *)
2010-07-08 17:17:00 +02:00
cd_mems : var_dec list;
cd_objs : obj_dec list;
cd_params : param list;
2010-07-08 17:17:00 +02:00
cd_methods: method_def list;
cd_loc : location }
2010-07-07 09:44:23 +02:00
2011-03-21 14:30:19 +01:00
2010-07-07 09:44:23 +02:00
type program =
{ p_modname : modul;
p_opened : modul list;
2010-07-07 09:44:23 +02:00
p_types : type_dec list;
2010-07-08 17:17:00 +02:00
p_consts : const_dec list;
2011-03-21 14:30:19 +01:00
p_classes : class_def list; }
2010-06-15 10:49:03 +02:00