@@ -408,7 +408,7 @@ impl Frame {
408408 self . push_value ( iter_obj) ;
409409 Ok ( None )
410410 }
411- bytecode:: Instruction :: ForIter => {
411+ bytecode:: Instruction :: ForIter { target } => {
412412 // The top of stack contains the iterator, lets push it forward:
413413 let top_of_stack = self . last_value ( ) ;
414414 let next_obj = objiter:: get_next_object ( vm, & top_of_stack) ;
@@ -424,12 +424,7 @@ impl Frame {
424424 self . pop_value ( ) ;
425425
426426 // End of for loop
427- let end_label = if let Block :: Loop { start : _, end } = self . last_block ( ) {
428- * end
429- } else {
430- panic ! ( "Wrong block type" )
431- } ;
432- self . jump ( end_label) ;
427+ self . jump ( * target) ;
433428 Ok ( None )
434429 }
435430 Err ( next_error) => {
@@ -927,49 +922,18 @@ impl Frame {
927922 ) -> FrameResult {
928923 let a = self . pop_value ( ) ;
929924 let value = match op {
930- & bytecode:: UnaryOperator :: Minus => {
931- // TODO:
932- // self.invoke('__neg__'
933- match a. borrow ( ) . kind {
934- PyObjectKind :: Integer { value : ref value1 } => vm. ctx . new_int ( -value1) ,
935- PyObjectKind :: Float { value : ref value1 } => vm. ctx . new_float ( -* value1) ,
936- _ => panic ! ( "Not impl {:?}" , a) ,
937- }
938- }
925+ & bytecode:: UnaryOperator :: Minus => vm. call_method ( & a, "__neg__" , vec ! [ ] ) ?,
926+ & bytecode:: UnaryOperator :: Plus => vm. call_method ( & a, "__pos__" , vec ! [ ] ) ?,
927+ & bytecode:: UnaryOperator :: Invert => vm. call_method ( & a, "__invert__" , vec ! [ ] ) ?,
939928 & bytecode:: UnaryOperator :: Not => {
940929 let value = objbool:: boolval ( vm, a) ?;
941930 vm. ctx . new_bool ( !value)
942931 }
943- _ => panic ! ( "Not impl {:?}" , op) ,
944932 } ;
945933 self . push_value ( value) ;
946934 Ok ( None )
947935 }
948936
949- fn _eq ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
950- vm. call_method ( & a, "__eq__" , vec ! [ b] )
951- }
952-
953- fn _ne ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
954- vm. call_method ( & a, "__ne__" , vec ! [ b] )
955- }
956-
957- fn _lt ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
958- vm. call_method ( & a, "__lt__" , vec ! [ b] )
959- }
960-
961- fn _le ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
962- vm. call_method ( & a, "__le__" , vec ! [ b] )
963- }
964-
965- fn _gt ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
966- vm. call_method ( & a, "__gt__" , vec ! [ b] )
967- }
968-
969- fn _ge ( & mut self , vm : & mut VirtualMachine , a : PyObjectRef , b : PyObjectRef ) -> PyResult {
970- vm. call_method ( & a, "__ge__" , vec ! [ b] )
971- }
972-
973937 fn _id ( & self , a : PyObjectRef ) -> usize {
974938 a. get_id ( )
975939 }
@@ -1035,17 +999,17 @@ impl Frame {
1035999 let b = self . pop_value ( ) ;
10361000 let a = self . pop_value ( ) ;
10371001 let value = match op {
1038- & bytecode:: ComparisonOperator :: Equal => self . _eq ( vm , a, b) ,
1039- & bytecode:: ComparisonOperator :: NotEqual => self . _ne ( vm , a, b) ,
1040- & bytecode:: ComparisonOperator :: Less => self . _lt ( vm , a, b) ,
1041- & bytecode:: ComparisonOperator :: LessOrEqual => self . _le ( vm , a, b) ,
1042- & bytecode:: ComparisonOperator :: Greater => self . _gt ( vm , a, b) ,
1043- & bytecode:: ComparisonOperator :: GreaterOrEqual => self . _ge ( vm , a, b) ,
1044- & bytecode:: ComparisonOperator :: Is => Ok ( vm. ctx . new_bool ( self . _is ( a, b) ) ) ,
1045- & bytecode:: ComparisonOperator :: IsNot => self . _is_not ( vm, a, b) ,
1046- & bytecode:: ComparisonOperator :: In => self . _in ( vm, a, b) ,
1047- & bytecode:: ComparisonOperator :: NotIn => self . _not_in ( vm, a, b) ,
1048- } ? ;
1002+ & bytecode:: ComparisonOperator :: Equal => vm . _eq ( & a, b) ? ,
1003+ & bytecode:: ComparisonOperator :: NotEqual => vm . _ne ( & a, b) ? ,
1004+ & bytecode:: ComparisonOperator :: Less => vm . _lt ( & a, b) ? ,
1005+ & bytecode:: ComparisonOperator :: LessOrEqual => vm . _le ( & a, b) ? ,
1006+ & bytecode:: ComparisonOperator :: Greater => vm . _gt ( & a, b) ? ,
1007+ & bytecode:: ComparisonOperator :: GreaterOrEqual => vm . _ge ( & a, b) ? ,
1008+ & bytecode:: ComparisonOperator :: Is => vm. ctx . new_bool ( self . _is ( a, b) ) ,
1009+ & bytecode:: ComparisonOperator :: IsNot => self . _is_not ( vm, a, b) ? ,
1010+ & bytecode:: ComparisonOperator :: In => self . _in ( vm, a, b) ? ,
1011+ & bytecode:: ComparisonOperator :: NotIn => self . _not_in ( vm, a, b) ? ,
1012+ } ;
10491013
10501014 self . push_value ( value) ;
10511015 Ok ( None )
@@ -1105,10 +1069,6 @@ impl Frame {
11051069 self . blocks . pop ( )
11061070 }
11071071
1108- fn last_block ( & self ) -> & Block {
1109- self . blocks . last ( ) . unwrap ( )
1110- }
1111-
11121072 pub fn push_value ( & mut self , obj : PyObjectRef ) {
11131073 self . stack . push ( obj) ;
11141074 }
0 commit comments