-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZListLiteralNode.java
39 lines (30 loc) · 927 Bytes
/
ZListLiteralNode.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
package de.lucaswerkmeister.graaleneyj.nodes;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import de.lucaswerkmeister.graaleneyj.runtime.ZList;
public class ZListLiteralNode extends ZNode {
@Children
private final ZNode[] nodes;
public ZListLiteralNode(ZNode[] nodes) {
this.nodes = nodes;
}
@Override
@ExplodeLoop
public ZList executeZList(VirtualFrame virtualFrame) {
CompilerAsserts.partialEvaluationConstant(nodes.length);
Object[] values = new Object[nodes.length];
for (int i = 0; i < nodes.length; i++) {
values[i] = nodes[i].execute(virtualFrame);
}
ZList list = ZList.NIL;
for (int i = nodes.length - 1; i >= 0; i--) {
list = new ZList(values[i], list);
}
return list;
}
@Override
public Object execute(VirtualFrame virtualFrame) {
return executeZList(virtualFrame);
}
}