Skip to content

Commit 54472ce

Browse files
committed
Remove errors in LSC
1 parent a925e14 commit 54472ce

File tree

5 files changed

+40
-106
lines changed

5 files changed

+40
-106
lines changed

src/expr.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ let rec sgen_expr_of_expr (e : expr) : sgen_expr =
165165
Clean (sgen_expr_of_expr g)
166166
(* exec *)
167167
| List [ Symbol k; g ] when equal_string k "exec" ->
168-
Exec (sgen_expr_of_expr g)
168+
Exec (false, sgen_expr_of_expr g)
169169
(* linear exec *)
170170
| List [ Symbol k; g ] when equal_string k "linexec" ->
171-
LinExec (sgen_expr_of_expr g)
171+
Exec (true, sgen_expr_of_expr g)
172172
(* linear exec *)
173173
| List [ Symbol k; g ] when equal_string k "eval" ->
174174
Eval (sgen_expr_of_expr g)

src/lsc_ast.ml

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ open Base
22
open Pretty
33
open Out_channel
44
open In_channel
5-
open Lsc_err
65

76
let ( let* ) x f = Result.bind x ~f
87

@@ -339,21 +338,6 @@ let fusion repl1 repl2 s1 s2 bans1 bans2 theta : star =
339338
; bans = List.map (nbans1 @ nbans2) ~f:(fmap_ban ~f:(subst theta))
340339
}
341340

