@@ -164,17 +164,17 @@ impl Compiler {
164
164
kind, data, ..
165
165
} = gene;
166
166
167
- match * kind. borrow ( ) {
167
+ match * kind {
168
168
Value :: Symbol ( ref s) if s == "var" => {
169
169
let first;
170
170
{
171
171
first = data[ 0 ] . clone ( ) ;
172
172
}
173
173
let second;
174
174
{
175
- second = data[ 1 ] . borrow ( ) . clone ( ) ;
175
+ second = data[ 1 ] . clone ( ) ;
176
176
}
177
- match * first. borrow_mut ( ) {
177
+ match first {
178
178
Value :: Symbol ( ref name) => {
179
179
self . compile_ ( block, second. clone ( ) ) ;
180
180
( * block) . add_instr ( Instruction :: DefMember ( name. clone ( ) ) ) ;
@@ -183,15 +183,15 @@ impl Compiler {
183
183
} ;
184
184
}
185
185
Value :: Symbol ( ref s) if s == "fn" => {
186
- let name = data[ 0 ] . borrow ( ) . to_string ( ) ;
186
+ let name = data[ 0 ] . to_string ( ) ;
187
187
188
188
let mut body = Block :: new ( name. clone ( ) ) ;
189
189
let body_id = body. id . clone ( ) ;
190
190
191
191
self . reg_trackers . insert ( body_id. clone ( ) , Vec :: new ( ) ) ;
192
192
193
- let borrowed = data[ 1 ] . borrow ( ) ;
194
- let matcher = Matcher :: from ( & * borrowed) ;
193
+ let borrowed = data[ 1 ] ;
194
+ let matcher = Matcher :: from ( & borrowed) ;
195
195
196
196
self . compile_statements ( & mut body, & data[ 2 ..] ) ;
197
197
body. add_instr ( Instruction :: CallEnd ) ;
@@ -206,19 +206,19 @@ impl Compiler {
206
206
self . compile_if ( block, data) ;
207
207
}
208
208
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 ( ) ;
211
211
self . compile_ ( block, value) ;
212
212
( * block) . add_instr ( Instruction :: SetMember ( name) ) ;
213
213
}
214
214
Value :: Symbol ( ref s) if is_binary_op ( s) => {
215
- let first = data[ 0 ] . borrow ( ) . clone ( ) ;
215
+ let first = data[ 0 ] . clone ( ) ;
216
216
self . compile_ ( block, first) ;
217
217
218
218
let first_reg = self . get_reg ( block) ;
219
219
( * block) . add_instr ( Instruction :: CopyFromDefault ( first_reg) ) ;
220
220
221
- let second = data[ 1 ] . borrow ( ) . clone ( ) ;
221
+ let second = data[ 1 ] . clone ( ) ;
222
222
self . compile_ ( block, second) ;
223
223
224
224
( * block) . add_instr ( Instruction :: BinaryOp ( s. to_string ( ) , first_reg) ) ;
@@ -232,8 +232,7 @@ impl Compiler {
232
232
}
233
233
_ => {
234
234
// Invocation
235
- let borrowed_kind = kind. borrow ( ) . clone ( ) ;
236
- self . compile_ ( block, borrowed_kind) ;
235
+ self . compile_ ( block, * kind) ;
237
236
let target_reg = self . get_reg ( block) ;
238
237
( * block) . add_instr ( Instruction :: CopyFromDefault ( target_reg) ) ;
239
238
@@ -242,8 +241,7 @@ impl Compiler {
242
241
let args_reg = self . get_reg ( block) ;
243
242
( * block) . add_instr ( Instruction :: CreateArguments ( args_reg) ) ;
244
243
for ( i, item) in data. iter ( ) . enumerate ( ) {
245
- let borrowed = item. borrow ( ) ;
246
- self . compile_ ( block, ( * borrowed) . clone ( ) ) ;
244
+ self . compile_ ( block, item. clone ( ) ) ;
247
245
( * block) . add_instr ( Instruction :: SetItem ( args_reg, i) ) ;
248
246
}
249
247
@@ -254,24 +252,23 @@ impl Compiler {
254
252
} ;
255
253
}
256
254
257
- fn compile_statements ( & mut self , block : & mut Block , stmts : & [ Rc < RefCell < Value > > ] ) {
255
+ fn compile_statements ( & mut self , block : & mut Block , stmts : & [ Value ] ) {
258
256
for item in stmts. iter ( ) . cloned ( ) {
259
- let borrowed = item. borrow ( ) . clone ( ) ;
257
+ let borrowed = item. clone ( ) ;
260
258
self . compile_ ( block, borrowed) ;
261
259
}
262
260
}
263
261
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 > ) {
265
263
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 ( ) ;
268
266
let mut is_else = false ;
269
267
for item in data. iter ( ) {
270
268
if is_else {
271
269
else_stmts. push ( item. clone ( ) ) ;
272
270
} else {
273
- let borrowed_item = item. borrow ( ) ;
274
- match * borrowed_item {
271
+ match * item {
275
272
Value :: Symbol ( ref s) if s == "then" => ( ) ,
276
273
Value :: Symbol ( ref s) if s == "else" => {
277
274
is_else = true ;
@@ -283,7 +280,7 @@ impl Compiler {
283
280
}
284
281
}
285
282
}
286
- self . compile_ ( block, cond. borrow ( ) . clone ( ) ) ;
283
+ self . compile_ ( block, cond. clone ( ) ) ;
287
284
let cond_jump_index = block. instructions . len ( ) ;
288
285
( * block) . add_instr ( Instruction :: Dummy ) ;
289
286
@@ -300,18 +297,18 @@ impl Compiler {
300
297
mem:: replace ( & mut ( * block) . instructions [ then_jump_index] , Instruction :: Jump ( end_index as i16 ) ) ;
301
298
}
302
299
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 > ) {
304
301
let start_index = block. instructions . len ( ) ;
305
302
306
303
( * block) . add_instr ( Instruction :: LoopStart ) ;
307
304
308
305
let cond = data. remove ( 0 ) ;
309
- self . compile_ ( block, cond. borrow ( ) . clone ( ) ) ;
306
+ self . compile_ ( block, cond. clone ( ) ) ;
310
307
let jump_index = block. instructions . len ( ) ;
311
308
( * block) . add_instr ( Instruction :: Dummy ) ;
312
309
313
310
for item in data. iter ( ) {
314
- self . compile_ ( block, item. borrow ( ) . clone ( ) ) ;
311
+ self . compile_ ( block, item. clone ( ) ) ;
315
312
}
316
313
( * block) . add_instr ( Instruction :: Jump ( start_index as i16 ) ) ;
317
314
( * block) . add_instr ( Instruction :: LoopEnd ) ;
@@ -593,19 +590,18 @@ fn normalize(gene: Gene) -> Gene {
593
590
if gene. data . is_empty ( ) {
594
591
gene
595
592
} 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 {
599
595
Value :: Symbol ( ref s) if is_binary_op ( s) || s == "=" => {
600
596
let Gene {
601
597
kind,
602
598
mut data,
603
599
props,
604
600
} = gene;
605
601
let new_kind = data. remove ( 0 ) ;
606
- data. insert ( 0 , kind) ;
602
+ data. insert ( 0 , * kind) ;
607
603
Gene {
608
- kind : new_kind,
604
+ kind : Box :: new ( new_kind. clone ( ) ) ,
609
605
props,
610
606
data,
611
607
}
0 commit comments