@@ -102,20 +102,22 @@ P6opaque.prototype.deserialize_repr_data = function(cursor, STable) {
102
102
103
103
var slots = [ ] ;
104
104
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
+ }
119
121
}
120
122
}
121
123
@@ -137,6 +139,62 @@ P6opaque.prototype.deserialize_repr_data = function(cursor, STable) {
137
139
/* TODO make auto viv values work */
138
140
} ;
139
141
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
+
140
198
P6opaque . prototype . deserialize_finish = function ( object , data ) {
141
199
var attrs = [ ] ;
142
200
@@ -232,8 +290,8 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
232
290
this . unbox_num_slot = - 1 ;
233
291
this . unbox_str_slot = - 1 ;
234
292
235
- this . posDelegateSlot = - 1 ;
236
- this . assocDelegateSlot = - 1 ;
293
+ this . positional_delegate_slot = - 1 ;
294
+ this . associative_delegate_slot = - 1 ;
237
295
238
296
var curAttr = 0 ;
239
297
/*
@@ -254,7 +312,9 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
254
312
* in the list to add to the layout. */
255
313
var numAttrs = attrs . length ;
256
314
if ( numAttrs > 0 ) {
257
- var indexes = new Hash ( ) ;
315
+ var names = [ ] ;
316
+ var slots = [ ] ;
317
+
258
318
for ( var j = 0 ; j < numAttrs ; j ++ ) {
259
319
var attr = attrs [ j ] . content ;
260
320
@@ -266,7 +326,9 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
266
326
/* TODO */
267
327
// if (attrType == Null)
268
328
// attrType = tc.gc.KnowHOW;
269
- indexes [ attr . name ] = curAttr ;
329
+
330
+ slots . push ( curAttr ) ;
331
+ names . push ( attr . name ) ;
270
332
271
333
/* AttrInfo info = new AttrInfo();
272
334
@@ -324,7 +386,7 @@ P6opaque.prototype.compose = function(STable, repr_info_hash) {
324
386
/*classHandles.add(type);
325
387
attrIndexes.add(indexes);*/
326
388
/* 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 } ) ;
328
390
}
329
391
330
392
/* Multiple parents means it's multiple inheritance. */
@@ -386,6 +448,10 @@ KnowHOWAttribute.prototype.deserialize_finish = function(object, data) {
386
448
object . __name = data . str ( ) ;
387
449
} ;
388
450
451
+ KnowHOWAttribute . prototype . serialize = function ( data , object ) {
452
+ data . str ( object . __name ) ;
453
+ } ;
454
+
389
455
KnowHOWAttribute . prototype . type_object_for = basic_type_object_for ;
390
456
KnowHOWAttribute . prototype . allocate = basic_allocate ;
391
457
KnowHOWAttribute . name = 'KnowHOWAttribute' ;
0 commit comments