@@ -27,6 +27,7 @@ enum JitValue {
2727 Float ( Value ) ,
2828 Bool ( Value ) ,
2929 None ,
30+ Null ,
3031 Tuple ( Vec < JitValue > ) ,
3132 FuncRef ( FuncRef ) ,
3233}
@@ -45,14 +46,14 @@ impl JitValue {
4546 JitValue :: Int ( _) => Some ( JitType :: Int ) ,
4647 JitValue :: Float ( _) => Some ( JitType :: Float ) ,
4748 JitValue :: Bool ( _) => Some ( JitType :: Bool ) ,
48- JitValue :: None | JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => None ,
49+ JitValue :: None | JitValue :: Null | JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => None ,
4950 }
5051 }
5152
5253 fn into_value ( self ) -> Option < Value > {
5354 match self {
5455 JitValue :: Int ( val) | JitValue :: Float ( val) | JitValue :: Bool ( val) => Some ( val) ,
55- JitValue :: None | JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => None ,
56+ JitValue :: None | JitValue :: Null | JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => None ,
5657 }
5758 }
5859}
@@ -139,7 +140,9 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
139140 }
140141 JitValue :: Bool ( val) => Ok ( val) ,
141142 JitValue :: None => Ok ( self . builder . ins ( ) . iconst ( types:: I8 , 0 ) ) ,
142- JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => Err ( JitCompileError :: NotSupported ) ,
143+ JitValue :: Null | JitValue :: Tuple ( _) | JitValue :: FuncRef ( _) => {
144+ Err ( JitCompileError :: NotSupported )
145+ }
143146 }
144147 }
145148
@@ -474,6 +477,36 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
474477 _ => Err ( JitCompileError :: BadBytecode ) ,
475478 }
476479 }
480+ Instruction :: CallWithSelf { nargs } => {
481+ let nargs = nargs. get ( arg) ;
482+
483+ let mut args = Vec :: new ( ) ;
484+ for _ in 0 ..nargs {
485+ let arg = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
486+ args. push ( arg. into_value ( ) . unwrap ( ) ) ;
487+ }
488+
489+ // Pop self_or_null (should be Null for JIT-compiled recursive calls)
490+ let self_or_null = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
491+ if !matches ! ( self_or_null, JitValue :: Null ) {
492+ return Err ( JitCompileError :: NotSupported ) ;
493+ }
494+
495+ match self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ? {
496+ JitValue :: FuncRef ( reference) => {
497+ let call = self . builder . ins ( ) . call ( reference, & args) ;
498+ let returns = self . builder . inst_results ( call) ;
499+ self . stack . push ( JitValue :: Int ( returns[ 0 ] ) ) ;
500+
501+ Ok ( ( ) )
502+ }
503+ _ => Err ( JitCompileError :: BadBytecode ) ,
504+ }
505+ }
506+ Instruction :: PushNull => {
507+ self . stack . push ( JitValue :: Null ) ;
508+ Ok ( ( ) )
509+ }
477510 Instruction :: CallIntrinsic1 { func } => {
478511 match func. get ( arg) {
479512 IntrinsicFunction1 :: UnaryPositive => {
0 commit comments