Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/StructuredData.java @ 22496:b3569a53c24c
Refactor and improve ComplexNumber sequence tests
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Mon, 14 Dec 2015 14:20:08 +0100 |
parents | aeba89e1d8da |
children | ec40768d77a6 |
comparison
equal
deleted
inserted
replaced
22495:aeba89e1d8da | 22496:b3569a53c24c |
---|---|
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.tck; | 25 package com.oracle.truffle.tck; |
26 | 26 |
27 import java.util.Map; | |
28 | |
29 import com.oracle.truffle.api.CallTarget; | 27 import com.oracle.truffle.api.CallTarget; |
30 import com.oracle.truffle.api.Truffle; | 28 import com.oracle.truffle.api.Truffle; |
31 import com.oracle.truffle.api.frame.VirtualFrame; | 29 import com.oracle.truffle.api.frame.VirtualFrame; |
32 import com.oracle.truffle.api.interop.ForeignAccess; | 30 import com.oracle.truffle.api.interop.ForeignAccess; |
33 import com.oracle.truffle.api.interop.ForeignAccess.Factory; | 31 import com.oracle.truffle.api.interop.ForeignAccess.Factory; |
34 import com.oracle.truffle.api.interop.Message; | 32 import com.oracle.truffle.api.interop.Message; |
35 import com.oracle.truffle.api.interop.TruffleObject; | 33 import com.oracle.truffle.api.interop.TruffleObject; |
36 import com.oracle.truffle.api.nodes.RootNode; | 34 import com.oracle.truffle.api.nodes.RootNode; |
37 | 35 |
38 public final class StructuredData implements TruffleObject { | 36 final class StructuredData implements TruffleObject { |
39 | 37 |
40 private final byte[] buffer; | 38 private final byte[] buffer; |
41 private final Schema schema; | 39 private final Schema schema; |
42 | 40 |
43 public StructuredData(byte[] buffer, Schema schema) { | 41 StructuredData(byte[] buffer, Schema schema) { |
44 this.buffer = buffer; | 42 this.buffer = buffer; |
45 this.schema = schema; | 43 this.schema = schema; |
46 } | |
47 | |
48 public Map<String, Object> getEntry(int index) { | |
49 return schema.getEntry(buffer, index); | |
50 } | 44 } |
51 | 45 |
52 public ForeignAccess getForeignAccess() { | 46 public ForeignAccess getForeignAccess() { |
53 return ForeignAccess.create(new StructuredDataForeignAccessFactory()); | 47 return ForeignAccess.create(new StructuredDataForeignAccessFactory()); |
54 } | 48 } |
86 | 80 |
87 @Override | 81 @Override |
88 public Object execute(VirtualFrame frame) { | 82 public Object execute(VirtualFrame frame) { |
89 StructuredData data = (StructuredData) ForeignAccess.getReceiver(frame); | 83 StructuredData data = (StructuredData) ForeignAccess.getReceiver(frame); |
90 Number index = (Number) ForeignAccess.getArguments(frame).get(0); | 84 Number index = (Number) ForeignAccess.getArguments(frame).get(0); |
91 return new MapTruffleObject(data.getEntry(index.intValue())); | 85 return new StructuredDataEntry(data.buffer, data.schema, index.intValue()); |
92 } | 86 } |
93 | 87 |
94 } | 88 } |
95 | 89 |
96 private static class StructuredDataSizeNode extends RootNode { | 90 private static class StructuredDataSizeNode extends RootNode { |