memo
tests-*-req.scm から適当に抜き出したサンプルについて gauche コンパイルのパス1,2,3を眺める。 ($gref 手続き) というパターンと $asm というパターンがある。また、定数式になってしまうものとそうでないものとがあって、なかなか面白い。HTML 表にしてざっくり見てみる。ソースを追うのは難しすぎてまだまだ無理、という感じ。
※どこかでこの類いの表を見たような気がする。"Reading Gauche" ?
(use text.tree) (use text.html-lite) ;; コンパイル。手抜きで compile-p1 etc の表示をそのまま (define (p1 program) (with-output-to-string (lambda () ((with-module gauche.internal compile-p1) program)))) ... ;; テストデータ (define tests-data '(0 1 -1 (fixnum? 0) (fixnum? #t) (null? ()) (null? #t) (if #t 12 13) (if #t (if 12 13 4) 17) (and) (and #t) ... (letrec ((f (lambda (x y) (+ x y))) (g (lambda (x) (+ x 12)))) (f 16 (f (g 0) (+ 1 (g 0))))) (letrec ((f (lambda (x) (g x x))) (g (lambda (x y) (fx+ x y)))) (f 12)) (letrec ((f (lambda (x) (if (zero? x) 1 (* x (f (- x 1))))))) (f 5)))) ;; HTML 生成 (define (gen-pass-html programs) (html:html (html:body (gen-pass-table programs)))) ;; テーブル生成 (define (gen-pass-table programs) (html:table :border #t (html:tr (html:th "program") (html:th "pass1") (html:th "pass2") (html:th "pass3")) (map (lambda (program) (html:tr (html:td (html:pre (format #f "~s" program))) (html:td (html:pre (p1 program))) (html:td (html:pre (p2 program))) (html:td (html:pre (p3 program))))) programs))) ;; HTML ファイル生成 (with-output-to-file "passes-gauche.html" (lambda () (write-tree (gen-pass-html tests-data))))
他でも同じように取り出せればざーっと眺められる。書いてから気付いたが、後で自作のコンパイラでもプログラム、最適化無し、最適化済み、それからアセンブラ、と出力しておこう。キーワードに色でも付けて一覧すると何か気付くことがあるかもしれない。