Some of you may know that, in my quest for Clicker, i've been developing a PERL-based code rewriting tool: "CodeMonkey"
The general idea is that anyone should be able to write code the way he prefers rather than the way you're expected to. It's a sort of programmable pre-processor (aimed at C-like language, though i haven't investigated whether other languages could be supported as well). CodeMonkey is just a text processing framework that will read your sources, tokenize it and do a few "managing" operations, but the 'rewriting' proper is delegated to "plugins".
You tell in your sources what plugin you want to apply, e.g.
Code: Select all
@plugin "objects.pl","synchronized.pl"
Code: Select all
@plugin "GTK.pl"
The reason why i'm talking about this now is that i'm just done with the first plugin that may have interest beyond my own research, e.g. processing arguments on command line. I don't know how you feel about "argc" and "argv", but honnestly, i never liked them. If you look into clicker's building tools, you'll notice weird stuff such as
Code: Select all
// options locales
clpSet clpLocal={
"",4,"target options",{
{"--target",setStart,"sets the default target address"},
{"--mode",setType,"sets the module type. Valid arguments are "
"'kernal', 'system', 'intermediate' or 'endlevel'"
},
{"--name",setName,"sets the module name."},
},
&clpExperimental
};
Even with my best cpp skills, i couldn't achieve something prettier than
Code: Select all
CLPFILTER(setName) {
CHK_ARG(1,"setting module name");
App.name=GET_ARG(1);
CLN_ARG(2);
}
Now, i can use e.g.
Code: Select all
@plugin "args.pl"
// some #include here
@argument int kbps=(5,"emission rate");
@argument int max=(5,"amount of packets to be sent");
@argument str ip=("127.0.0.1","target IP address");
int main(int argc, char* argv[])
{
// local variables
@argument.prepare;
// now you can use kbps, max and ip ;)
}
Code: Select all
# how to process the existing types in @argument.
# new types can be added with new entries in this hash, e.g.
# - real C type for the argument (e.g. Person_t *)
# - number of arguments to retrieve on the command line (e.g. 2)
# - function or expression to create a value from the arguments
# from strings. (e.g. newPerson(%) which will be expanded into
# newPerson("Sylvain", "Martin") at run time.
# that would mean
# 'person' => "struct Person_t *::2::newPerson(%)"
my %types=(
'int'=>"int::1::atoi(%)",
'str'=>"char*::1::%",
'flag'=>"int::0::1",
);
If you're interested, you can download a "demo" package here.cmdemo> ./collect --help
Available Options :
Group "@args.pl auto-generated options":
* -kbps :emission rate(int)
* -max :amount of packets to be sent(int)
* -ip :target IP address(str)
Group "generic options" (--...):
* help :Display this help
So ... what's your general feeling about it ... Is there any things where you think you might want to have a CodeMonkey plugin or is it just overcomplication on top of an already-bloated compiler for an imperfect programming language ?