Hi all!
I often use Guillaume Germain's profiler for gambit (http://www.iro.umontreal.ca/~germaing/statprof.html) and I would like to know if its possible to get a profiling result on the marco expanded code, and not the source code.
I ask this because I wrote several macro which define multiple functions. It seems that lots of the work is done within these functions but the profiler only tells me that it is my macro call who does all the work (but its in fact the code generated by that macro). So having access to a profiling report of the macro expanded code could be usefull :)
Thanks!
David
Afficher les réponses par date
For statprof to work with your code, you will have to rewrite your macros using Gambit's ##define-syntax.
When you use define-macro, Gambit strips all source information before passing the sexpr to expand to your macro. With ##define-syntax, you will receive a source object containing source positioning information for every sexpr in the form to expand. You can then insert those source objects into the expansion of your macro. Doing that, every Gambit tool that needs source information like statprof will now work with your macros.
Here's a 'when' macro defined using ##define-syntax :
(##define-syntax when (lambda (form-src) (let ((test (cadr (##source-code form-src))) (body (cddr (##source-code form-src)))) (##sourcify `(if ,test (begin ,@body) #f) form-src))))
A partial list of primitives you will need :
- (##source? expr) : guess what it does :) - (##source-code source) : returns the sepxr that was sourcified by 'source' - (##desourcify source) : full recursive desourcification of 'source' - (##sourcify expr source) : creates a source object for 'expr' that has the same source info as 'source'
On Thu, Nov 6, 2008 at 8:21 AM, David St-Hilaire sthilaid@iro.umontreal.cawrote:
Hi all!
I often use Guillaume Germain's profiler for gambit (http://www.iro.umontreal.ca/~germaing/statprof.html) and I would like to know if its possible to get a profiling result on the marco expanded code, and not the source code.
I ask this because I wrote several macro which define multiple functions. It seems that lots of the work is done within these functions but the profiler only tells me that it is my macro call who does all the work (but its in fact the code generated by that macro). So having access to a profiling report of the macro expanded code could be usefull :)
Thanks!
David _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Why doesn't the Gambit define-macro (and syntax-case) just do the right thing? This is very annoying. And it seems that the transformation you are applying below is very straightforward, and could be applied to all macros created with define-macro. I know there are complex cases where it might not work, but at least pointing the source at the macro source (as you do below) would be nice. Can you access the sub-source of a source object, rather than getting the sexpr?
William
Guillaume Cartier wrote:
For statprof to work with your code, you will have to rewrite your macros using Gambit's ##define-syntax.
When you use define-macro, Gambit strips all source information before passing the sexpr to expand to your macro. With ##define-syntax, you will receive a source object containing source positioning information for every sexpr in the form to expand. You can then insert those source objects into the expansion of your macro. Doing that, every Gambit tool that needs source information like statprof will now work with your macros.
Here's a 'when' macro defined using ##define-syntax :
(##define-syntax when (lambda (form-src) (let ((test (cadr (##source-code form-src))) (body (cddr (##source-code form-src)))) (##sourcify `(if ,test (begin ,@body) #f) form-src))))
A partial list of primitives you will need :
* (##source? expr) : guess what it does :) * (##source-code source) : returns the sepxr that was sourcified by 'source' * (##desourcify source) : full recursive desourcification of 'source' * (##sourcify expr source) : creates a source object for 'expr' that has the same source info as 'source'
On Thu, Nov 6, 2008 at 8:21 AM, David St-Hilaire <sthilaid@iro.umontreal.ca mailto:sthilaid@iro.umontreal.ca> wrote:
Hi all! I often use Guillaume Germain's profiler for gambit (http://www.iro.umontreal.ca/~germaing/statprof.html) and I would like to know if its possible to get a profiling result on the marco expanded code, and not the source code. I ask this because I wrote several macro which define multiple functions. It seems that lots of the work is done within these functions but the profiler only tells me that it is my macro call who does all the work (but its in fact the code generated by that macro). So having access to a profiling report of the macro expanded code could be usefull :) Thanks! David _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca <mailto:Gambit-list@iro.umontreal.ca> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On Nov 15, 2008, at 12:38 PM, William Cook wrote:
Why doesn't the Gambit define-macro (and syntax-case) just do the right thing?
The R6RS syntax-case system that was developed for Ikarus (ported to some 12 other Scheme implementations including Gambit) does precisely that. At every macro transcription step, the source of the macro input (the form itself) is applied to the list of annotations of the output form, and duplicates are cancelled (in the same manner how marks cancel, but that's irrelevant). This gives allows syntax errors to show the macro expansion steps that resulted in the syntax error (when available); instead of just showing the final error.
Here's an example:
$ cat q.ss (import (rnrs))
(define-syntax let^ (syntax-rules () [(_ ([x* v*] ...) e e* ...) ((lambda (x* ...) e e* ...) v* ...)]))
(define-syntax L (syntax-rules () [(_ x v e) (let^ ([x v]) e)]))
(L v 13 (L 12 x (+ v x)))
$ ikarus --r6rs-script q.ss Unhandled exception: Condition components: 1. &who: lambda 2. &message: "not an identifier" 3. &syntax: form: (lambda (12) (+ v x)) subform: 12 4. &trace: #<syntax (lambda (12) (+ v x))> 5. &trace: #<syntax (let^ ((12 x)) (+ v x))> 6. &trace: #<syntax (L 12 x (+ v x)) [char 214 of q.ss]>
Aziz,,,