Reimplementing the bulk of std.meta iteratively
Stefan Koch
uplink.coder at gmail.com
Thu Oct 1 09:02:11 UTC 2020
On Thursday, 1 October 2020 at 08:56:58 UTC, Walter Bright wrote:
>
> I had looked into this. Unfortunately, many aspects of types
> are simply too complex to try and represent at run time. For
> example, is type T1 implicitly convertible to T2? This
> seemingly simple question is very complex. Yes, `alias this`
> makes it much worse :-/
>
The my latest post please!
The example on type functions with the conversion matrix.
This is all you need:
override void visit(IsExp e)
{
auto targe = e.targ.isTypeExpression();
if(!targe)
{
e.error("is expressions within type functions may
only use type expressions");
result = ErrorExp.get();
return ;
}
auto targ = ctfeInterpret(targe.exp);
auto te = targ.isTypeExp();
result = IntegerExp.createBool(te && te.type &&
te.type.ty != Terror);
auto tspece = e.tspec ? e.tspec.isTypeExpression() : null;
auto tspec = tspece ? ctfeInterpret(tspece.exp) : null;
auto ts = tspec ? tspec.isTypeExp() : null;
// handling of == and &&
// See IsExp handling in expressionsem.d
if (e.tspec && !e.id && !(e.parameters &&
e.parameters.dim))
{
if (e.tok == TOK.colon)
{
result =
IntegerExp.createBool(te.type.implicitConvTo(ts.type) !=
MATCH.nomatch);
}
else if(e.tok == TOK.equal)
{
result =
IntegerExp.createBool(te.type.equals(ts.type));
}
}
else if (e.tok2 != TOK.reserved)
{
e.error("Complex pattern matching forms of is
expressions are not supported in TypeFunctions yet");
result = IntegerExp.createBool(false);
}
}
More information about the Digitalmars-d
mailing list