tags 890294 + fixed-upstream thanks > Hello! Following piece of code is meant to create wrapper structures > around primitive types, simplifying creation of generic code. I attach the answer of upstream - he has fixed the code to give a better error message, and also gives a way to produce a working code. Thanks Norbert -- PREINING Norbert http://www.preining.info Accelia Inc. + JAIST + TeX Live + Debian Developer GPG: 0x860CDC13 fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13
--- Begin Message ---
- To: vectorgraphics/asymptote <asymptote@noreply.github.com>
- Cc: Norbert Preining <norbert@preining.info>, Author <author@noreply.github.com>
- Subject: Re: [vectorgraphics/asymptote] Core dump wrt to typedef and wrappers (#59)
- From: John Bowman <notifications@github.com>
- Date: Sat, 17 Feb 2018 07:03:15 +0000 (UTC)
- Message-id: <vectorgraphics/asymptote/issues/59/366422581@github.com>
- Reply-to: vectorgraphics/asymptote <reply+001a7ba55e3a4a2c9e4f893d0174b618bd9521d248cd0de392cf00000001169f95b392a169ce11b84764@reply.github.com>
- In-reply-to: <vectorgraphics/asymptote/issues/59@github.com>
- References: <vectorgraphics/asymptote/issues/59@github.com>
Hi Norbert,
Thanks for sending on this interesting example. On my system this causes an assert. I have fixed this in
commit fc0cc03 to generate a more informative error:/u/bowman/camp/test76.asy: 5.35: cannot convert 'real' to 'int' in assignment
/u/bowman/camp/test76.asy: 6.32: cannot cast 'Aint' to 'Areal'The problem is that the quote code does not get re-evaluated with the new typedefs, but this is easy to fix with two nested evals:
`void define_wrapper(string type)
{
string wrapper="A"+type;
eval("var casts=quote {"+
"public struct "+wrapper+"{ "+type+" value; };"
"typedef "+wrapper+" TWrap;"+
"typedef "+type+" TInner;"+
"public TWrap operator cast(TInner value) {
var obj=new TWrap;
obj.value=value;
return obj;
}
public TInner operator cast(TWrap obj) {
return obj.value;
}
};
eval(casts,true);",true);
}define_wrapper("int");
define_wrapper("real");Aint x;
Areal y;x.value=1;
y.value=pi;write(x.value);
write(y.value);
`—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
--- End Message ---