1
1
package org .enso .interpreter .runtime .state ;
2
2
3
- import org .enso .interpreter .node .expression .builtin .runtime .Context ;
4
- import org .enso .interpreter .runtime .EnsoContext ;
5
- import org .enso .interpreter .runtime .data .atom .Atom ;
6
-
7
3
public class ExecutionEnvironment {
8
4
9
5
private final String name ;
10
6
11
- // Ideally we would "just" use a map here. But that leads
12
- // to native image build problems. This in turn leads to
13
- // TruffleBoundary annotations which in turn leads to slow path.
14
- private final String [] keys ;
15
- private final Boolean [] permissions ;
7
+ final ContextPermissions permissions ;
16
8
17
9
public static final String LIVE_ENVIRONMENT_NAME = "live" ;
18
10
@@ -22,82 +14,25 @@ public class ExecutionEnvironment {
22
14
public static final ExecutionEnvironment DESIGN =
23
15
new ExecutionEnvironment (DESIGN_ENVIRONMENT_NAME );
24
16
25
- private static final ExecutionEnvironment initLive (String name ) {
26
- String [] keys = new String [] {Context .INPUT_NAME , Context .OUTPUT_NAME };
27
- Boolean [] permissions = new Boolean [] {true , true };
28
- return new ExecutionEnvironment (name , keys , permissions );
17
+ private static ExecutionEnvironment initLive (String name ) {
18
+ var permissions = new ContextPermissions (true , true , false );
19
+ return new ExecutionEnvironment (name , permissions );
29
20
}
30
21
31
22
public ExecutionEnvironment (String name ) {
32
23
this .name = name ;
33
- this .keys = new String [0 ];
34
- this .permissions = new Boolean [0 ];
24
+ this .permissions = new ContextPermissions (false , false , false );
35
25
}
36
26
37
- private ExecutionEnvironment (String name , String [] keys , Boolean [] permissions ) {
27
+ ExecutionEnvironment (String name , ContextPermissions permissions ) {
38
28
this .name = name ;
39
- this .keys = keys ;
40
29
this .permissions = permissions ;
41
30
}
42
31
43
32
public String getName () {
44
33
return this .name ;
45
34
}
46
35
47
- public ExecutionEnvironment withContextEnabled (Atom context ) {
48
- return update (context , true );
49
- }
50
-
51
- public ExecutionEnvironment withContextDisabled (Atom context ) {
52
- return update (context , false );
53
- }
54
-
55
- private ExecutionEnvironment update (Atom context , boolean value ) {
56
- assert context .getConstructor ().getType ()
57
- == EnsoContext .get (null ).getBuiltins ().context ().getType ();
58
- int keyFound = -1 ;
59
- for (int i = 0 ; i < keys .length ; i ++) {
60
- if (keys [i ].equals (context .getConstructor ().getName ())) {
61
- keyFound = i ;
62
- }
63
- }
64
- String [] keys1 ;
65
- Boolean [] permissions1 ;
66
- if (keyFound != -1 ) {
67
- keys1 = cloneArray (keys , new String [keys .length ]);
68
- permissions1 = cloneArray (permissions , new Boolean [keys .length ]);
69
- permissions1 [keyFound ] = value ;
70
- } else {
71
- keys1 = cloneArray (keys , new String [keys .length + 1 ]);
72
- permissions1 = cloneArray (permissions , new Boolean [keys .length + 1 ]);
73
- keyFound = keys .length ;
74
- keys1 [keyFound ] = context .getConstructor ().getName ();
75
- permissions1 [keyFound ] = value ;
76
- }
77
- return new ExecutionEnvironment (name , keys1 , permissions1 );
78
- }
79
-
80
- private <T > T [] cloneArray (T [] fromArray , T [] toArray ) {
81
- for (int i = 0 ; i < fromArray .length ; i ++) {
82
- toArray [i ] = fromArray [i ];
83
- }
84
- return toArray ;
85
- }
86
-
87
- public Boolean hasContextEnabled (String context ) {
88
- int keyFound = -1 ;
89
- for (int i = 0 ; i < keys .length ; i ++) {
90
- if (keys [i ].equals (context )) {
91
- keyFound = i ;
92
- }
93
- }
94
- if (keyFound != -1 ) {
95
- return permissions [keyFound ];
96
- } else {
97
- return false ;
98
- }
99
- }
100
-
101
36
public static ExecutionEnvironment forName (String name ) {
102
37
switch (name ) {
103
38
case LIVE_ENVIRONMENT_NAME :
0 commit comments