[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding a New "primitive" Method.
I've long dreaded the day that someone wants to modify MrEd
significantly. The MrEd-MzScheme glue is one of the oldest, trickiest,
grossest parts of the system. It's long overdue for an overhaul, but we
have a few other things to overhaul first.
Anyway, to answer the meta-questions:
> # No one should write code like this. It's horrible. It's immoral.
This is the only line in the source code for xctocc that I'm happy to
defend. :)
Of course, if I did it over again, I'd turn MzScheme in a compentent
scripting language before creating MrEd, instead of the other way
around. Then there'd be no perl code in the build process.
> Should I learn this xctocc thing?
No.
> (Will I go to hell if I do?)
You shouldn't take any chances.
> Is there an alternative way to add a method to a primitive scheme class?
Not really. :(
> How long is "for now"?
Probably a good while longer.
I'm gradually cleaning up the source code to make it readable, but
currently I'm working in plt/src/mzscheme/src and the wxWindows code.
It's a long-term project.
Meanwhile, I predict significant upheaval in the implementation of
MzScheme and MrEd over the coming months. Nothing that will make MrEd
easier to modify, though.
> Will there eventually be a way for moral programmers to modify/add to
> the MrEd source?
Eventually.
----------------------------------------
Now, the painful answer to the main question:
Quoting Greg Pettyjohn:
> Suppose I wanted to write a program that looked like this:
>
> [...]
>
> (define rc (send canvas get-rc))
If you really want to add a method to the primitive canvas%, you have
correctly deduced that you want to modify some .xc[i] file in
plt/src/mred/wxs. In this case, it's wxs_cnvs.xc. Somewhere near
@ "get-dc" : wxDC! GetDC();
add:
@ m "get-rc" : void[]/CastToSO//spAnything GetRC();
Somewhere at the top, near
static void FillZero(int *a, int *b) {
*a = *b = 0;
}
add:
@MACRO CastToSO = (Scheme_Object*){x}
@MACRO spAnything = _
void *GetRC(wxDC *dc) {
... implement it, returning a Scheme_Object* ...
}
If you're using some form of Unix, wxs_cnvs.cxx will get generated by
the make process. If you're using Windows, then in plt/src/mred/wxs
yuo want to run
perl ../../mzscheme/utils/xctocc -cxx wxs_cnvs.xc
But wait --- there's more! In plt/src/mred/wrap/mred.ss, you need to
add `get-rc' to yet another wrapping layer. Look for `basic-canvas%',
and add `get-rc' in the same way as `get-dc' is already there. Then, if
you're in Unix, go to mred/wrap in your build area and run `make'. (The
normal make won't do that unless you;ve done it once before.) Using
Windows, run plt/src/mred/wrap/makewrap.bat.
For the implementation of `rc', avoid xctocc. Some other tool, like the
one described at www.dia.uniroma3.it/~scorzell might be the right
thing. Or see the "tree.cxx" example in plt/collects/mzscheme/example
and figure out how to generate the glue you want.
Matthew