Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpouzet committed Oct 28, 2024
1 parent 1dba3af commit 30b0b2b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/compiler/gencode/obc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ and ientry =
i_machine: exp; (* the machine it belongs to *)
i_kind: Deftypes.kind; (* the kind of the machine *)
i_params: exp path; (* static parameters used at instance creation *)
i_sizes: exp list; (* it is possibly an array of instances *)
i_size: exp list; (* it is possibly an array of instances *)
}

and method_desc =
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/gencode/ocamlprinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,24 @@ and print_memory ff { m_name; m_value; m_typ; m_kind; m_size } =
end
| Some(k) ->
match k with
Ezero ->
Zero ->
fprintf ff "@[%a = @[<hov 2>{ zin = %a;@ zout = %a }@]@]"
name m_name (array_of m_value Initial.typ_bool) m_size
(array_of (Some(Econst(Efloat(1.0)))) Initial.typ_float)
m_size
| Econt ->
| Cont ->
fprintf ff "@[%a = @[<hov 2>{ pos = %a; der = %a }@]@]"
name m_name (array_of m_value m_typ) m_size
(* the default value of a derivative must be zero *)
(array_of (Some(Econst(Efloat(0.0)))) m_typ) m_size
| Ehorizon | Emajor | Eperiod | Eencore ->
| Horizon | Major | Period | Encore ->
fprintf ff "%a = %a" name m_name (array_of m_value m_typ) m_size


and print_instance ff { i_name; i_machine; i_kind; i_params; i_sizes } =
and print_instance ff { i_name; i_machine; i_kind; i_params; i_size } =
fprintf ff "@[%a = %a (* %s *)@ @]" name i_name
(array_make (fun ff n -> fprintf ff "%a_alloc ()" name n) i_name)
i_sizes (kind i_kind)
i_size (kind i_kind)

and exp_with_typ ff (e, ty) = fprintf ff "(%a:%a)" (exp 2) e ptype ty

Expand Down Expand Up @@ -344,7 +344,7 @@ let palloc f i_opt memories ff instances =

(* print an entry [let n_alloc, n_step, n_reset, ... = f ... in] *)
(* for every instance *)
let def_instance_function ff { i_name; i_machine; i_kind; i_params; i_sizes } =
let def_instance_function ff { i_name; i_machine; i_kind; i_params; i_size } =
(* Define the method *)
let method_name ff me_name =
let m = method_name me_name in
Expand All @@ -360,7 +360,7 @@ let def_instance_function ff { i_name; i_machine; i_kind; i_params; i_sizes } =
fprintf ff
"@[let %s { alloc = %a_alloc; %a } = %a %a in@]"
k name i_name list_of_methods m_name_list
(exp 0) i_machine (print_list_r (exp 1) "" " " "") i_sizes
(exp 0) i_machine (print_list_r (exp 1) "" " " "") i_size

(* Print a machine as pieces with a type definition for the state *)
(* and a collection of functions *)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/gencode/oprinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ and memory ff { m_name; m_value; m_typ; m_kind; m_size } =
(print_list_no_space (print_with_braces (exp 0) "[" "]") "" "" "")
m_size ptype m_typ (print_opt (exp 0)) m_value

and instance ff { i_name; i_machine; i_kind; i_params; i_sizes } =
and instance ff { i_name; i_machine; i_kind; i_params; i_size } =
fprintf ff "@[%a : %s(%a)%a%a@]" name i_name (kind i_kind) (exp 0) i_machine
(print_list_no_space
(print_with_braces (exp 0) "(" ")") "" "" "")
i_params
(print_list_no_space
(print_with_braces (exp 0) "[" "]") "" "" "")
i_sizes
i_size

and pmethod ff { me_name; me_params; me_body; me_typ } =
fprintf ff "@[<hov 2>method %s %a@ =@ (%a:%a)@]"
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/gencode/translate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ let apply k env loop_path e e_list
| Deftypes.Tfun _ -> Eapp { f = e; arg_list = e_list }, code
| Deftypes.Tnode _ ->
(* the first [n-1] arguments are static *)
let se_list, arg = Misc.firsts e_list in
let f_opt = match e with | Eglobal(g) -> Some(g) | _ -> None in
let loop_path = List.map (fun ix -> Elocal(ix)) loop_path in
let se_list, arg = Util.firsts e_list in
let f_opt = match e with | Eglobal { lname } -> Some lname | _ -> None in
let loop_path =
List.map (fun ix -> Evar { is_mutable = false; id = ix }) loop_path in
(* create an instance *)
let o = Ident.fresh "i" in
let j_code = { i_name = o; i_machine = e; i_kind = k;
Expand All @@ -338,8 +339,8 @@ let apply k env loop_path e e_list
met_instance = Some(o, loop_path); met_args = [arg] }) in
step_code,
{ code with instances = Parseq.cons j_code j;
init = seq (Oexp(reset_code)) i;
reset = seq (Oexp(reset_code)) r }
init = Oaux.seq reset_code i;
reset = Oaux.seq reset_code r }

(** Translation of expressions under an environment [env] *)
(* [code] is the code already generated in the context. *)
Expand Down
6 changes: 6 additions & 0 deletions src/global/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ let mapfold f acc l =
(* duplicate a value into a list *)
let rec list_of n v = if n = 0 then [] else v :: (list_of (n-1) v)

(* takes the first patterns of the list, except the last one *)
let rec firsts = function
| [] -> assert false
| [p] -> [], p
| p :: l -> let head, tail = firsts l in p :: head, tail

(* execute only *)
let continue_if_not b x f = if b then x else f x

0 comments on commit 30b0b2b

Please sign in to comment.