@@ -52,7 +52,6 @@ impl DIR {
5252 . iter ( )
5353 . flat_map ( |m| m. as_bytes ( & mut self . constant_pool ) )
5454 . collect ( ) ;
55- println ! ( "Constant pool: {:?}" , self . constant_pool) ;
5655 // Constant Pool
5756 result. extend_from_slice ( & self . constant_pool . count ( ) . to_be_bytes ( ) ) ;
5857 result. append ( & mut self . constant_pool . as_bytes ( ) ) ;
@@ -348,7 +347,7 @@ impl LocalVarPool {
348347 . iter ( )
349348 . position ( |n| n == name)
350349 . 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 ) )
352351 }
353352}
354353#[ derive( Debug ) ]
@@ -455,9 +454,7 @@ pub struct NameAndType {
455454}
456455
457456fn 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
461458}
462459
463460fn get_instructions_length ( instructions : & [ Instruction ] ) -> u16 {
@@ -751,7 +748,7 @@ fn generate_code_stmt(
751748 ) ) ;
752749 }
753750 Stmt :: LocalVarDecl ( types, name) => {
754- local_var_pool. add ( name. clone ( ) ) ;
751+ local_var_pool. add ( name) ;
755752 stack. inc ( 1 ) ;
756753 }
757754 Stmt :: If ( expr, stmt1, stmt2) => {
@@ -902,8 +899,7 @@ fn generate_code_stmt_expr(
902899 }
903900 StmtExpr :: New ( types, exprs) => {
904901 // 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 ( ) ) ) ;
907903 let method_index = constant_pool. add ( Constant :: MethodRef ( MethodRef {
908904 class : types. to_ir_string ( ) ,
909905 method : NameAndType {
@@ -938,7 +934,7 @@ fn generate_code_stmt_expr(
938934 } )
939935 . collect ( ) ,
940936 ) ;
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 {
942938 // Argument types comma seperated
943939 let argument_types = args
944940 . iter ( )
@@ -1008,7 +1004,7 @@ fn generate_code_expr(
10081004 stack. inc ( 1 ) ;
10091005 }
10101006 Expr :: String ( s) => {
1011- let index = constant_pool. add ( Constant :: String ( s. to_string ( ) ) ) ;
1007+ let index = constant_pool. add ( Constant :: String ( s) ) ;
10121008 result. push ( Instruction :: ldc ( index as u8 ) ) ;
10131009 stack. inc ( 1 ) ;
10141010 }
@@ -1060,7 +1056,7 @@ fn generate_code_expr(
10601056 let field_index = constant_pool. add ( Constant :: FieldRef ( FieldRef {
10611057 class : class_name. to_string ( ) ,
10621058 field : NameAndType {
1063- name : name . clone ( ) ,
1059+ name,
10641060 r#type : r#type. to_ir_string ( ) ,
10651061 } ,
10661062 } ) ) ;
@@ -1386,16 +1382,16 @@ fn generate_code_expr(
13861382 let index = local_var_pool. get_index ( & name) ;
13871383 match r#type {
13881384 Type :: Int => {
1389- result. push ( Instruction :: iload ( index as u8 ) ) ;
1385+ result. push ( Instruction :: iload ( index) ) ;
13901386 }
13911387 Type :: Bool => {
1392- result. push ( Instruction :: iload ( index as u8 ) ) ;
1388+ result. push ( Instruction :: iload ( index) ) ;
13931389 }
13941390 Type :: Char => {
1395- result. push ( Instruction :: iload ( index as u8 ) ) ;
1391+ result. push ( Instruction :: iload ( index) ) ;
13961392 }
13971393 Type :: String => {
1398- result. push ( Instruction :: aload ( index as u8 ) ) ;
1394+ result. push ( Instruction :: aload ( index) ) ;
13991395 }
14001396 _ => panic ! ( "Unexpected type: {:?}" , r#type) ,
14011397 }
@@ -1414,7 +1410,7 @@ fn generate_code_expr(
14141410 let index = constant_pool. add ( Constant :: FieldRef ( FieldRef {
14151411 class : class_name. to_string ( ) ,
14161412 field : NameAndType {
1417- name : name . clone ( ) ,
1413+ name,
14181414 r#type : r#type. to_ir_string ( ) ,
14191415 } ,
14201416 } ) ) ;
0 commit comments