342-
let apply_effect r theta : (unit, err_effect) Result.t =
343-
match (r, theta) with
344-
| Func ((Noisy, (_, "print")), _), [] -> Error (TooFewArgs "print")
345-
| Func ((Noisy, (_, "print")), _), _ :: _ :: _ -> Error (TooManyArgs "print")
346-
| Func ((Noisy, (_, "print")), _), [ (_, Func ((_, (Null, arg)), [])) ] ->
347-
String.strip ~drop:(fun x -> equal_char x '\"') arg |> output_string stdout;
348-
flush stdout;
349-
Ok ()
350-
| Func ((Noisy, (_, "print")), _), [ (_, arg) ] ->
351-
output_string stdout (string_of_ray arg);
352-
flush stdout;
353-
Ok ()
354-
| Func ((Noisy, (_, s)), _), _ -> Error (UnknownEffect s)
355-
| _ -> Ok ()
356-
357341
let pause () =
358342
flush stdout;
359343
let _ = input_line stdin in
@@ -384,9 +368,9 @@ let coherent_bans bans =
384368
(* interaction between one selected ray and one selected action *)
385369
let rec interaction ~showtrace ~queue repl1 repl2
386370
(selected_action, other_actions) (selected_ray, other_rays, bans) :
387-
(star list, err_effect) Result.t =
371+
star list =
388372
match selected_action.content with
389-
| [] -> Ok []
373+
| [] -> []
390374
| r' :: s' when not (is_polarised r') ->
391375
interaction ~showtrace ~queue:(r' :: queue) repl1 repl2
392376
({ content = s'; bans }, other_actions)
@@ -405,15 +389,14 @@ let rec interaction ~showtrace ~queue repl1 repl2
405389
(selected_ray, other_rays, bans)
406390
(* if there is an actual connection between rays *)
407391
| Some theta ->
408-
let* _ = apply_effect selected_ray theta in
409392
begin
410393
if showtrace then
411394
output_string stdout
412395
@@ Printf.sprintf "success with %s." (string_of_subst theta);
413396
if showtrace then pause ()
414397
end;
415398
(* action is consumed when execution is linear *)
416-
let* next =
399+
let next =
417400
interaction ~showtrace ~queue:(r' :: queue) repl1 repl2
418401
({ content = s'; bans }, other_actions)
419402
(selected_ray, other_rays, bans)
@@ -423,29 +406,29 @@ let rec interaction ~showtrace ~queue repl1 repl2
423406
fusion repl1 repl2 other_rays other_rays' bans selected_action.bans
424407
theta
425408
in
426-
let* res =
409+
let res =
427410
if coherent_bans after_fusion.bans then begin
428411
let _ =
429412
if showtrace then
430413
output_string stdout
431414
@@ Printf.sprintf " add star %s." (string_of_star after_fusion)
432415
in
433-
Ok (after_fusion :: next)
416+
after_fusion :: next
434417
end
435418
else begin
436419
if showtrace then
437420
output_string stdout
438421
@@ Printf.sprintf " result filtered out by constraint.";
439-
Ok next
422+
next
440423
end
441424
in
442425
if showtrace then pause ();
443426
ident_counter := !ident_counter + 2;
444-
Ok res )
427+
res )
445428

446429
(* search partner for a selected ray within a set of available actions *)
447430
let search_partners ~linear ~showtrace (selected_ray, other_rays, bans) actions
448-
: (star list * star list, err_effect) Result.t =
431+
: star list * star list =
449432
if showtrace then begin
450433
let str_ray = string_of_ray selected_ray in
451434
let str_rays = string_of_raylist other_rays in
@@ -455,29 +438,29 @@ let search_partners ~linear ~showtrace (selected_ray, other_rays, bans) actions
455438
end;
456439
let repl1 = replace_indices !ident_counter in
457440
let rec try_actions acc = function
458-
| [] -> Ok ([], acc)
441+
| [] -> ([], acc)
459442
| selected_action :: other_actions ->
460443
let repl2 = replace_indices (!ident_counter + 1) in
461-
let* res =
444+
let res =
462445
interaction ~showtrace ~queue:[] repl1 repl2
463446
(selected_action, other_actions)
464447
(selected_ray, other_rays, bans)
465448
in
466449
if (not @@ List.is_empty res) && linear then
467-
let* next, new_actions = try_actions acc other_actions in
468-
Ok (res @ next, new_actions)
450+
let next, new_actions = try_actions acc other_actions in
451+
(res @ next, new_actions)
469452
else
470-
let* next, new_actions =
453+
let next, new_actions =
471454
try_actions (selected_action :: acc) other_actions
472455
in
473-
Ok (res @ next, new_actions)
456+
(res @ next, new_actions)
474457
in
475458
try_actions [] actions
476459

477460
let rec select_ray ~linear ~showtrace ~queue actions other_states
478-
(selected_state, bans) : (star list option * star list, err_effect) Result.t =
461+
(selected_state, bans) : star list option * star list =
479462
match selected_state with
480-
| [] -> Ok (None, actions)
463+
| [] -> (None, actions)
481464
(* if unpolarized, no need to try, try other stars *)
482465
| r :: rs when not (is_polarised r) ->
483466
select_ray ~linear ~showtrace ~queue:(r :: queue) actions other_states
@@ -490,48 +473,45 @@ let rec select_ray ~linear ~showtrace ~queue actions other_states
490473
actions
491474
with
492475
(* interaction did nothing (no partner), try other rays *)
493-
| Ok ([], new_actions) ->
476+
| ([], new_actions) ->
494477
select_ray ~linear ~showtrace ~queue:(selected_ray :: queue) new_actions
495478
other_states (other_rays, bans)
496479
(* interaction returns a result, keep it for the next round *)
497-
| Ok (new_stars, new_actions) -> Ok (Some new_stars, new_actions)
498-
| Error e -> Error e )
480+
| (new_stars, new_actions) -> (Some new_stars, new_actions))
499481

500482
let rec select_star ~linear ~showtrace ~queue actions :
501-
star list -> (star list option * star list, err_effect) Result.t = function
502-
| [] -> Ok (None, actions)
483+
star list -> star list option * star list = function
484+
| [] -> (None, actions)
503485
(* select a state star and try finding a partner for each ray *)
504486
| selected_state :: other_states -> (
505487
match
506488
select_ray ~linear ~showtrace ~queue:[] actions other_states
507489
(selected_state.content, selected_state.bans)
508490
with
509491
(* no success with this star, try other stars *)
510-
| Ok (None, new_actions) ->
492+
| (None, new_actions) ->
511493
select_star ~linear ~showtrace new_actions
512494
~queue:(selected_state :: queue) other_states
513495
(* got new stars to add, construct the result for the next round *)
514-
| Ok (Some new_stars, new_actions) ->
515-
Ok (Some (List.rev queue @ other_states @ new_stars), new_actions)
516-
| Error e -> Error e )
496+
| (Some new_stars, new_actions) ->
497+
(Some (List.rev queue @ other_states @ new_stars), new_actions))
517498

518499
let string_of_cfg (actions, states) : string =
519500
Printf.sprintf ">> actions: %s\n>> states: %s\n"
520501
(string_of_constellation actions)
521502
(string_of_constellation states)
522503

523504
let exec ?(showtrace = false) ?(linear = false) mcs :
524-
(constellation, err_effect) Result.t =
505+
constellation =
525506
(* do a sequence of rounds with a single interaction on state per round *)
526507
let rec loop ((actions, states) as cfg) =
527508
if showtrace then begin
528509
output_string stdout @@ string_of_cfg cfg;
529510
pause ()
530511
end;
531512
match select_star ~linear ~showtrace ~queue:[] actions states with
532-
| Ok (None, _) -> Ok states (* no more possible interaction *)
533-
| Ok (Some res, new_actions) -> loop (new_actions, res)
534-
| Error e -> Error e
513+
| (None, _) -> states (* no more possible interaction *)
514+
| (Some res, new_actions) -> loop (new_actions, res)
535515
in
536516
let cfg = extract_intspace mcs in
537517
if showtrace then

src/lsc_err.ml

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/sgen_ast.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ open Base
22
open Lsc_ast
33

44
type err =
5-
| IllFormedChecker
65
| ReservedWord of string
76
| UnknownID of string
8-
| LscError of Lsc_err.err_effect
97

108
type ident = StellarRays.term
119

@@ -18,8 +16,7 @@ type ray_prefix = StellarRays.fmark * idfunc
1816
and sgen_expr =
1917
| Raw of marked_constellation
2018
| Id of ident
21-
| Exec of sgen_expr
22-
| LinExec of sgen_expr
19+
| Exec of bool * sgen_expr
2320
| Union of sgen_expr list
2421
| Subst of sgen_expr * substitution
2522
| Focus of sgen_expr

src/sgen_eval.ml

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
open Base
22
open Lsc_ast
3-
open Lsc_err
43
open Sgen_ast
54
open Out_channel
65

@@ -22,18 +21,15 @@ let rec map_sgen_expr env ~f : sgen_expr -> (sgen_expr, err) Result.t = function
2221
| None -> Error (UnknownID (string_of_ray x))
2322
| Some g -> map_sgen_expr env ~f g
2423
end
25-
| Exec e ->
24+
| Exec (b, e) ->
2625
let* map_e = map_sgen_expr env ~f e in
27-
Exec map_e |> Result.return
26+
Exec (b, map_e) |> Result.return
2827
| Kill e ->
2928
let* map_e = map_sgen_expr env ~f e in
3029
Kill map_e |> Result.return
3130
| Clean e ->
3231
let* map_e = map_sgen_expr env ~f e in
3332
Clean map_e |> Result.return
34-
| LinExec e ->
35-
let* map_e = map_sgen_expr env ~f e in
36-
LinExec map_e |> Result.return
3733
| Union es ->
3834
let* map_es = List.map ~f:(map_sgen_expr env ~f) es |> Result.all in
3935
Union map_es |> Result.return
@@ -68,18 +64,15 @@ let rec replace_id env (_from : ident) (_to : sgen_expr) e :
6864
match e with
6965
| Id x when is_reserved x -> Ok (Id x)
7066
| Id x when equal_ray x _from -> Ok _to
71-
| Exec e ->
67+
| Exec (b, e) ->
7268
let* g = replace_id env _from _to e in
73-
Exec g |> Result.return
69+
Exec (b, g) |> Result.return
7470
| Kill e ->
7571
let* g = replace_id env _from _to e in
7672
Kill g |> Result.return
7773
| Clean e ->
7874
let* g = replace_id env _from _to e in
7975
Clean g |> Result.return
80-
| LinExec e ->
81-
let* g = replace_id env _from _to e in
82-
LinExec g |> Result.return
8376
| Union es ->
8477
let* gs = List.map ~f:(replace_id env _from _to) es |> Result.all in
8578
Union gs |> Result.return
@@ -104,16 +97,15 @@ let subst_funcs env _from _to =
10497
map_sgen_expr env ~f:(subst_all_funcs [ (_from, _to) ])
10598

10699
let rec pp_err e : (string, err) Result.t =
100+
let red text = "\x1b[31m" ^ text ^ "\x1b[0m" in
107101
match e with
108-
| IllFormedChecker -> "Ill-formed checker.\n" |> Result.return
109102
| ReservedWord x ->
110103
Printf.sprintf "%s: identifier '%s' is reserved.\n"
111104
(red "ReservedWord Error") x
112105
|> Result.return
113106
| UnknownID x ->
114107
Printf.sprintf "%s: identifier '%s' not found.\n" (red "UnknownID Error") x
115108
|> Result.return
116-
| LscError e -> pp_err_effect e |> Result.return
117109

118110
and eval_sgen_expr ~notyping (env : env) :
119111
sgen_expr -> (marked_constellation, err) Result.t = function
@@ -131,20 +123,9 @@ and eval_sgen_expr ~notyping (env : env) :
131123
in
132124
let* mcs = Ok eval_es in
133125
Ok (List.concat mcs)
134-
| Exec e ->
135-
let* eval_e = eval_sgen_expr ~notyping env e in
136-
begin
137-
match exec ~linear:false ~showtrace:false eval_e with
138-
| Ok res -> Ok (unmark_all res)
139-
| Error e -> Error (LscError e)
140-
end
141-
| LinExec e ->
126+
| Exec (b, e) ->
142127
let* eval_e = eval_sgen_expr ~notyping env e in
143-
begin
144-
match exec ~linear:true ~showtrace:false eval_e with
145-
| Ok mcs -> Ok (unmark_all mcs)
146-
| Error e -> Error (LscError e)
147-
end
128+
Ok (exec ~linear:b ~showtrace:false eval_e |> unmark_all)
148129
| Focus e ->
149130
let* eval_e = eval_sgen_expr ~notyping env e in
150131
eval_e |> remove_mark_all |> focus |> Result.return
@@ -168,7 +149,7 @@ and eval_sgen_expr ~notyping (env : env) :
168149
acc |> remove_mark_all |> clean |> focus |> Result.return
169150
| _ ->
170151
let origin = acc |> remove_mark_all |> focus in
171-
eval_sgen_expr ~notyping env (Focus (Exec (Union [ x; Raw origin ]))) )
152+
eval_sgen_expr ~notyping env (Focus (Exec (false, Union [ x; Raw origin ]))) )
172153
in
173154
res |> Result.return
174155
| Subst (e, Extend pf) ->
@@ -244,14 +225,11 @@ let rec eval_decl ~typecheckonly ~notyping env :
244225
| Trace _ when typecheckonly -> Ok env
245226
| Trace e ->
246227
let* eval_e = eval_sgen_expr ~notyping env e in
247-
begin
248-
match exec ~showtrace:true eval_e with
249-
| Ok _ -> Ok env
250-
| Error e -> Error (LscError e)
251-
end
228+
let _ = exec ~showtrace:true eval_e in
229+
Ok env
252230
| Run _ when typecheckonly -> Ok env
253231
| Run e ->
254-
let _ = eval_sgen_expr ~notyping env (Exec e) in
232+
let _ = eval_sgen_expr ~notyping env (Exec (false, e)) in
255233
Ok env
256234
| Expect (_x, _mcs) -> Ok { objs = []; types = [] } (* TODO *)
257235
| Use path ->

0 commit comments

Comments
 (0)