Next: 2 仮想計算機
Up: 1 Schemeのコンパイラ
Previous: 1.3 コンパイラの初期化
コンパイルで得られた構造体を
返すのではなく,コード部のみを
わかりやすく表示する手続きをcomp-show
として定義しておきます.
fresh-lineは,出力ストリームが行の先頭になっていなければ
改行を行う組み込み関数です.先頭にかかわらず改行を出力する
組み込み関数としてterpriがあります.
(defun comp-show (x)
(show-fn (scheme-compile x)))
(defun show-fn (fn &optional
(stream *standard-output*)
(depth 0))
(if (not (fn-p fn))
(format stream "~6a" fn)
(progn
(fresh-line)
(incf depth 6)
(dolist (instr (fn-code fn))
(if (atom instr)
(format stream "~a:" instr)
(progn
(format stream "~VT" depth)
(dolist (arg instr)
(show-fn arg stream depth))
(fresh-line)))))))
format文は,(format stream format-string args)という形で
format-stringに a は式をそのまま表示し,
VTは 指定された数の文字文の出力場所に表示し,
<cl> (format t "~VT~a" 10 'a)
A
NIL
<cl> (format t "~VT~a~%~VT~a" 4 'a 8 'b)
A
B
NIL
<cl> (format t "~VT~a~&~VT~a" 10 'a 12 'b)
A
B
NIL
<cl> (format t "~VT~a~VT~a" 4 'a 8 'b)
A B
NIL
generated through LaTeX2HTML. M.Inaba 平成18年5月6日