@@ -8,7 +8,10 @@ use wtf8::Wtf8Buf;
88
99use crate :: {
1010 ecmascript:: {
11- builtins:: regexp:: { RegExp , reg_exp_create_literal} ,
11+ builtins:: {
12+ ordinary:: shape:: ObjectShape ,
13+ regexp:: { RegExp , reg_exp_create_literal} ,
14+ } ,
1215 execution:: Agent ,
1316 types:: { BigInt , IntoValue , Number , PropertyKey , String , Value } ,
1417 } ,
@@ -35,6 +38,8 @@ pub(super) struct ExecutableContext<'agent, 'gc, 'scope> {
3538 instructions : Vec < u8 > ,
3639 /// Constants being built
3740 constants : Vec < Value < ' gc > > ,
41+ /// Object Shapes being built
42+ shapes : Vec < ObjectShape < ' gc > > ,
3843 /// Function expressions being built
3944 function_expressions : Vec < FunctionExpression < ' gc > > ,
4045 /// Arrow function expressions being built
@@ -50,6 +55,7 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
5055 current_instruction_pointer_is_unreachable : false ,
5156 instructions : Vec :: new ( ) ,
5257 constants : Vec :: new ( ) ,
58+ shapes : Vec :: new ( ) ,
5359 function_expressions : Vec :: new ( ) ,
5460 arrow_function_expressions : Vec :: new ( ) ,
5561 class_initializer_bytecodes : Vec :: new ( ) ,
@@ -114,6 +120,7 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
114120 self . agent . heap . create ( ExecutableHeapData {
115121 instructions : self . instructions . into_boxed_slice ( ) ,
116122 constants : self . constants . unbind ( ) . into_boxed_slice ( ) ,
123+ shapes : self . shapes . unbind ( ) . into_boxed_slice ( ) ,
117124 function_expressions : self . function_expressions . unbind ( ) . into_boxed_slice ( ) ,
118125 arrow_function_expressions : self . arrow_function_expressions . into_boxed_slice ( ) ,
119126 class_initializer_bytecodes : self
@@ -189,6 +196,21 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
189196 } )
190197 }
191198
199+ pub ( super ) fn add_shape ( & mut self , shape : ObjectShape < ' gc > ) -> usize {
200+ let duplicate = self
201+ . shapes
202+ . iter ( )
203+ . enumerate ( )
204+ . find ( |item| item. 1 . eq ( & shape) )
205+ . map ( |( idx, _) | idx) ;
206+
207+ duplicate. unwrap_or_else ( || {
208+ let index = self . shapes . len ( ) ;
209+ self . shapes . push ( shape) ;
210+ index
211+ } )
212+ }
213+
192214 pub ( super ) fn add_instruction_with_immediate (
193215 & mut self ,
194216 instruction : Instruction ,
@@ -299,6 +321,18 @@ impl<'agent, 'gc, 'scope> ExecutableContext<'agent, 'gc, 'scope> {
299321 index as IndexType
300322 }
301323
324+ pub ( super ) fn add_instruction_with_shape (
325+ & mut self ,
326+ instruction : Instruction ,
327+ shape : ObjectShape < ' gc > ,
328+ ) {
329+ debug_assert_eq ! ( instruction. argument_count( ) , 1 ) ;
330+ debug_assert ! ( instruction. has_shape_index( ) ) ;
331+ self . push_instruction ( instruction) ;
332+ let shape = self . add_shape ( shape) ;
333+ self . add_index ( shape) ;
334+ }
335+
302336 pub ( super ) fn add_arrow_function_expression (
303337 & mut self ,
304338 arrow_function_expression : ArrowFunctionExpression ,
0 commit comments