Skip to content

Commit c7b64d1

Browse files
committed
[js] progress on deserializing P6opaque objects
1 parent 3bf0df3 commit c7b64d1

File tree

2 files changed

+88
-19
lines changed

2 files changed

+88
-19
lines changed

src/vm/js/nqp-runtime/reprs.js

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,22 @@ P6opaque.prototype.deserialize_repr_data = function(cursor, STable) {
102102

103103
var slots = [];
104104
var autovived = {};
105-
for (var i in this.name_to_index_mapping) {
106-
for (var j in this.name_to_index_mapping[i].slots) {
107-
var name = this.name_to_index_mapping[i].names[j];
108-
var slot = this.name_to_index_mapping[i].slots[j];
109-
slots[slot] = name;
110-
if (this.auto_viv_values[slot]) {
111-
if (!this.auto_viv_values[slot].type_object_) {
112-
console.log('autoviv', name, slot, this.auto_viv_values[slot]);
113-
throw "We currently only implement autoviv with type object values";
114-
}
115-
/* TODO autoviving things that aren't typeobjects */
116-
/* TODO we need to store attributes better */
117-
autovived[name] = this.auto_viv_values[slot];
118-
}
105+
if (this.auto_viv_values) {
106+
for (var i in this.name_to_index_mapping) {
107+
for (var j in this.name_to_index_mapping[i].slots) {
108+
var name = this.name_to_index_mapping[i].names[j];
109+
var slot = this.name_to_index_mapping[i].slots[j];
110+
slots[slot] = name;
111+
if (this.auto_viv_values[slot]) {
112+
if (!this.auto_viv_values[slot].type_object_) {
113+
console.log('autoviv', name, slot, this.auto_viv_values[slot]);
114+
throw "We currently only implement autoviv with type object values";
115+
}
116+
/* TODO autoviving things that aren't typeobjects */
117+
/* TODO we need to store attributes better */
118+
autovived[name] = this.auto_viv_values[slot];
119+
}
120+
}
119121
}
120122
}
121123

@@ -137,6 +139,62 @@ P6opaque.prototype.deserialize_repr_data = function(cursor, STable) {
137139
/* TODO make auto viv values work */
138140
};
139141

142+
P6opaque.prototype.serialize_repr_data = function(st, cursor) {
143+
var numAttrs = st.REPR.flattened_stables.length;
144+
cursor.varint(numAttrs);
145+
146+
STARTING_OFFSET = cursor.offset;
147+
148+
for (var i = 0; i < numAttrs; i++) {
149+
if (st.REPR.flattened_stables[i] == null) {
150+
cursor.varint(0);
151+
}
152+
else {
153+
cursor.varint(1);
154+
throw "NYI";
155+
cursor.STableRef(st.REPR.flattened_stables[i]);
156+
}
157+
}
158+
159+
cursor.varint(st.REPR.mi ? 1 : 0);
160+
161+
//TODO
162+
// if (st.REPR.auto_viv_values != null) {
163+
// cursor.varint(1);
164+
// for (var i = 0; i < numAttrs; i++)
165+
// cursor.ref(st.REPR.auto_viv_values[i]);
166+
// }
167+
// else {
168+
cursor.varint(0);
169+
// }
170+
171+
172+
173+
cursor.varint(st.REPR.unbox_int_slot);
174+
cursor.varint(st.REPR.unbox_str_slot);
175+
cursor.varint(st.REPR.unbox_str_slot);
176+
177+
// TODO: Unbox slots
178+
cursor.varint(0);
179+
180+
cursor.varint(this.name_to_index_mapping.length);
181+
for (var i = 0; i < this.name_to_index_mapping.length; i++) {
182+
cursor.ref(this.name_to_index_mapping[i].class_key);
183+
184+
var num_attrs = this.name_to_index_mapping[i].names.length;
185+
186+
cursor.varint(num_attrs);
187+
188+
for (var j = 0; j < num_attrs; j++) {
189+
cursor.str(this.name_to_index_mapping[i].names[j]);
190+
cursor.varint(this.name_to_index_mapping[i].slots[j]);
191+
}
192+
}
193+
194+
cursor.varint(this.positional_delegate_slot);
195+
cursor.varint(this.associative_delegate_slot);
196+
};
197+
140198
P6opaque.prototype.deserialize_finish = function(object, data) {
141199
var attrs = [];
142200

@@ -232,8 +290,8 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
232290
this.unbox_num_slot = -1;
233291
this.unbox_str_slot = -1;
234292

235-
this.posDelegateSlot = -1;
236-
this.assocDelegateSlot = -1;
293+
this.positional_delegate_slot = -1;
294+
this.associative_delegate_slot = -1;
237295

238296
var curAttr = 0;
239297
/*
@@ -254,7 +312,9 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
254312
* in the list to add to the layout. */
255313
var numAttrs = attrs.length;
256314
if (numAttrs > 0) {
257-
var indexes = new Hash();
315+
var names = [];
316+
var slots = [];
317+
258318
for (var j = 0; j < numAttrs; j++) {
259319
var attr = attrs[j].content;
260320

@@ -266,7 +326,9 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
266326
/* TODO */
267327
// if (attrType == Null)
268328
// attrType = tc.gc.KnowHOW;
269-
indexes[attr.name] = curAttr;
329+
330+
slots.push(curAttr);
331+
names.push(attr.name);
270332

271333
/* AttrInfo info = new AttrInfo();
272334
@@ -324,7 +386,7 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
324386
/*classHandles.add(type);
325387
attrIndexes.add(indexes);*/
326388
/* FIXME*/
327-
this.name_to_index_mapping.push({class_key: type, name_map: indexes});
389+
this.name_to_index_mapping.push({class_key: type, slots: slots, names: names});
328390
}
329391

330392
/* Multiple parents means it's multiple inheritance. */
@@ -386,6 +448,10 @@ KnowHOWAttribute.prototype.deserialize_finish = function(object, data) {
386448
object.__name = data.str();
387449
};
388450

451+
KnowHOWAttribute.prototype.serialize = function(data, object) {
452+
data.str(object.__name);
453+
};
454+
389455
KnowHOWAttribute.prototype.type_object_for = basic_type_object_for;
390456
KnowHOWAttribute.prototype.allocate = basic_allocate;
391457
KnowHOWAttribute.name = 'KnowHOWAttribute';

src/vm/js/nqp-runtime/serialization.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ SerializationWriter.prototype.serializeSTable = function(st) {
438438
writeInt(st.hllRole);
439439
*/
440440

441+
/* TODO - HLL owner */
442+
443+
this.stables_data.str(null);
441444
/* Location of REPR data. */
442445
this.stables.I32(this.stables_data.offset);
443446

0 commit comments

Comments
 (0)