-
Notifications
You must be signed in to change notification settings - Fork 0
/
iExecutorImpl.java
89 lines (79 loc) · 2.86 KB
/
iExecutorImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.stmt.Statement;
public class iExecutorImpl implements iExecutor {
Scope current_scope;
public iExecutorImpl(Scope scope) {
current_scope = scope;
}
void log(Scope scope, Object x) {
scope.log("[exec] %s(%s)", x.getClass().getSimpleName(), x);
}
void log(Scope scope, Object x, Object v) {
scope.log("[exec2] %s(%s)=%s", x.getClass().getSimpleName(), x, v);
}
public iObject exec(MethodDeclaration x, iObject instance, iObject... args) {
Scope scope = current_scope.getChild(x);
iExecutor exec = scope.getExecutor();
try {
log(scope, x);
iObject v = iExecutorStatic.exec(scope, exec, x, instance, args);
log(scope, x, v);
return v;
} catch (Throwable t) {
throw throw_err(x, t);
}
}
public iObject exec(ConstructorDeclaration x, iObjectVirtual instance, iObject... args) {
Scope scope = current_scope.getChild(x);
iExecutor exec = scope.getExecutor();
try {
log(scope, x);
iObject v = iExecutorStatic.exec(scope, exec, x, instance, args);
log(scope, x, v);
return v;
} catch (Throwable t) {
throw throw_err(x, t);
}
}
public iObject exec(Statement x) {
Scope scope = current_scope.getChild(x);
iExecutor exec = scope.getExecutor();
try {
log(scope, x);
iObject v = iExecutorStatic.exec(scope, exec, x);
log(scope, x, v);
return v;
} catch (Throwable t) {
throw throw_err(x, t);
}
}
public iObject exec(Expression x) {
Scope scope = current_scope.getChild(x);
iExecutor exec = scope.getExecutor();
try {
log(scope, x);
iObject v = iExecutorStatic.exec(scope, exec, x);
log(scope, x, v);
return v;
} catch (Throwable t) {
throw throw_err(x, t);
}
}
public iObject exec(iExecutable x, iObject obj, iObject[] args) {
Scope scope = current_scope;// ????????
iExecutor exec = scope.getExecutor();
try {
log(scope, x);
iObject v = iExecutorStatic.exec(scope, exec, x, obj, args);
log(scope, x, v);
return v;
} catch (Throwable t) {
throw throw_err(x, t);
}
}
public static RuntimeException throw_err(Object x, Throwable t) {
return new RuntimeException("error while running " + x.getClass().getSimpleName() + " " + x, t);
}
}