Skip to content

Commit 91720fe

Browse files
committed
Get P6int/P6num to take/keep bit size.
1 parent 8f912e2 commit 91720fe

File tree

2 files changed

+88
-12
lines changed

2 files changed

+88
-12
lines changed

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/P6int.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,25 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
1818
SixModelObject obj = new TypeObject();
1919
obj.st = st;
2020
st.WHAT = obj;
21+
22+
StorageSpec ss = new StorageSpec();
23+
ss.inlineable = StorageSpec.INLINED;
24+
ss.boxed_primitive = StorageSpec.BP_INT;
25+
ss.bits = 64;
26+
ss.can_box = StorageSpec.CAN_BOX_INT;
27+
st.REPRData = ss;
28+
2129
return st.WHAT;
2230
}
31+
32+
public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
33+
SixModelObject integerInfo = repr_info.at_key_boxed(tc, "integer");
34+
if (integerInfo != null) {
35+
SixModelObject bits = integerInfo.at_key_boxed(tc, "bits");
36+
if (bits != null)
37+
((StorageSpec)st.REPRData).bits = (short)bits.get_int(tc);
38+
}
39+
}
2340

2441
public SixModelObject allocate(ThreadContext tc, STable st) {
2542
P6intInstance obj = new P6intInstance();
@@ -28,12 +45,7 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
2845
}
2946

3047
public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
31-
StorageSpec ss = new StorageSpec();
32-
ss.inlineable = StorageSpec.INLINED;
33-
ss.boxed_primitive = StorageSpec.BP_INT;
34-
ss.bits = 64;
35-
ss.can_box = StorageSpec.CAN_BOX_INT;
36-
return ss;
48+
return (StorageSpec)st.REPRData;
3749
}
3850

3951
public void inlineStorage(ThreadContext tc, STable st, ClassWriter cw, String prefix) {
@@ -117,4 +129,30 @@ public void serialize_inlined(ThreadContext tc, STable st, SerializationWriter w
117129
throw new RuntimeException(e);
118130
}
119131
}
132+
133+
/**
134+
* REPR data serialization. Serializes the per-type representation data that
135+
* is attached to the supplied STable.
136+
*/
137+
public void serialize_repr_data(ThreadContext tc, STable st, SerializationWriter writer)
138+
{
139+
writer.writeInt(((StorageSpec)st.REPRData).bits);
140+
}
141+
142+
/**
143+
* REPR data deserialization. Deserializes the per-type representation data and
144+
* attaches it to the supplied STable.
145+
*/
146+
public void deserialize_repr_data(ThreadContext tc, STable st, SerializationReader reader)
147+
{
148+
StorageSpec ss = new StorageSpec();
149+
ss.inlineable = StorageSpec.INLINED;
150+
ss.boxed_primitive = StorageSpec.BP_INT;
151+
if (reader.version >= 7)
152+
ss.bits = (short)reader.readLong();
153+
else
154+
ss.bits = 64;
155+
ss.can_box = StorageSpec.CAN_BOX_INT;
156+
st.REPRData = ss;
157+
}
120158
}

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/P6num.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,25 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
1818
SixModelObject obj = new TypeObject();
1919
obj.st = st;
2020
st.WHAT = obj;
21+
22+
StorageSpec ss = new StorageSpec();
23+
ss.inlineable = StorageSpec.INLINED;
24+
ss.boxed_primitive = StorageSpec.BP_NUM;
25+
ss.bits = 64;
26+
ss.can_box = StorageSpec.CAN_BOX_NUM;
27+
st.REPRData = ss;
28+
2129
return st.WHAT;
2230
}
31+
32+
public void compose(ThreadContext tc, STable st, SixModelObject repr_info) {
33+
SixModelObject floatInfo = repr_info.at_key_boxed(tc, "float");
34+
if (floatInfo != null) {
35+
SixModelObject bits = floatInfo.at_key_boxed(tc, "bits");
36+
if (bits != null)
37+
((StorageSpec)st.REPRData).bits = (short)bits.get_int(tc);
38+
}
39+
}
2340

2441
public SixModelObject allocate(ThreadContext tc, STable st) {
2542
P6numInstance obj = new P6numInstance();
@@ -29,12 +46,7 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
2946
}
3047

3148
public StorageSpec get_storage_spec(ThreadContext tc, STable st) {
32-
StorageSpec ss = new StorageSpec();
33-
ss.inlineable = StorageSpec.INLINED;
34-
ss.boxed_primitive = StorageSpec.BP_NUM;
35-
ss.bits = 64;
36-
ss.can_box = StorageSpec.CAN_BOX_NUM;
37-
return ss;
49+
return (StorageSpec)st.REPRData;
3850
}
3951

4052
public void inlineStorage(ThreadContext tc, STable st, ClassWriter cw, String prefix) {
@@ -118,4 +130,30 @@ public void serialize_inlined(ThreadContext tc, STable st, SerializationWriter w
118130
throw new RuntimeException(e);
119131
}
120132
}
133+
134+
/**
135+
* REPR data serialization. Serializes the per-type representation data that
136+
* is attached to the supplied STable.
137+
*/
138+
public void serialize_repr_data(ThreadContext tc, STable st, SerializationWriter writer)
139+
{
140+
writer.writeInt(((StorageSpec)st.REPRData).bits);
141+
}
142+
143+
/**
144+
* REPR data deserialization. Deserializes the per-type representation data and
145+
* attaches it to the supplied STable.
146+
*/
147+
public void deserialize_repr_data(ThreadContext tc, STable st, SerializationReader reader)
148+
{
149+
StorageSpec ss = new StorageSpec();
150+
ss.inlineable = StorageSpec.INLINED;
151+
ss.boxed_primitive = StorageSpec.BP_NUM;
152+
if (reader.version >= 7)
153+
ss.bits = (short)reader.readLong();
154+
else
155+
ss.bits = 64;
156+
ss.can_box = StorageSpec.CAN_BOX_NUM;
157+
st.REPRData = ss;
158+
}
121159
}

0 commit comments

Comments
 (0)