@@ -52,7 +52,6 @@ impl DIR {
52
52
. iter ( )
53
53
. flat_map ( |m| m. as_bytes ( & mut self . constant_pool ) )
54
54
. collect ( ) ;
55
- println ! ( "Constant pool: {:?}" , self . constant_pool) ;
56
55
// Constant Pool
57
56
result. extend_from_slice ( & self . constant_pool . count ( ) . to_be_bytes ( ) ) ;
58
57
result. append ( & mut self . constant_pool . as_bytes ( ) ) ;
@@ -348,7 +347,7 @@ impl LocalVarPool {
348
347
. iter ( )
349
348
. position ( |n| n == name)
350
349
. map ( |i| i as u8 )
351
- . expect ( & * format ! ( "Local var {:?} not found in {:?}" , name, self . 0 ) )
350
+ . unwrap_or_else ( || panic ! ( "Local var {:?} not found in {:?}" , name, self . 0 ) )
352
351
}
353
352
}
354
353
#[ derive( Debug ) ]
@@ -455,9 +454,7 @@ pub struct NameAndType {
455
454
}
456
455
457
456
fn get_instruction_length ( istr : & Instruction ) -> u16 {
458
- match istr {
459
- i => i. as_bytes ( ) . len ( ) as u16 ,
460
- }
457
+ istr. as_bytes ( ) . len ( ) as u16
461
458
}
462
459
463
460
fn get_instructions_length ( instructions : & [ Instruction ] ) -> u16 {
@@ -751,7 +748,7 @@ fn generate_code_stmt(
751
748
) ) ;
752
749
}
753
750
Stmt :: LocalVarDecl ( types, name) => {
754
- local_var_pool. add ( name. clone ( ) ) ;
751
+ local_var_pool. add ( name) ;
755
752
stack. inc ( 1 ) ;
756
753
}
757
754
Stmt :: If ( expr, stmt1, stmt2) => {
@@ -902,8 +899,7 @@ fn generate_code_stmt_expr(
902
899
}
903
900
StmtExpr :: New ( types, exprs) => {
904
901
// Generate bytecode for new
905
- let class_index =
906
- constant_pool. add ( Constant :: Class ( types. to_ir_string ( ) . to_string ( ) ) ) ;
902
+ let class_index = constant_pool. add ( Constant :: Class ( types. to_ir_string ( ) ) ) ;
907
903
let method_index = constant_pool. add ( Constant :: MethodRef ( MethodRef {
908
904
class : types. to_ir_string ( ) ,
909
905
method : NameAndType {
@@ -938,7 +934,7 @@ fn generate_code_stmt_expr(
938
934
} )
939
935
. collect ( ) ,
940
936
) ;
941
- fn generate_name_and_type ( return_type : & Type , args : & Vec < Expr > ) -> String {
937
+ fn generate_name_and_type ( return_type : & Type , args : & [ Expr ] ) -> String {
942
938
// Argument types comma seperated
943
939
let argument_types = args
944
940
. iter ( )
@@ -1008,7 +1004,7 @@ fn generate_code_expr(
1008
1004
stack. inc ( 1 ) ;
1009
1005
}
1010
1006
Expr :: String ( s) => {
1011
- let index = constant_pool. add ( Constant :: String ( s. to_string ( ) ) ) ;
1007
+ let index = constant_pool. add ( Constant :: String ( s) ) ;
1012
1008
result. push ( Instruction :: ldc ( index as u8 ) ) ;
1013
1009
stack. inc ( 1 ) ;
1014
1010
}
@@ -1060,7 +1056,7 @@ fn generate_code_expr(
1060
1056
let field_index = constant_pool. add ( Constant :: FieldRef ( FieldRef {
1061
1057
class : class_name. to_string ( ) ,
1062
1058
field : NameAndType {
1063
- name : name . clone ( ) ,
1059
+ name,
1064
1060
r#type : r#type. to_ir_string ( ) ,
1065
1061
} ,
1066
1062
} ) ) ;
@@ -1386,16 +1382,16 @@ fn generate_code_expr(
1386
1382
let index = local_var_pool. get_index ( & name) ;
1387
1383
match r#type {
1388
1384
Type :: Int => {
1389
- result. push ( Instruction :: iload ( index as u8 ) ) ;
1385
+ result. push ( Instruction :: iload ( index) ) ;
1390
1386
}
1391
1387
Type :: Bool => {
1392
- result. push ( Instruction :: iload ( index as u8 ) ) ;
1388
+ result. push ( Instruction :: iload ( index) ) ;
1393
1389
}
1394
1390
Type :: Char => {
1395
- result. push ( Instruction :: iload ( index as u8 ) ) ;
1391
+ result. push ( Instruction :: iload ( index) ) ;
1396
1392
}
1397
1393
Type :: String => {
1398
- result. push ( Instruction :: aload ( index as u8 ) ) ;
1394
+ result. push ( Instruction :: aload ( index) ) ;
1399
1395
}
1400
1396
_ => panic ! ( "Unexpected type: {:?}" , r#type) ,
1401
1397
}
@@ -1414,7 +1410,7 @@ fn generate_code_expr(
1414
1410
let index = constant_pool. add ( Constant :: FieldRef ( FieldRef {
1415
1411
class : class_name. to_string ( ) ,
1416
1412
field : NameAndType {
1417
- name : name . clone ( ) ,
1413
+ name,
1418
1414
r#type : r#type. to_ir_string ( ) ,
1419
1415
} ,
1420
1416
} ) ) ;
0 commit comments