Skip to content

Commit f26f401

Browse files
committed
process: new composition syntax, misc fixes
1 parent 3087d23 commit f26f401

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎src/parsing/lexer.mll‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ rule read_token = parse
8989
| "with" { WITH }
9090
| "reads" { READS }
9191
| "writes" { WRITES }
92-
| "Par" { PAR }
93-
| "Seq" { SEQ }
92+
(* | "Par" { PAR }
93+
| "Seq" { SEQ } *)
94+
| "{{" { LPARC }
95+
| "}}" { RPARC }
96+
| "[[" { LSEQC }
97+
| "]]" { RSEQC }
9498
(* | "((" {P_LPAREN}
9599
| "))" {P_RPAREN} *)
96100
| "!" { NOT }

‎src/parsing/parser.mly‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
%token <char> CHAR
3838

3939
%token LPAREN "(" RPAREN ")" LBRACE "{" RBRACE "}" LSQBRACE "[" RSQBRACE "]" LANGLE "<" RANGLE ">" (* ARROW "->" *)
40+
%token LPARC RPARC LSEQC RSEQC
4041
%token COMMA "," COLON ":" DCOLON "::" SEMICOLON ";" DOT "."
4142
%token ASSIGN "="
4243
%token IMPORT
@@ -50,7 +51,7 @@
5051
%token WRITES READS
5152
%token P_PROC_INIT
5253
// %token AWAIT EMIT WATCHING WHEN PAR "||"
53-
%token PAR SEQ
54+
// %token PAR SEQ
5455
%token P_INIT P_LOOP
5556
// %token P_LPAREN "((" P_RPAREN "))"
5657
%token WITH
@@ -152,8 +153,8 @@ let loop :=
152153
located(
153154
| ~ = statement ; ~ = pwhen ; <Statement>
154155
| ~ = located(UID) ; ~ = pwhen; <Run>
155-
| PAR ; cond = pwhen ; "{" ; children = separated_list(WITH,loop) ; "}" ; { PGroup {p_ty=Parallel; cond ; children} }
156-
| SEQ ; cond = pwhen ; "{" ; children = separated_list(WITH,loop) ; "}" ; { PGroup {p_ty=Sequence; cond ; children} }
156+
| LPARC ; children = separated_list(WITH,loop) ; RPARC ; cond = pwhen ; { PGroup {p_ty=Parallel; cond ; children} }
157+
| LSEQC ; children = separated_list(WITH,loop) ; RSEQC ; cond = pwhen ; { PGroup {p_ty=Sequence; cond ; children} }
157158
)
158159

159160
let pwhen == midrule(WHEN ; LPAREN ; ~= expression ; RPAREN; <>)?

‎src/passes/process/process.ml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module Pass = Pass.Make(struct
2020
let rec compute_tree closed (l,pi:loc * _ proc_init) : HirU.statement M.t =
2121
let closed = FieldSet.add pi.proc closed in (* no cycle *)
2222

23-
let* p = find_process_source (mk_locatable l pi.proc) pi.mloc procs (*fixme : grammar to allow :: syntax *) in
24-
let* p = M.throw_if_none Logging.(make_msg l @@ Fmt.str "process '%s' is unknown" pi.proc) p in
23+
let* p = find_process_source (mk_locatable l pi.proc) pi.mloc procs (*fixme : grammar to allow :: syntax *)
24+
>>= M.throw_if_none Logging.(make_msg l @@ Fmt.str "process '%s' is unknown" pi.proc) in
2525
let* tag = M.fresh_prefix p.p_name in
2626
let prefix = (Fmt.str "%s_%s_" tag) in
2727
let read_params,write_params = p.p_interface.p_shared_vars in
@@ -34,9 +34,11 @@ module Pass = Pass.Make(struct
3434
let* () = param_arg_mismatch "init" p.p_interface.p_params pi.params in
3535

3636

37+
(* correspondence between shared variables names (given, original) *)
3738
let rename_l = List.map2 (fun subx x -> (fst x.value,subx.value) )
3839
(pi.read @ pi.write)
3940
(fst p.p_interface.p_shared_vars @ snd p.p_interface.p_shared_vars) in
41+
(* if the id corresponds to a shared variable, replace it by the name of the provided variable *)
4042
let rename = fun id -> match List.assoc_opt id rename_l with Some v -> v | None -> id in
4143

4244
(* add process local (but persistant) vars *)
@@ -68,10 +70,9 @@ module Pass = Pass.Make(struct
6870
return (process_cond cond s)
6971

7072
| Run (id,cond) ->
71-
M.throw_if Logging.(make_msg l "not allowed to call Main process explicitely") (id.value = Constants.main_process) >>= fun () ->
72-
M.throw_if Logging.(make_msg l "not allowed to have recursive process") (FieldSet.mem id.value closed) >>= fun () ->
7373
let* pi = M.throw_if_none Logging.(make_msg l @@ Fmt.str "no proc init called '%s'" id.value)
7474
(List.find_opt (fun p -> p.value.id = id.value) p.p_body.proc_init) in
75+
M.throw_if Logging.(make_msg l "not allowed to have recursive process") (FieldSet.mem pi.value.proc closed) >>= fun () ->
7576
let read = List.map (fun (id:l_str) -> mk_locatable id.loc @@ prefix id.value) pi.value.read in
7677
let write = List.map (fun (id:l_str) -> mk_locatable id.loc @@ prefix id.value) pi.value.write in
7778
let params = List.map (AstU.rename_var prefix) pi.value.params in

0 commit comments

Comments
 (0)