1
1
package org .enso .interpreter .node .expression .builtin .resource ;
2
2
3
- import com .oracle .truffle .api .dsl .Specialization ;
4
3
import com .oracle .truffle .api .frame .VirtualFrame ;
5
4
import com .oracle .truffle .api .nodes .Node ;
6
5
import org .enso .interpreter .dsl .BuiltinMethod ;
12
11
13
12
@ BuiltinMethod (
14
13
type = "Managed_Resource" ,
15
- name = "with " ,
14
+ name = "with_builtin " ,
16
15
description =
17
16
"Applies the passed action to the underlying resource managed by the passed"
18
17
+ " Managed_Resource object." )
19
- public abstract class WithNode extends Node {
18
+ public final class WithNode extends Node {
19
+ private WithNode () {}
20
20
21
21
private @ Child InvokeCallableNode invokeCallableNode =
22
22
InvokeCallableNode .build (
@@ -25,24 +25,22 @@ public abstract class WithNode extends Node {
25
25
InvokeCallableNode .ArgumentsExecutionMode .PRE_EXECUTED );
26
26
27
27
static WithNode build () {
28
- return WithNodeGen . create ();
28
+ return new WithNode ();
29
29
}
30
30
31
- abstract Object execute (State state , VirtualFrame frame , Object self , Object action );
32
-
33
- @ Specialization
34
- Object doWith (State state , VirtualFrame frame , ManagedResource self , Object action ) {
31
+ Object execute (
32
+ State state , VirtualFrame frame , ManagedResource mr , Object action , Object onMissing ) {
35
33
var ctx = EnsoContext .get (this );
36
34
var resourceManager = ctx .getResourceManager ();
37
- if (self .getPhantomReference ().refersTo (self )) {
38
- resourceManager .park (self );
35
+ if (mr .getPhantomReference ().refersTo (mr )) {
36
+ resourceManager .park (mr );
39
37
try {
40
- return invokeCallableNode .execute (action , frame , state , new Object [] {self .getResource ()});
38
+ return invokeCallableNode .execute (action , frame , state , new Object [] {mr .getResource ()});
41
39
} finally {
42
- resourceManager .unpark (self );
40
+ resourceManager .unpark (mr );
43
41
}
44
42
} else {
45
- return ctx . getBuiltins (). nothing () ;
43
+ return onMissing ;
46
44
}
47
45
}
48
46
}
0 commit comments