@@ -164,17 +164,17 @@ impl Compiler {
164164 kind, data, ..
165165 } = gene;
166166
167- match * kind. borrow ( ) {
167+ match * kind {
168168 Value :: Symbol ( ref s) if s == "var" => {
169169 let first;
170170 {
171171 first = data[ 0 ] . clone ( ) ;
172172 }
173173 let second;
174174 {
175- second = data[ 1 ] . borrow ( ) . clone ( ) ;
175+ second = data[ 1 ] . clone ( ) ;
176176 }
177- match * first. borrow_mut ( ) {
177+ match first {
178178 Value :: Symbol ( ref name) => {
179179 self . compile_ ( block, second. clone ( ) ) ;
180180 ( * block) . add_instr ( Instruction :: DefMember ( name. clone ( ) ) ) ;
@@ -183,15 +183,15 @@ impl Compiler {
183183 } ;
184184 }
185185 Value :: Symbol ( ref s) if s == "fn" => {
186- let name = data[ 0 ] . borrow ( ) . to_string ( ) ;
186+ let name = data[ 0 ] . to_string ( ) ;
187187
188188 let mut body = Block :: new ( name. clone ( ) ) ;
189189 let body_id = body. id . clone ( ) ;
190190
191191 self . reg_trackers . insert ( body_id. clone ( ) , Vec :: new ( ) ) ;
192192
193- let borrowed = data[ 1 ] . borrow ( ) ;
194- let matcher = Matcher :: from ( & * borrowed) ;
193+ let borrowed = data[ 1 ] ;
194+ let matcher = Matcher :: from ( & borrowed) ;
195195
196196 self . compile_statements ( & mut body, & data[ 2 ..] ) ;
197197 body. add_instr ( Instruction :: CallEnd ) ;
@@ -206,19 +206,19 @@ impl Compiler {
206206 self . compile_if ( block, data) ;
207207 }
208208 Value :: Symbol ( ref s) if s == "=" => {
209- let name = data[ 0 ] . borrow ( ) . to_string ( ) ;
210- let value = data[ 1 ] . borrow ( ) . clone ( ) ;
209+ let name = data[ 0 ] . to_string ( ) ;
210+ let value = data[ 1 ] . clone ( ) ;
211211 self . compile_ ( block, value) ;
212212 ( * block) . add_instr ( Instruction :: SetMember ( name) ) ;
213213 }
214214 Value :: Symbol ( ref s) if is_binary_op ( s) => {
215- let first = data[ 0 ] . borrow ( ) . clone ( ) ;
215+ let first = data[ 0 ] . clone ( ) ;
216216 self . compile_ ( block, first) ;
217217
218218 let first_reg = self . get_reg ( block) ;
219219 ( * block) . add_instr ( Instruction :: CopyFromDefault ( first_reg) ) ;
220220
221- let second = data[ 1 ] . borrow ( ) . clone ( ) ;
221+ let second = data[ 1 ] . clone ( ) ;
222222 self . compile_ ( block, second) ;
223223
224224 ( * block) . add_instr ( Instruction :: BinaryOp ( s. to_string ( ) , first_reg) ) ;
@@ -232,8 +232,7 @@ impl Compiler {
232232 }
233233 _ => {
234234 // Invocation
235- let borrowed_kind = kind. borrow ( ) . clone ( ) ;
236- self . compile_ ( block, borrowed_kind) ;
235+ self . compile_ ( block, * kind) ;
237236 let target_reg = self . get_reg ( block) ;
238237 ( * block) . add_instr ( Instruction :: CopyFromDefault ( target_reg) ) ;
239238
@@ -242,8 +241,7 @@ impl Compiler {
242241 let args_reg = self . get_reg ( block) ;
243242 ( * block) . add_instr ( Instruction :: CreateArguments ( args_reg) ) ;
244243 for ( i, item) in data. iter ( ) . enumerate ( ) {
245- let borrowed = item. borrow ( ) ;
246- self . compile_ ( block, ( * borrowed) . clone ( ) ) ;
244+ self . compile_ ( block, item. clone ( ) ) ;
247245 ( * block) . add_instr ( Instruction :: SetItem ( args_reg, i) ) ;
248246 }
249247
@@ -254,24 +252,23 @@ impl Compiler {
254252 } ;
255253 }
256254
257- fn compile_statements ( & mut self , block : & mut Block , stmts : & [ Rc < RefCell < Value > > ] ) {
255+ fn compile_statements ( & mut self , block : & mut Block , stmts : & [ Value ] ) {
258256 for item in stmts. iter ( ) . cloned ( ) {
259- let borrowed = item. borrow ( ) . clone ( ) ;
257+ let borrowed = item. clone ( ) ;
260258 self . compile_ ( block, borrowed) ;
261259 }
262260 }
263261
264- fn compile_if ( & mut self , block : & mut Block , mut data : Vec < Rc < RefCell < Value > > > ) {
262+ fn compile_if ( & mut self , block : & mut Block , mut data : Vec < Value > ) {
265263 let cond = data. remove ( 0 ) ;
266- let mut then_stmts = Vec :: < Rc < RefCell < Value > > > :: new ( ) ;
267- let mut else_stmts = Vec :: < Rc < RefCell < Value > > > :: new ( ) ;
264+ let mut then_stmts = Vec :: new ( ) ;
265+ let mut else_stmts = Vec :: new ( ) ;
268266 let mut is_else = false ;
269267 for item in data. iter ( ) {
270268 if is_else {
271269 else_stmts. push ( item. clone ( ) ) ;
272270 } else {
273- let borrowed_item = item. borrow ( ) ;
274- match * borrowed_item {
271+ match * item {
275272 Value :: Symbol ( ref s) if s == "then" => ( ) ,
276273 Value :: Symbol ( ref s) if s == "else" => {
277274 is_else = true ;
@@ -283,7 +280,7 @@ impl Compiler {
283280 }
284281 }
285282 }
286- self . compile_ ( block, cond. borrow ( ) . clone ( ) ) ;
283+ self . compile_ ( block, cond. clone ( ) ) ;
287284 let cond_jump_index = block. instructions . len ( ) ;
288285 ( * block) . add_instr ( Instruction :: Dummy ) ;
289286
@@ -300,18 +297,18 @@ impl Compiler {
300297 mem:: replace ( & mut ( * block) . instructions [ then_jump_index] , Instruction :: Jump ( end_index as i16 ) ) ;
301298 }
302299
303- fn compile_while ( & mut self , block : & mut Block , mut data : Vec < Rc < RefCell < Value > > > ) {
300+ fn compile_while ( & mut self , block : & mut Block , mut data : Vec < Value > ) {
304301 let start_index = block. instructions . len ( ) ;
305302
306303 ( * block) . add_instr ( Instruction :: LoopStart ) ;
307304
308305 let cond = data. remove ( 0 ) ;
309- self . compile_ ( block, cond. borrow ( ) . clone ( ) ) ;
306+ self . compile_ ( block, cond. clone ( ) ) ;
310307 let jump_index = block. instructions . len ( ) ;
311308 ( * block) . add_instr ( Instruction :: Dummy ) ;
312309
313310 for item in data. iter ( ) {
314- self . compile_ ( block, item. borrow ( ) . clone ( ) ) ;
311+ self . compile_ ( block, item. clone ( ) ) ;
315312 }
316313 ( * block) . add_instr ( Instruction :: Jump ( start_index as i16 ) ) ;
317314 ( * block) . add_instr ( Instruction :: LoopEnd ) ;
@@ -593,19 +590,18 @@ fn normalize(gene: Gene) -> Gene {
593590 if gene. data . is_empty ( ) {
594591 gene
595592 } else {
596- let borrowed = gene. data [ 0 ] . clone ( ) ;
597- let first = borrowed. borrow_mut ( ) ;
598- match * first {
593+ let first = gene. data [ 0 ] . clone ( ) ;
594+ match first {
599595 Value :: Symbol ( ref s) if is_binary_op ( s) || s == "=" => {
600596 let Gene {
601597 kind,
602598 mut data,
603599 props,
604600 } = gene;
605601 let new_kind = data. remove ( 0 ) ;
606- data. insert ( 0 , kind) ;
602+ data. insert ( 0 , * kind) ;
607603 Gene {
608- kind : new_kind,
604+ kind : Box :: new ( new_kind. clone ( ) ) ,
609605 props,
610606 data,
611607 }
0 commit comments