ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
noonien has joined #zig
<daurnimator>
donpdonp: btw, you can just use `i32(-1)` rather than `@intCast(i32, -1)`.
<daurnimator>
the former is fully defined and safety checked; the latter is potentially unsafe.
<daurnimator>
So I'm trying to figure out how to translate some complex structure definitions/usage to zig
<daurnimator>
and I think there's a few missing language features
<daurnimator>
lets start with: usize bytes. If the lowest bit is even, then consider it to be an aligned pointer. otherwise cast the top bit to a boolean.
<daurnimator>
Is this the right starting point? union { Ptr: align(32) *c_void, Bool: bool }
<daurnimator>
but then how can I tell zig how to pick which bit the boolean is?
<daurnimator>
or how can I tell it that the bottom bit is the "tag" bit?
<daurnimator>
s/align(32)/align(2)/
redj has quit [Read error: Connection reset by peer]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
redj has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
<Marumoto>
does linkSystemLibrary look in /usr/lib?
jevinski_ has quit [Read error: Connection reset by peer]
jevinskie has joined #zig
jevinski_ has joined #zig
jevinskie has quit [Ping timeout: 250 seconds]
wilsonk has quit [Read error: No route to host]
hooo has quit [Quit: Connection closed for inactivity]
wilsonk has joined #zig
tbodt has quit [Quit: ZNC 1.6.5+deb2build2 - http://znc.in]
<daurnimator>
Marumoto: if I recall correctly, not by default.
tbodt has joined #zig
reductum has joined #zig
darithorn has joined #zig
darithorn has quit [Quit: Leaving]
Marumoto has quit [Ping timeout: 244 seconds]
kristate has joined #zig
fsateler_ has joined #zig
fsateler has quit [Ping timeout: 250 seconds]
_whitelogger has joined #zig
Hejsil has joined #zig
<Hejsil>
daurnimator, We don't have a way to specify the location of the union tag, so I don't think a union is the right choice for your problem
<Hejsil>
I think a struct with a usize field and methods that does the conversion is the best you can do
<Hejsil>
This would allow you to write you code like this:
<Hejsil>
if (me.toBool()) |b| {} else if (me.toPtr()) |p| {} else {}
<Hejsil>
You could also convert it to a union: switch (me.toUnion) {T.Bool => |b| {}, T.Ptr => |p| {}}
<Hejsil>
me.toUnion()*
reductum has quit [Quit: WeeChat 2.3]
<daurnimator>
Hejsil: hmmm. what about this if we had anonymous unions: union { packed struct { Ptr: align(2) *cvoid, isPtr: bool }, packed struct { Bool: bool, _: u63}, tag(self: *This()) @tagType(*This()) { if (self.isPtr) { return @typeOf(self.Ptr) } else { return @typeOf(self.Bool) } } }
<Hejsil>
Well, packed struct { Ptr: align(2) *cvoid, isPtr: bool } wont work, as isPtr is a bit outside the pointers bits. Also, it seems that your tag function tries to return a type a runtime
<Hejsil>
packed union { Data: packed struct { b: bool, _: u62, isPtr: bool }, Ptr: *align(2) c_void, } could work to represent your data I think
<Hejsil>
What is this even used for. Seems like a fearly complex packing of data
<daurnimator>
Hejsil: it's a simplified example of what I'm looking at doing
<daurnimator>
Hejsil: the idea is that *most* pointers are align(4), so you can store them "inline". otherwise they are a pointer to another another area. with a tag.
<daurnimator>
one of the more interesting things in a maple tree IMO is the "sparse" format, the value idea is: {x, val1, y, val2, z }. which says that between x and y, the value is val_1, between y and z it is val_2
<daurnimator>
and the value is another tree: which can be an inline pointer, a value, or a pointer to another dense or sparse node
<daurnimator>
the size of a sparse node {w,val0,x,val1,y,val2,z} is ideally made to be the size of a cache line
<daurnimator>
and the whole thing can be made thread-safe!
slugspace has quit [Ping timeout: 240 seconds]
kristate has quit [Read error: Connection reset by peer]
kristate has joined #zig
<Hejsil>
daurnimator, i see. One thing we might want is more control over the layout of tagged unions (at least packed ones).
<Hejsil>
In case you know that your bytes are of the platforms endianess, you can just use @bytesToSlice(u32, block[0..4])[0]
steveno has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
halosghost has joined #zig
Hejsil has quit [Ping timeout: 256 seconds]
kristate has quit [Remote host closed the connection]
darithorn has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
schme245 has joined #zig
steveno has quit [Ping timeout: 268 seconds]
schme245 has quit [Ping timeout: 240 seconds]
Zaab1t has joined #zig
Avila has joined #zig
steveno has joined #zig
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
wootehfoot has joined #zig
steveno has quit [Ping timeout: 240 seconds]
MajorLag has quit [Ping timeout: 240 seconds]
MajorLag has joined #zig
MajorLag has quit [Ping timeout: 250 seconds]
<donpdonp>
here's another webasm oddity. in zig i can export fn setup() [*]const u8 {} and the function 'setup' will be in the .wasm file, where without the export it wouldnt be 'exported' into the wasm. the problem im running into is I need setup to be an export in the wasm, and its not.
MajorLag has joined #zig
Marumoto has joined #zig
<donpdonp>
ah nevermind. zig HEAD fixes it :)
schme245 has joined #zig
Zaab1t has quit [Quit: bye bye friends]
<schme245>
how do i bitshift left with a runtime value?