@@ -433,7 +433,7 @@ impl Executor {
433
433
match command. as_str ( ) {
434
434
// Commands of calculation
435
435
436
- // addition
436
+ // Addition
437
437
"add" => {
438
438
let b = self . pop_stack ( ) . get_number ( ) ;
439
439
let a = self . pop_stack ( ) . get_number ( ) ;
@@ -519,14 +519,14 @@ impl Executor {
519
519
self . stack . push ( Type :: Bool ( !b) ) ;
520
520
}
521
521
522
- // Is it equal
522
+ // Judge is it equal
523
523
"equal" => {
524
524
let b = self . pop_stack ( ) . get_string ( ) ;
525
525
let a = self . pop_stack ( ) . get_string ( ) ;
526
526
self . stack . push ( Type :: Bool ( a == b) ) ;
527
527
}
528
528
529
- // Is it less
529
+ // Judge is it less
530
530
"less" => {
531
531
let b = self . pop_stack ( ) . get_number ( ) ;
532
532
let a = self . pop_stack ( ) . get_number ( ) ;
@@ -554,8 +554,8 @@ impl Executor {
554
554
555
555
// Repeat string a number of times
556
556
"repeat" => {
557
- let count = self . pop_stack ( ) . get_number ( ) ; // 回数
558
- let text = self . pop_stack ( ) . get_string ( ) ; // 文字列
557
+ let count = self . pop_stack ( ) . get_number ( ) ; // Count
558
+ let text = self . pop_stack ( ) . get_string ( ) ; // String
559
559
self . stack . push ( Type :: String ( text. repeat ( count as usize ) ) ) ;
560
560
}
561
561
@@ -598,7 +598,7 @@ impl Executor {
598
598
self . stack . push ( Type :: String ( text. replace ( & before, & after) ) )
599
599
}
600
600
601
- // split string by key
601
+ // Split string by the key
602
602
"split" => {
603
603
let key = self . pop_stack ( ) . get_string ( ) ;
604
604
let text = self . pop_stack ( ) . get_string ( ) ;
@@ -633,7 +633,7 @@ impl Executor {
633
633
) )
634
634
}
635
635
636
- // Is it finding in string
636
+ // Judge is it find in string
637
637
"find" => {
638
638
let word = self . pop_stack ( ) . get_string ( ) ;
639
639
let text = self . pop_stack ( ) . get_string ( ) ;
@@ -781,17 +781,17 @@ impl Executor {
781
781
782
782
// Commands of control
783
783
784
- // evaluate string as program
784
+ // Evaluate string as program
785
785
"eval" => {
786
786
let code = self . pop_stack ( ) . get_string ( ) ;
787
787
self . evaluate_program ( code)
788
788
}
789
789
790
790
// Conditional branch
791
791
"if" => {
792
- let condition = self . pop_stack ( ) . get_bool ( ) ; // condition
793
- let code_else = self . pop_stack ( ) . get_string ( ) ; // else code
794
- let code_if = self . pop_stack ( ) . get_string ( ) ; // if code
792
+ let condition = self . pop_stack ( ) . get_bool ( ) ; // Condition
793
+ let code_else = self . pop_stack ( ) . get_string ( ) ; // Code of else
794
+ let code_if = self . pop_stack ( ) . get_string ( ) ; // Code of If
795
795
if condition {
796
796
self . evaluate_program ( code_if)
797
797
} else {
@@ -818,7 +818,7 @@ impl Executor {
818
818
thread:: spawn ( move || executor. evaluate_program ( code) ) ;
819
819
}
820
820
821
- // exit a process
821
+ // Exit a process
822
822
"exit" => {
823
823
let status = self . pop_stack ( ) . get_number ( ) ;
824
824
std:: process:: exit ( status as i32 ) ;
@@ -884,11 +884,11 @@ impl Executor {
884
884
885
885
// Get index of the list
886
886
"index" => {
887
- let findhint = self . pop_stack ( ) . get_string ( ) ;
888
- let findtarget = self . pop_stack ( ) . get_list ( ) ;
887
+ let target = self . pop_stack ( ) . get_string ( ) ;
888
+ let list = self . pop_stack ( ) . get_list ( ) ;
889
889
890
- for index in 0 .. ( findtarget . len ( ) ) {
891
- if findhint == findtarget [ index ] . clone ( ) . get_string ( ) {
890
+ for ( index, item ) in list . iter ( ) . enumerate ( ) {
891
+ if target == item . clone ( ) . get_string ( ) {
892
892
self . stack . push ( Type :: Number ( index as f64 ) ) ;
893
893
return ;
894
894
}
@@ -920,7 +920,7 @@ impl Executor {
920
920
self . stack . push ( Type :: List ( list) ) ;
921
921
}
922
922
923
- // Iteration
923
+ // Iteration for the list
924
924
"for" => {
925
925
let code = self . pop_stack ( ) . get_string ( ) ;
926
926
let vars = self . pop_stack ( ) . get_string ( ) ;
@@ -1040,7 +1040,7 @@ impl Executor {
1040
1040
1041
1041
// Commands of memory manage
1042
1042
1043
- // pop in the stack
1043
+ // Pop in the stack
1044
1044
"pop" => {
1045
1045
self . pop_stack ( ) ;
1046
1046
}
@@ -1159,7 +1159,7 @@ impl Executor {
1159
1159
let element = match data. get ( index) {
1160
1160
Some ( value) => value,
1161
1161
None => {
1162
- self . log_print ( format ! ( "Error! initial data is shortage\n " ) ) ;
1162
+ self . log_print ( "Error! initial data is shortage\n " . to_string ( ) ) ;
1163
1163
self . stack
1164
1164
. push ( Type :: Error ( "instance-shortage" . to_string ( ) ) ) ;
1165
1165
return ;
0 commit comments