@@ -108,26 +108,34 @@ impl Interpreter<'_> {
108108 pub fn run ( & mut self ) {
109109 while let Some ( instr) = self . bc . code . get ( self . program_counter ) {
110110 match instr {
111- // ix if let Some(&(dest, src)) = ix.get_unary() => {}
111+ ix if let Some ( & ( dest, src) ) = ix. get_unary ( ) => {
112+ let src = self . registers . get ( src) ;
113+ let val = match ix. opcode {
114+ OpCode :: Record => todo ! ( ) ,
115+ OpCode :: Negation => Value :: Float ( !src. to_bool ( ) as usize as f64 ) ,
116+ OpCode :: ToInt => Value :: Float ( src. to_num ( ) ) ,
117+ OpCode :: Negative => Value :: Float ( -src. to_num ( ) ) ,
118+ _ => unreachable ! ( ) ,
119+ } ;
120+ self . registers . write ( dest, val) ;
121+ }
112122 ix if let Some ( & ( dest, lhs, rhs) ) = ix. get_binary ( ) => {
113- let val = {
114- let lhs = self . registers . get ( lhs) ;
115- let rhs = self . registers . get ( rhs) ;
116- match ix. opcode {
117- OpCode :: Add => lhs + rhs,
118- OpCode :: Subtract => lhs - rhs,
119- OpCode :: Multiply => lhs * rhs,
120- OpCode :: Divide => lhs / rhs,
121- OpCode :: Concat => {
122- let mut buf = StdVec :: with_capacity (
123- lhs. string_size_hint ( ) + rhs. string_size_hint ( ) ,
124- ) ;
125- lhs. write_string ( & mut buf) ;
126- rhs. write_string ( & mut buf) ;
127- Value :: String ( buf. into ( ) )
128- }
129- _ => todo ! ( ) ,
123+ let lhs = self . registers . get ( lhs) ;
124+ let rhs = self . registers . get ( rhs) ;
125+ let val = match ix. opcode {
126+ OpCode :: Add => lhs + rhs,
127+ OpCode :: Subtract => lhs - rhs,
128+ OpCode :: Multiply => lhs * rhs,
129+ OpCode :: Divide => lhs / rhs,
130+ OpCode :: Concat => {
131+ let mut buf = StdVec :: with_capacity (
132+ lhs. string_size_hint ( ) + rhs. string_size_hint ( ) ,
133+ ) ;
134+ lhs. write_string ( & mut buf) ;
135+ rhs. write_string ( & mut buf) ;
136+ Value :: String ( buf. into ( ) )
130137 }
138+ _ => todo ! ( ) ,
131139 } ;
132140 self . registers . write ( dest, val) ;
133141 }
0 commit comments