Will Coleda wrote:
While it would be possible to implement
the basic functionality by wrapping existing subs in other subs,
I'm not sure that would help with
[trace info], which provides a way to report on all the traces that are
currently set.

Isn't that more a matter of setting a flag on the wrapping/tracing routine than it is of whether the wrapping thing is a subroutine?

> (We could hack this into a hidden global, as we do for tcl's
> ability to report on a function declaration: but that's a hack that
> I'd like to undo at some point).

Yes, let's avoid the hidden globals.

[...]

Thoughts? If this seems a reasonable approach, I can spec out more opcodes,
PIR sugar, etc., to handle all the subroutine related tracing required by
Tcl.

I like the idea. Write up a more complete proposal and we'll all review it. A few thoughts:

- The same mechanism could be used to implement Perl 6 sub wrapping, so keep that in mind as you're thinking through the implementation options. Names like "trace_sub" may be too specific to one particular use.

- Runtime addition of traces/wrappers will be more important than adding them at compile-time, considering that they're likely to be mostly used for layering debugging/profiling/etc checks over existing code, and in the debugger. So much more important, that I'd consider skipping the compile-time syntax.

- I like the Perl 6 way of specifying the point in the wrapping sub where the wrapped sub should be called better than setting up conditionals based on an argument for the operation type. So, something like:

.sub joe
  .param pmc wrapped_sub
  .param pmc orig_args

  .local string proc_name
  proc_name = wrapped_sub.name()

  print "entering "
  say proc_name

  invoke_wrapped wrapped_sub, orig_args

  print "leaving "
  say proc_name
.end

.sub bob :wrap joe
  say "whoa."
.end

(That also means you can monkey around with the args before passing them on to the wrapped sub.)


- It should be possible both to put multiple wrappers/traces on a subroutine, and to put wrappers around other wrappers. So these are all possible:

.sub joe
  #...
.end

.sub bob :wrap joe
  #...
.end

.sub phil :wrap joe
  #...
.end

.sub dave :wrap phil
  #...
.end


Allison

Reply via email to