Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 31, 2018 std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
"CTFE Digests do not work in CTFE" That's an unfortunate limitation... why is, those things? :( |
June 01, 2018 Re: std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Thursday, 31 May 2018 at 21:29:13 UTC, Manu wrote:
> "CTFE
> Digests do not work in CTFE"
>
>
> That's an unfortunate limitation... why is, those things? :(
Because CTFE cannot do things which are technically ABI dependent.
You can work around it with code like this:
T fromBytes(T, Endianess endianess = Endianess.LittleEndian) (const ubyte[] _data)
pure {
static assert(is(T : long)); // poor man's isIntegral
T result;
static if (endianess == Endianess.LittleEndian) {
static if (T.sizeof == 4) {
result = (
_data[0] |
(_data[1] << 8) |
(_data[2] << 16) |
(_data[3] << 24)
);
} else static if (T.sizeof == 8) {
result = (
_data[0] |
(_data[1] << 8) |
(_data[2] << 16) |
(_data[3] << 24) |
(cast(ulong)_data[4] << 32UL) |
(cast(ulong)_data[5] << 40UL) |
(cast(ulong)_data[6] << 48UL) |
(cast(ulong)_data[7] << 56UL)
);
} else {
static assert(0, "only int and long are supported");
}
} else {
static assert(0, "Big Endian currently not supported");
}
return result;
}
|
June 01, 2018 Re: std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Friday, 1 June 2018 at 14:56:32 UTC, Stefan Koch wrote:
> On Thursday, 31 May 2018 at 21:29:13 UTC, Manu wrote:
>> "CTFE
>> Digests do not work in CTFE"
>>
>>
>> That's an unfortunate limitation... why is, those things? :(
>
> Because CTFE cannot do things which are technically ABI dependent.
Is there a technical reason for this? Can CTFE determine the endianness of the (target-) system?
|
June 01, 2018 Re: std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sisor | On Friday, 1 June 2018 at 18:30:34 UTC, Sisor wrote:
> On Friday, 1 June 2018 at 14:56:32 UTC, Stefan Koch wrote:
>> On Thursday, 31 May 2018 at 21:29:13 UTC, Manu wrote:
>>> "CTFE
>>> Digests do not work in CTFE"
>>>
>>>
>>> That's an unfortunate limitation... why is, those things? :(
>>
>> Because CTFE cannot do things which are technically ABI dependent.
>
> Is there a technical reason for this? Can CTFE determine the endianness of the (target-) system?
it's more then just endianness it's also alignment. I'd rather not make guarantees about that.
newCTFE for example is build in reasonably a platform agnostic way, therefore it cannot know anything target or even host specific without the programmer being explicit about it.
|
June 01, 2018 Re: std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Thursday, 31 May 2018 at 21:29:13 UTC, Manu wrote: > "CTFE > Digests do not work in CTFE" > > > That's an unfortunate limitation... why is, those things? :( just for fun: https://run.dlang.io/gist/861f14f0d776f75e0195c8910990e14c - chacha20 running at compile time :) |
June 01, 2018 Re: std.digest can't CTFE? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | https://run.dlang.io/gist/946773fd185902c7f65ba32cb3368719 - and this is poly1305, the combined source is too big for run.dlang.org. |
Copyright © 1999-2021 by the D Language Foundation