[m-dev.] lcmc for high-level data
Ian MacLarty
maclarty at csse.unimelb.edu.au
Tue Sep 8 15:29:58 AEST 2009
On Tue, Sep 8, 2009 at 1:50 PM, Peter Wang<novalazy at gmail.com> wrote:
> On 2009-09-08, Zoltan Somogyi <zs at csse.unimelb.edu.au> wrote:
>> On 07-Sep-2009, Peter Hawkins <hawkinsp at cs.stanford.edu> wrote:
>> > Not knowing the specifics of the transformation in question, rather
>> > than using reflection, couldn't you do add a method to the object
>> > whose field is to be updated along the lines of:
>> >
>> > void updateField(int field_number, Object o) {
>> > switch (field_number) {
>> > case 0: this.a = (TypeA)o; break;
>> > case 1: this.b = (TypeB)o; break;
>> > ...
>> > }
>> > }
>> >
>> > The transformation needs to ensure that the appropriate field number
>> > is passed from caller to callee together with the object base pointer,
>> > and the callee should call the updateField method to write to the
>> > field.
>>
>> My guess is that Peter Wang was talking about this exact scheme of code
>> generaton.
>
> No, I actually was talking about reflection in the footnote.
>
> The updateField() scheme requires both the object base pointer and field
> number to be passed in, but the number of variant procedures would not
> increase.
>
Could you add an interface like the following:
interface Ref {
public void set(Object o);
}
Then, at the point you want to take the address of the field you
construct an anonymous instance of this interface and use that:
Ref r = new Ref() {
public void set(Object o) {
obj.field = (FieldType)o;
}
};
obj would need to be final. If it's not already final you could
always create a new final reference to it to use in Ref.
Also, have you had a look at the sun.misc.Unsafe class? It may
provide some useful features, but I'm not sure.
Ian.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list