@@ -26,6 +26,7 @@ enum JitValue {
2626 Float ( Value ) ,
2727 Bool ( Value ) ,
2828 None ,
29+ Tuple ( Vec < JitValue > ) ,
2930}
3031
3132impl JitValue {
@@ -42,14 +43,14 @@ impl JitValue {
4243 JitValue :: Int ( _) => Some ( JitType :: Int ) ,
4344 JitValue :: Float ( _) => Some ( JitType :: Float ) ,
4445 JitValue :: Bool ( _) => Some ( JitType :: Bool ) ,
45- JitValue :: None => None ,
46+ JitValue :: None | JitValue :: Tuple ( _ ) => None ,
4647 }
4748 }
4849
4950 fn into_value ( self ) -> Option < Value > {
5051 match self {
5152 JitValue :: Int ( val) | JitValue :: Float ( val) | JitValue :: Bool ( val) => Some ( val) ,
52- JitValue :: None => None ,
53+ JitValue :: None | JitValue :: Tuple ( _ ) => None ,
5354 }
5455 }
5556}
@@ -88,6 +89,11 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
8889 compiler
8990 }
9091
92+ fn pop_multiple ( & mut self , count : usize ) -> Vec < JitValue > {
93+ let stack_len = self . stack . len ( ) ;
94+ self . stack . drain ( stack_len - count..) . collect ( )
95+ }
96+
9197 fn store_variable (
9298 & mut self ,
9399 idx : bytecode:: NameIdx ,
@@ -126,6 +132,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
126132 }
127133 JitValue :: Bool ( val) => Ok ( val) ,
128134 JitValue :: None => Ok ( self . builder . ins ( ) . iconst ( types:: I8 , 0 ) ) ,
135+ JitValue :: Tuple ( _) => Err ( JitCompileError :: NotSupported ) ,
129136 }
130137 }
131138
@@ -260,6 +267,26 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
260267 Instruction :: LoadConst { idx } => {
261268 self . load_const ( constants[ * idx as usize ] . borrow_constant ( ) )
262269 }
270+ Instruction :: BuildTuple { unpack, size } if !unpack => {
271+ let elements = self . pop_multiple ( * size as usize ) ;
272+ self . stack . push ( JitValue :: Tuple ( elements) ) ;
273+ Ok ( ( ) )
274+ }
275+ Instruction :: UnpackSequence { size } => {
276+ let val = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
277+
278+ let elements = match val {
279+ JitValue :: Tuple ( elements) => elements,
280+ _ => return Err ( JitCompileError :: NotSupported ) ,
281+ } ;
282+
283+ if elements. len ( ) != * size as usize {
284+ return Err ( JitCompileError :: NotSupported ) ;
285+ }
286+
287+ self . stack . extend ( elements. into_iter ( ) . rev ( ) ) ;
288+ Ok ( ( ) )
289+ }
263290 Instruction :: ReturnValue => {
264291 let val = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
265292 if let Some ( ref ty) = self . sig . ret {
0 commit comments