Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: castto


This is true, and I've never been fully satisfied with the syntax.

The reasoning for the way it is right now is twofold.

First, types and variables live in their own separate, independent
namespaces.  There is no overloading of the call operator for casting,
and no special treatment of type names, as a result.

This is valid code, for example:

    var int : int
    int = 42

I've been putting some thought into changing it, so that defining
a type implicitly defined a 'type description' variable of the same
name. I could make that callable, although I'm not sure what I'd want
to make it do for custom types.

Second, I want casts to be at least a bit ugly. I find that I mostly
end up using them for marshalling values, and I'd rather have that
wrapped up in a standard function. I actually thought that I already
had 'packle/unpackle/packbe/unpackbe functions already, but it seems
that I don't. They'd be welcome additions to the standard library.

(And they'd be so much more usable when I get inlining working.
Especially cross-modules.)

On Tue, 25 Nov 2014 22:55:22 +0100
Daniel Cegiełka <daniel.cegielka@xxxxxxxxx> wrote:

> It seems that 'castto' in Go way is much more readable and compact:
> 
>   /* myrdin */
>   j0  = (c[0] castto(uint32))
>   j0 |= (c[1] castto(uint32)) << 8
>   j0 |= (c[2] castto(uint32)) << 16
>   j0 |= (c[3] castto(uint32)) << 24
> 
>   // Go
>   j0  = uint32(c[0])
>   j0 |= uint32(c[1]) << 8
>   j0 |= uint32(c[2]) << 16
>   j0 |= uint32(c[3]) << 24
> 
>   /* myrdin */
>   out[0] = x0 castto(byte)
>   out[1] = (x0 >> 8) castto(byte)
>   out[2] = (x0 >> 16) castto(byte)
>   out[3] = (x0 >> 24)    castto(byte)
> 
>   // Go
>   out[0] = byte(x0)
>   out[1] = byte(x0 >> 8)
>   out[2] = byte(x0 >> 16)
>   out[3] = byte(x0 >> 24)
> 
> btw. code from libcrypto/chacha20.myr... still incomplete :)
> 
> Daniel
> 


-- 
Ori Bernstein <ori@xxxxxxxxxxxxxx>

References:
casttoDaniel Cegiełka <daniel.cegielka@xxxxxxxxx>