@@ -162,7 +162,7 @@ impl Executor {
162
162
/// ログ表示
163
163
fn log_print ( & mut self , msg : String ) {
164
164
if let Mode :: Debug = self . mode {
165
- println ! ( "{msg}" ) ;
165
+ print ! ( "{msg}" ) ;
166
166
}
167
167
}
168
168
@@ -179,6 +179,17 @@ impl Executor {
179
179
) ) ;
180
180
}
181
181
182
+ fn show_stack ( & mut self ) {
183
+ self . log_print ( format ! (
184
+ "Stack〔 {} 〕" ,
185
+ self . stack
186
+ . iter( )
187
+ . map( |x| x. display( ) )
188
+ . collect:: <Vec <_>>( )
189
+ . join( " | " )
190
+ ) )
191
+ }
192
+
182
193
/// 構文解析
183
194
fn analyze_syntax ( & mut self , code : String ) -> Vec < String > {
184
195
let code = code
@@ -244,15 +255,8 @@ impl Executor {
244
255
245
256
for token in syntax {
246
257
// スタック内部を表示する
247
- self . log_print ( format ! (
248
- "Stack〔 {} 〕 ← {}" ,
249
- self . stack
250
- . iter( )
251
- . map( |x| x. display( ) )
252
- . collect:: <Vec <_>>( )
253
- . join( " | " ) ,
254
- token
255
- ) ) ;
258
+ self . show_stack ( ) ;
259
+ self . log_print ( format ! ( " ← {}\n " , token) ) ;
256
260
257
261
// 数値に変換できたらスタックに積む
258
262
if let Ok ( i) = token. parse :: < f64 > ( ) {
@@ -303,7 +307,7 @@ impl Executor {
303
307
304
308
// コメントを処理
305
309
if token. contains ( "#" ) {
306
- self . log_print ( format ! ( "※ コメント「{}」" , token. replace( "#" , "" ) ) ) ;
310
+ self . log_print ( format ! ( "※ コメント「{}」\n " , token. replace( "#" , "" ) ) ) ;
307
311
continue ;
308
312
}
309
313
@@ -312,14 +316,8 @@ impl Executor {
312
316
}
313
317
314
318
// 実行後のスタックを表示
315
- self . log_print ( format ! (
316
- "Stack〔 {} 〕" ,
317
- self . stack
318
- . iter( )
319
- . map( |x| x. display( ) )
320
- . collect:: <Vec <_>>( )
321
- . join( " | " ) ,
322
- ) ) ;
319
+ self . show_stack ( ) ;
320
+ self . log_print ( "\n " . to_string ( ) ) ;
323
321
}
324
322
325
323
/// コマンドを実行する
@@ -435,7 +433,7 @@ impl Executor {
435
433
match result {
436
434
Some ( c) => self . stack . push ( Type :: String ( c. to_string ( ) ) ) ,
437
435
None => {
438
- self . log_print ( "エラー! 数値デコードに失敗しました" . to_string ( ) ) ;
436
+ self . log_print ( "エラー! 数値デコードに失敗しました\n " . to_string ( ) ) ;
439
437
self . stack . push ( Type :: Number ( code) ) ;
440
438
}
441
439
}
@@ -446,7 +444,7 @@ impl Executor {
446
444
if let Some ( first_char) = string. chars ( ) . next ( ) {
447
445
self . stack . push ( Type :: Number ( ( first_char as u32 ) as f64 ) ) ;
448
446
} else {
449
- self . log_print ( "エラー! 文字列のエンコードに失敗しました" . to_string ( ) ) ;
447
+ self . log_print ( "エラー! 文字列のエンコードに失敗しました\n " . to_string ( ) ) ;
450
448
self . stack . push ( Type :: String ( string) )
451
449
}
452
450
}
@@ -582,7 +580,7 @@ impl Executor {
582
580
. to_string ( ) ,
583
581
) ) ,
584
582
Err ( _) => {
585
- self . log_print ( "エラー! シェルスクリプトの実行に失敗しました" . to_string ( ) )
583
+ self . log_print ( "エラー! シェルスクリプトの実行に失敗しました\n " . to_string ( ) )
586
584
}
587
585
}
588
586
}
@@ -602,7 +600,7 @@ impl Executor {
602
600
if list. len ( ) > index {
603
601
self . stack . push ( list[ index] . clone ( ) ) ;
604
602
} else {
605
- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
603
+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
606
604
self . stack . push ( Type :: List ( list) ) ;
607
605
}
608
606
}
@@ -616,7 +614,7 @@ impl Executor {
616
614
list[ index] = value;
617
615
self . stack . push ( Type :: List ( list) ) ;
618
616
} else {
619
- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
617
+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
620
618
self . stack . push ( Type :: List ( list) ) ;
621
619
}
622
620
}
@@ -629,7 +627,7 @@ impl Executor {
629
627
list. remove ( index as usize ) ;
630
628
self . stack . push ( Type :: List ( list) ) ;
631
629
} else {
632
- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
630
+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
633
631
self . stack . push ( Type :: List ( list) ) ;
634
632
}
635
633
}
@@ -863,7 +861,9 @@ impl Executor {
863
861
if let Some ( value) = self . stack . pop ( ) {
864
862
value
865
863
} else {
866
- self . log_print ( "エラー! スタックの値が足りません。デフォルト値を返します" . to_string ( ) ) ;
864
+ self . log_print (
865
+ "エラー! スタックの値が足りません。デフォルト値を返します\n " . to_string ( ) ,
866
+ ) ;
867
867
Type :: String ( "" . to_string ( ) )
868
868
}
869
869
}
0 commit comments