Skip to content

Commit e5fec77

Browse files
authored
Merge pull request #105 from engboris/fix-exec
Remove sources of unpredictability in behaviour of execution
2 parents 7f978a7 + 8ad0967 commit e5fec77

File tree

12 files changed

+90
-55
lines changed

12 files changed

+90
-55
lines changed

examples/linear_lambda.sg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ end
2323

2424
adapter = -id(l:X) +x(X); -id(r:X) +y(X).
2525

26-
vehicle :: "a -o a".
26+
checker = galaxy
27+
interaction = #tested #test.
28+
expect = ok.
29+
end
30+
31+
vehicle :: "a -o a" [checker].
2732
vehicle = #id #adapter.

examples/mll.sg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ spec "a -o a" = galaxy
2222
@-7(X) ok.
2323
end
2424

25-
id :: "a -o a".
25+
checker = galaxy
26+
interaction = #tested #test.
27+
expect = ok.
28+
end
29+
30+
id :: "a -o a" [checker].
2631
id =
2732
-5(l:X) +1(X);
2833
-5(r:X) +2(X);

examples/syntax.sg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ show-exec (#1 #2)[#1=>+f(X) X][#2=>-f(a)].
6060

6161
'checkers & typechecking
6262
checker = galaxy
63-
interaction = #tested #test.
63+
interaction = (@#tested) #test.
6464
expect = ok.
6565
end
6666

exercises/solutions/01-paths.sg

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
'fill the 'your_answer' holes to replace #1 in the constellations
22
'below such that the result of execution is { ok }
33

4-
x :=: ok.
4+
x1 :=: ok.
5+
x1 = (@(-1 ok) #1)[#1=>+1].
56

6-
x = ((-1 ok) #1)[#1=>+1].
7+
x2 :=: ok.
8+
x2 = ((@-1; +2) #1)[#1=>+1 -2 ok].
79

8-
x = ((-1; +2) #1)[#1=>+1 -2 ok].
10+
x3 :=: ok.
11+
x3 = ((@-1 ok; -2 +3) #1)[#1=>+1 +2; -3].
912

10-
x = ((-1 ok; -2 +3) #1)[#1=>+1 +2; -3].
13+
x4 :=: ok.
14+
x4 = ((@-f(+g(X)) ok) #1)[#1=>+f(-g(X))].
1115

12-
x = ((-f(+g(X)) ok) #1)[#1=>+f(-g(X))].
13-
14-
x = ((+f(a) +f(b); +g(a); @+g(b) ok) #1)[#1=>-f(a); -f(b) -g(a) -g(b)].
16+
x5 :=: ok.
17+
x5 = ((+f(a) +f(b); +g(a); @+g(b) ok) #1)[#1=>-f(a); -f(b) -g(a) -g(b)].

exercises/solutions/04-boolean.sg

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'fill the #your_answer hole by following the specifications
22

3+
checker = galaxy
4+
interaction = #tested #test.
5+
expect = ok.
6+
end
7+
38
not_spec = galaxy
49
test0 = @-not(0 1) ok.
510
test1 = @-not(1 0) ok.
611
end
712

8-
not :: not_spec.
13+
not :: not_spec [checker].
914
not = +not(0 1); +not(1 0).
1015

1116
'how to print the truth table of NOT ?
@@ -19,10 +24,10 @@ and_spec = galaxy
1924
test11 = @-and(1 1 1) ok.
2025
end
2126

22-
and :: and_spec.
27+
and :: and_spec [checker].
2328
and = +and(0 0 0); +and(0 1 0); +and(1 0 0); +and(1 1 1).
2429

25-
and2 :: and_spec.
30+
and2 :: and_spec [checker].
2631
and2 = +and(0 X 0); +and(1 X X).
2732

2833
or_spec = galaxy
@@ -32,10 +37,10 @@ or_spec = galaxy
3237
test11 = @-or(1 1 1) ok.
3338
end
3439

35-
or :: or_spec.
40+
or :: or_spec [checker].
3641
or = +or(0 0 0); +or(0 1 1); +or(1 0 1); +or(1 1 1).
3742

38-
or2 :: or_spec.
43+
or2 :: or_spec [checker].
3944
or2 = +or(0 X X); +or(1 X 1).
4045

4146
impl_spec = galaxy
@@ -45,11 +50,11 @@ impl_spec = galaxy
4550
test11 = @-impl(1 1 1) ok.
4651
end
4752

48-
impl :: impl_spec.
49-
impl = #not #or @{-not(X Y) -or(Y Z R) +impl(X Z R)}.
53+
impl :: impl_spec [checker].
54+
impl = exec #not #or @{-not(X Y) -or(Y Z R) +impl(X Z R)} end.
5055

51-
impl2 :: impl_spec.
52-
impl2 = #not #or @{-not(X Y) -or(Y Z R) +impl(X Z R)}.
56+
impl2 :: impl_spec [checker].
57+
impl2 = exec #not #or @{-not(X Y) -or(Y Z R) +impl(X Z R)} end.
5358

5459
ex :=: +ex(1 1); +ex(0 1).
5560
ex = #not #or @{-not(X R1) -or(R1 X R2) +ex(X R2)}.

src/lsc/lsc_ast.ml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,19 @@ let cc_representatives from cs =
294294
in
295295
selection [] from cs
296296

297-
let extract_intspace (mcs : marked_constellation) =
298-
let rec sort (cs, space) = function
297+
let classify =
298+
let rec aux (cs, space) = function
299299
| [] -> (List.rev cs, List.rev space)
300-
| Marked s :: t -> sort (cs, s :: space) t
301-
| Unmarked s :: t -> sort (s :: cs, space) t
300+
| Marked s :: t -> aux (cs, s :: space) t
301+
| Unmarked s :: t -> aux (s :: cs, space) t
302302
in
303-
match sort ([], []) mcs with
304-
(* marks are selected for you in each connected component *)
305-
| unmarked, [] ->
306-
let cs, marked = cc_representatives [] unmarked in
307-
ident_counter := 0;
308-
(cs, marked)
309-
(* user selects marks *)
310-
| unmarked, marked ->
311-
ident_counter := 0;
312-
(unmarked, marked)
303+
aux ([], [])
304+
305+
let extract_intspace (mcs : marked_constellation) =
306+
(* auto-selection *)
307+
(* let cs, marked = cc_representatives [] unmarked in *)
308+
ident_counter := 0;
309+
classify mcs
313310

314311
(* ---------------------------------------
315312
Execution

src/stellogen/sgen_ast.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ type env =
5050
}
5151

5252
let expect (g : galaxy_expr) : galaxy_expr =
53-
Raw (Galaxy [ GLabelDef ("expect", g) ])
53+
Raw
54+
(Galaxy [ GLabelDef ("interaction", Id "tested"); GLabelDef ("expect", g) ])
5455

5556
let initial_env =
5657
{ objs = [ ("^empty", Raw (Const [])) ]

src/stellogen/sgen_eval.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ and eval_galaxy_expr ~notyping (env : env) :
207207
let* mcs = galaxy_to_constellation ~notyping env eval_e in
208208
begin
209209
match exec ~linear:false ~showtrace:false mcs with
210-
| Ok mcs -> Ok (Const (unmark_all mcs))
210+
| Ok res -> Ok (Const (unmark_all res))
211211
| Error e -> Error (LscError e)
212212
end
213213
| LinExec e ->
@@ -237,7 +237,8 @@ and eval_galaxy_expr ~notyping (env : env) :
237237
| _ ->
238238
let origin = acc |> remove_mark_all |> focus in
239239
let* ev =
240-
eval_galaxy_expr ~notyping env (Exec (Union (x, Raw (Const origin))))
240+
eval_galaxy_expr ~notyping env
241+
(Focus (Exec (Union (x, Raw (Const origin)))))
241242
in
242243
galaxy_to_constellation ~notyping env ev )
243244
in
@@ -332,7 +333,7 @@ and typecheck ~notyping env x t (ck : galaxy_expr) : (unit, err) Result.t =
332333
, Exec
333334
(Subst
334335
( Subst (format, SGal ("test", test))
335-
, SGal ("tested", Exec obj_x) ) )
336+
, SGal ("tested", obj_x) ) )
336337
|> eval_galaxy_expr ~notyping env )
337338
end
338339
| _ -> Error IllFormedChecker )
@@ -347,7 +348,7 @@ and typecheck ~notyping env x t (ck : galaxy_expr) : (unit, err) Result.t =
347348
| Error e -> Error e )
348349
|> Result.all_unit
349350

350-
and default_interaction = Union (Id "tested", Id "test")
351+
and default_interaction = Union (Focus (Id "tested"), Id "test")
351352

352353
and default_expect =
353354
Raw (Const [ Unmarked { content = [ func "ok" [] ]; bans = [] } ])

src/stellogen/sgen_parser.mly

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ open Sgen_ast
1616
%token EQ
1717
%token END
1818

19+
%left RARROW
20+
%nonassoc AT
21+
1922
%start <Sgen_ast.program> program
2023

2124
%%
@@ -62,21 +65,36 @@ let delimited_raw_galaxy :=
6265
| ~=braces(marked_constellation); <Const>
6366

6467
let galaxy_content :=
65-
| ~=pars(galaxy_content); <>
66-
| SHARP; ~=SYM; <Id>
67-
| ~=delimited_raw_galaxy; <Raw>
68-
| g=galaxy_content; h=galaxy_content; { Union (g, h) }
69-
| ~=galaxy_content; RARROW; ~=SYM; <Access>
70-
| AT; SHARP; x=SYM; { Focus (Id x) }
71-
| AT; g=delimited_raw_galaxy; { Focus (Raw g) }
72-
| ~=galaxy_content; ~=bracks(substitution); <Subst>
73-
| EXEC; EOL*; ~=galaxy_content; EOL*; END; EXEC?; <Exec>
74-
| LINEXEC; EOL*; ~=galaxy_content; EOL*; END; LINEXEC?; <LinExec>
68+
| ~=pars(galaxy_content); <>
69+
| SHARP; ~=SYM; <Id>
70+
| ~=delimited_raw_galaxy; <Raw>
71+
| g=galaxy_content; h=galaxy_content; { Union (g, h) }
72+
| ~=galaxy_access; <>
73+
| AT; ~=focussed_galaxy_content; <Focus>
74+
| ~=galaxy_content; ~=bracks(substitution); <Subst>
75+
| ~=galaxy_block; <>
76+
77+
let focussed_galaxy_content :=
78+
| ~=pars(galaxy_content); <>
79+
| ~=galaxy_access; <>
80+
| SHARP; ~=SYM; <Id>
81+
| ~=delimited_raw_galaxy; <Raw>
82+
| ~=galaxy_block; <>
83+
84+
let galaxy_block :=
85+
| EXEC; EOL*; ~=galaxy_content; EOL*; END; EXEC?;
86+
<Exec>
87+
| LINEXEC; EOL*; ~=galaxy_content; EOL*; END; LINEXEC?;
88+
<LinExec>
7589
| EXEC; EOL*; mcs=marked_constellation; EOL*; END; EXEC?;
7690
{ Exec (Raw (Const mcs)) }
7791
| LINEXEC; EOL*; mcs=marked_constellation; EOL*; END; LINEXEC?;
7892
{ LinExec (Raw (Const mcs)) }
7993

94+
let galaxy_access :=
95+
| SHARP; x=SYM; RARROW; y=SYM; { Access (Id x, y) }
96+
| ~=galaxy_access; RARROW; y=SYM; <Access>
97+
8098
let substitution :=
8199
| DRARROW; ~=symbol; <Extend>
82100
| ~=symbol; DRARROW; <Reduce>

test/behavior/galaxy.sg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ g = galaxy
99
end
1010

1111
x :=: 1.
12-
x = #g->test1.
12+
x = @#g->test1.
1313

1414
x :=: 2.
15-
x = #g->test2->test21.
15+
x = @#g->test2->test21.
1616

1717
x :=: 3.
18-
x = #g->test2->test22->test3.
18+
x = @#g->test2->test22->test3.

0 commit comments

Comments
 (0)