@@ -162,7 +162,7 @@ impl Executor {
162162 /// ログ表示
163163 fn log_print ( & mut self , msg : String ) {
164164 if let Mode :: Debug = self . mode {
165- println ! ( "{msg}" ) ;
165+ print ! ( "{msg}" ) ;
166166 }
167167 }
168168
@@ -179,6 +179,17 @@ impl Executor {
179179 ) ) ;
180180 }
181181
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+
182193 /// 構文解析
183194 fn analyze_syntax ( & mut self , code : String ) -> Vec < String > {
184195 let code = code
@@ -244,15 +255,8 @@ impl Executor {
244255
245256 for token in syntax {
246257 // スタック内部を表示する
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) ) ;
256260
257261 // 数値に変換できたらスタックに積む
258262 if let Ok ( i) = token. parse :: < f64 > ( ) {
@@ -303,7 +307,7 @@ impl Executor {
303307
304308 // コメントを処理
305309 if token. contains ( "#" ) {
306- self . log_print ( format ! ( "※ コメント「{}」" , token. replace( "#" , "" ) ) ) ;
310+ self . log_print ( format ! ( "※ コメント「{}」\n " , token. replace( "#" , "" ) ) ) ;
307311 continue ;
308312 }
309313
@@ -312,14 +316,8 @@ impl Executor {
312316 }
313317
314318 // 実行後のスタックを表示
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 ( ) ) ;
323321 }
324322
325323 /// コマンドを実行する
@@ -435,7 +433,7 @@ impl Executor {
435433 match result {
436434 Some ( c) => self . stack . push ( Type :: String ( c. to_string ( ) ) ) ,
437435 None => {
438- self . log_print ( "エラー! 数値デコードに失敗しました" . to_string ( ) ) ;
436+ self . log_print ( "エラー! 数値デコードに失敗しました\n " . to_string ( ) ) ;
439437 self . stack . push ( Type :: Number ( code) ) ;
440438 }
441439 }
@@ -446,7 +444,7 @@ impl Executor {
446444 if let Some ( first_char) = string. chars ( ) . next ( ) {
447445 self . stack . push ( Type :: Number ( ( first_char as u32 ) as f64 ) ) ;
448446 } else {
449- self . log_print ( "エラー! 文字列のエンコードに失敗しました" . to_string ( ) ) ;
447+ self . log_print ( "エラー! 文字列のエンコードに失敗しました\n " . to_string ( ) ) ;
450448 self . stack . push ( Type :: String ( string) )
451449 }
452450 }
@@ -582,7 +580,7 @@ impl Executor {
582580 . to_string ( ) ,
583581 ) ) ,
584582 Err ( _) => {
585- self . log_print ( "エラー! シェルスクリプトの実行に失敗しました" . to_string ( ) )
583+ self . log_print ( "エラー! シェルスクリプトの実行に失敗しました\n " . to_string ( ) )
586584 }
587585 }
588586 }
@@ -602,7 +600,7 @@ impl Executor {
602600 if list. len ( ) > index {
603601 self . stack . push ( list[ index] . clone ( ) ) ;
604602 } else {
605- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
603+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
606604 self . stack . push ( Type :: List ( list) ) ;
607605 }
608606 }
@@ -616,7 +614,7 @@ impl Executor {
616614 list[ index] = value;
617615 self . stack . push ( Type :: List ( list) ) ;
618616 } else {
619- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
617+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
620618 self . stack . push ( Type :: List ( list) ) ;
621619 }
622620 }
@@ -629,7 +627,7 @@ impl Executor {
629627 list. remove ( index as usize ) ;
630628 self . stack . push ( Type :: List ( list) ) ;
631629 } else {
632- self . log_print ( "エラー! インデックス指定が範囲外です" . to_string ( ) ) ;
630+ self . log_print ( "エラー! インデックス指定が範囲外です\n " . to_string ( ) ) ;
633631 self . stack . push ( Type :: List ( list) ) ;
634632 }
635633 }
@@ -863,7 +861,9 @@ impl Executor {
863861 if let Some ( value) = self . stack . pop ( ) {
864862 value
865863 } else {
866- self . log_print ( "エラー! スタックの値が足りません。デフォルト値を返します" . to_string ( ) ) ;
864+ self . log_print (
865+ "エラー! スタックの値が足りません。デフォルト値を返します\n " . to_string ( ) ,
866+ ) ;
867867 Type :: String ( "" . to_string ( ) )
868868 }
869869 }
0 commit comments