my last entry (http://use.perl.org/user/particle/journal/35300>) described how i added support to the Parrot Compiler Toolkit to support a '--help' command line option for compilers. my next commit enables this option for perl6.
view the patch here: http://perlsix.org/svn/parrot/revision/?rev=24554>
since i laid the foundation for implementing usage messages in PCT, it was easy to customize it for perl6. i'll walk through it briefly.
the first difference is in the 'onload' subroutine, which is run when the perl6 bytecode is loaded by parrot. after a new HLLCompiler object has been created, i create a new String PMC using a parrot heredoc containing the help text for the command line options specific to perl6. since @larry hasn't written S19, the synopsis on the perl 6 command line interface, these options are likely to change.
the second difference implements the 'usage' method that HLLCompiler calls when the '-h' or '--help' option is passed. if an argument is not passed for the optional parameter 'name', it is defaulted to 'perl6'. a usage message is printed containing the contents of 'name' and the '$usage' attribute of the HLLCompiler object as set above, and the program exits.
based on the techniques i've used to implement '--help', it should be straightforward to implement similar command line options for the perl6 compiler.
related links:
perl 6 synopses:
http://perlcabal.org/syn
Firstly, thanks very much for your last couple of diary entries, they've been helpful getting me started learning a bit more about parrot and PCT.
Looking at your second change though, I'm not sure that it's working the way that it's supposed to...
Does Perl6::Compiler actually sub-class HLLCompiler? It doesn't appear to, since the 'usage' method that you define in perl6.pir never seems to be called. It seems to be using the version defined in HLLCompiler instead, which presumably means that the one in perl6.pir is not overriding the other one.
Also, in any case I think that the method contains an error: I'm not certain, but I think it should say 'if has_name goto has_name', and not 'unless has_name
Re:'usage' method not actually overridden?
particle on 2008-01-08T00:42:12
oops! you're right. there's no reason for a 'usage' method in perl6, because HLLCompiler already provides one. all i need to do is put the usage text in the '$usage' attribute. i've made this change in r24667.
view the diff here: http://perlsix.org/svn/parrot/revision/?rev=24667