トップ «前の日記(2005-10-18 (Tue)) 最新 次の日記(2005-12-17 (Sat))» 編集 RSS feed

継続にっき

2004|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|12|
2006|01|03|05|06|08|09|10|12|
2007|01|02|03|05|07|12|
2008|10|
2009|01|05|12|
2010|04|05|11|
2011|01|09|12|
2012|02|03|05|09|12|
2013|02|03|
2014|05|09|
2015|12|
2017|09|

2005-12-10 (Sat)

))) Gauche 0.8.6のコンパイル過程を見る

こんな風にsrc/compile.scmをいじって

--- src/compile.scm     13 Aug 2005 06:51:52 -0000      1.33
+++ src/compile.scm     10 Dec 2005 10:29:12 -0000
@@ -33,11 +33,18 @@
 ;;;  $Id: compile.scm,v 1.33 2005/08/13 06:51:52 shirok Exp $
 ;;;

-(define-module gauche.internal
+(define-module gauche.internal.test
   (use srfi-2)
   (use util.match)
   )
-(select-module gauche.internal)
+(select-module gauche.internal.test)
+(with-module gauche.internal (export-all))
+(import gauche.internal)
+
+(define-syntax eval-when
+  (syntax-rules ()
+    ((_ (situation ...) body ...)
+     (begin body ...))))

 ;;; THE COMPILER
 ;;;

goshでロードするといろいろと遊べる。

$ gosh -I src -l compile.scm -E 'select-module gauche.internal.test'

 gosh> (define p1 (pass1 '((lambda (x) x) 1) (make-bottom-cenv)))
 gosh> (define p2 (pass2 p1))
 gosh> (define p3 (pass3 p2
                         (make-compiled-code-builder 0 0 '%toplevel #f #f)
                         '() 'tail))
 gosh> p1
 #(13 (#0=(lambda (x) x) 1) #(9 #0# #f 1 0 (#1=#(lvar x #<undef> 1 0)) #(1 #1#) #f () ()) (#(5 1)) #f ())
 gosh> p2
 #(5 1)
 gosh> (vm-dump-code p3)
 main_code (name=%toplevel, code=0x9001eb8, size=2, const=0, stack=0):
 args: #f
      0 CONSTI(1)
      1 RET

ちなみに以前gauche.vm.disasmにあったdisasmはgauche.procedureに移ったようだ。

$ gosh -ugauche.procedure

 gosh> (define a (lambda (x y) (+ x y)))
 a
 gosh> (disasm a)
 main_code (name=a, code=0x86e3e20, size=4, const=0, stack=1):
 args: #f
      0 LREF1-PUSH               ; x
      1 LREF0                    ; y
      2 NUMADD2                  ; (+ x y)
      3 RET

追記

compile.scm中で定義されているマクロを使う必要性が無いときにはcompile-p1などを使えばcompile.scmに 手を加えなくてもコンパイル過程を見ることが出来る。

$ gosh
gosh> (with-module gauche.internal (compile-p1 '((lambda (x) x) 1)))
($call ($lambda[#f;0] (x[1;0])
         ($lref x[1;0]))
  ($const 1))

2004|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|12|
2006|01|03|05|06|08|09|10|12|
2007|01|02|03|05|07|12|
2008|10|
2009|01|05|12|
2010|04|05|11|
2011|01|09|12|
2012|02|03|05|09|12|
2013|02|03|
2014|05|09|
2015|12|
2017|09|
トップ «前の日記(2005-10-18 (Tue)) 最新 次の日記(2005-12-17 (Sat))» 編集 RSS feed