Neil Jerram <n...@ossau.uklinux.net> writes: > I now have it down to this: a program compiled inside the RHS of a > define-syntax form apparently has no meta; whereas the same program > compiled outside a define-syntax form does have meta:
Apologies for taking so long to follow up on this! I've been trying to remedy my lack of detailed understanding about how compilation works, and that has led me to wondering whether and how we will provide similar debugging facilities for compiled code as we have in 1.8.x for interpreted code. One option would be not to take the 1.8.x approach at all (i.e. using special hooks from the core of the evaluator/VM) but instead rely on instrumenting code at runtime. I had a quick play with this and it seems quite simple and promising. For example, here's a way of tracing when a procedure is called, and its return values: (define-macro (trace proc) `(let ((proc ,proc)) (set! ,proc (lambda args (display ";TRACE: ") (display ',proc) (display " ") (write args) (newline) (call-with-values (lambda () (apply proc args)) (lambda results (for-each (lambda (result) (display ";TRACE: ") (display ',proc) (display " => ") (write result) (newline)) results) (apply values results))))))) Yes, I know I should write that with define-syntax instead. :-) Then, with that in my .guile: n...@arudy:~/SW/Guile/git$ meta/uninstalled-env guile Guile Scheme interpreter 0.5 on Guile 1.9.5 Copyright (C) 2001-2008 Free Software Foundation, Inc. Enter `,help' for help. scheme@(guile-user)> (trace (@@ (system base compile) compile-fold)) ;;; note: source file /home/neil/SW/Guile/git/module/language/glil/compile-assembly.scm ;;; newer than compiled /home/neil/SW/Guile/git/module/language/glil/compile-assembly.go ;;; found fresh local cache at /home/neil/SW/Guile/git/cache/guile/ccache/1.9-0.L-LE-4/home/neil/SW/Guile/git/module/language/glil/compile-assembly.scm.go scheme@(guile-user)> (trace (@@ (language glil compile-assembly) compile-assembly)) ;TRACE: (@@ (system base compile) compile-fold) ((#<program compile-tree-il (x e opts)> #<program compile-glil (x e opts)> #<program compile-asm (x e opts)> #<program compile-bytecode (assembly env . opts)> #<program compile-objcode (x e opts)>) (trace (@@ (language glil compile-assembly) compile-assembly)) #<directory (guile-user) 9947b98> (())) ;TRACE: (@@ (system base compile) compile-fold) => #<objcode 9b9f800> ;TRACE: (@@ (system base compile) compile-fold) => #<directory (guile-user) 9947b98> ;TRACE: (@@ (system base compile) compile-fold) => #<directory (guile-user) 9947b98> scheme@(guile-user)> (+ 3 4 5) ;TRACE: (@@ (system base compile) compile-fold) ((#<program compile-tree-il (x e opts)> #<program compile-glil (x e opts)> #<program compile-asm (x e opts)> #<program compile-bytecode (assembly env . opts)> #<program compile-objcode (x e opts)>) (+ 3 4 5) #<directory (guile-user) 9947b98> (())) ;TRACE: (@@ (language glil compile-assembly) compile-assembly) (#<glil (program () (source ((breakpoint . #f) (line . 2) (column . 0) (filename . #f))) (std-prelude 0 0 #f) (label :LCASE113) (const 3) (const 4) (const 5) (call add 2) (source ((breakpoint . #f) (line . 2) (column . 0) (filename . #f))) (call add 2) (source ((breakpoint . #f) (line . 2) (column . 0) (filename . #f))) (call return 1))>) ;TRACE: (@@ (language glil compile-assembly) compile-assembly) (#<glil (program () (const (() ((0 2 . 0)) ((6 15 0)))) (call return 1))>) ;TRACE: (@@ (language glil compile-assembly) compile-assembly) => (load-program () 25 #f (make-eol) (make-int8:0) (make-int8 2) (make-int8:0) (cons) (cons) (list 0 1) (make-int8 6) (make-int8 15) (make-int8:0) (list 0 3) (list 0 1) (list 0 3) (return)) ;TRACE: (@@ (language glil compile-assembly) compile-assembly) => (load-program ((:LCASE113 . 6)) 16 (load-program () 25 #f (make-eol) (make-int8:0) (make-int8 2) (make-int8:0) (cons) (cons) (list 0 1) (make-int8 6) (make-int8 15) (make-int8:0) (list 0 3) (list 0 1) (list 0 3) (return)) (assert-nargs-ee 0 0) (reserve-locals 0 0) (make-int8 3) (make-int8 4) (make-int8 5) (add) (add) (return) (nop)) ;TRACE: (@@ (system base compile) compile-fold) => #<objcode 9bd3f40> ;TRACE: (@@ (system base compile) compile-fold) => #<directory (guile-user) 9947b98> ;TRACE: (@@ (system base compile) compile-fold) => #<directory (guile-user) 9947b98> 12 scheme@(guile-user)> That seems quite nice and useful. (SLIB has stuff like this too. I wonder if it would just work.) We should be able to do breakpoints like this too, using either the command line or the GDS debugger - although I'm not sure how much of the stack inspection facilities will immediately work. I'll try that next. I don't see how single-stepping could easily be implemented this way, though. I think that may require hooks in the VM. But then again, would single stepping through VM operations be useful and comprehensible anyway? All thoughts welcome, as ever... Neil