ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<pixelherodev> It's *awful*
<fengb> I can’t grok it. Hence I reference the old design docs which are written in English at least
<companion_cube> seems pretty similar to BNF
<companion_cube> (I mean, the same kind of notation)
<fengb> But... wasm isn’t about defining syntax
<fengb> That doesn’t help you understand the memory model
<pixelherodev> It focuses on all the wrong things
<pixelherodev> Like, it might be good for writing an *encoder* (I wouldn't know), but for a *decoder*, it's a PITA
<companion_cube> oh, I saw mostly the spec of hte bytecode format, I guess
layneson has joined #zig
<companion_cube> ah yes I was in `binary format`, duh
<pixelherodev> Whoops. Accidentallied stage2
<pixelherodev> Infinite loop looking for free space :P
<fengb> pixelherodev: maybe look at my decoder? Everything other than opcode decoding is pretty straightforward
<pixelherodev> I will, thanks
<pixelherodev> Just found myself missing goto in zig for the first time
<pixelherodev> I've got a loop that checks for either of two conditions, and restarts the whole thing if either one is true
<pixelherodev> Ended up using a while(true) which `break`s at the end and `continue :outer`s within two nested conditionals
<pixelherodev> Or I would have if that wasn't buggy :(
<pixelherodev> Okays! Got it emitting `error: NoFreeSpace` for SPU II target w/o RAM or RAM added :)
ur5us has quit [Ping timeout: 256 seconds]
_Vi has quit [Ping timeout: 256 seconds]
ur5us has joined #zig
layneson has quit [Ping timeout: 258 seconds]
<pixelherodev> And got it not breaking on x64 in the process :)
<pixelherodev> Oh god why
<pixelherodev> There's a build system for C and C++... *inspired by Cargo*
* pixelherodev shivers in revulsion
aarvay has quit [Quit: Connection closed for inactivity]
waleee-cl has quit [Quit: Connection closed for inactivity]
Nilium has quit [Remote host closed the connection]
Nilium has joined #zig
knebulae has quit [Ping timeout: 264 seconds]
<leeward> Cargo has some nice properties. Worse things exist.
<pixelherodev> leeward: [citation needed]
<pixelherodev> Name one :P
<shakesoda> pixelherodev: npm
aarvay has joined #zig
<pixelherodev> you win.
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #zig
<daurnimator> andrewrk: we should go through and change occurences of (mac)osx to macos
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
craigo has joined #zig
drewr has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 260 seconds]
_ofelas has quit [Quit: shutdown -h now]
ofelas has joined #zig
Nypsie has joined #zig
ur5us has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
<pixelherodev> daurnimator: find -exec sed?
<daurnimator> pixelherodev: a little more to it than that... but yeah
<pixelherodev> I mean, with git, you can be a bit overzealous and just fix any extras
<pixelherodev> Worst case, you `git reset --hard` and be a bit more careful with the sed on the next attempt
dermetfan has joined #zig
dermetfan has quit [Remote host closed the connection]
dermetfan has joined #zig
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
Biolunar has quit [Ping timeout: 272 seconds]
cole-h has quit [Quit: Goodbye]
Biolunar has joined #zig
dermetfan has quit [Ping timeout: 260 seconds]
dermetfan has joined #zig
marnix has joined #zig
hspak has quit [Ping timeout: 256 seconds]
marnix has quit [Ping timeout: 240 seconds]
ur5us has joined #zig
marnix has joined #zig
cren has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
Ashpool_ has joined #zig
Ashpool__ has quit [Ping timeout: 240 seconds]
_Vi has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
_Vi has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 244 seconds]
waleee-cl has joined #zig
cren has quit [Ping timeout: 256 seconds]
daex has joined #zig
st4ll1 has quit [Ping timeout: 240 seconds]
st4ll1 has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
st4ll1 has quit [Remote host closed the connection]
st4ll1 has joined #zig
tsujp has joined #zig
<tsujp> Zig zagging my way into zig
<tsujp> Ye ye
<ifreund> \o/
st4ll1 has quit [Ping timeout: 264 seconds]
st4ll1 has joined #zig
eddyb[legacy] has quit [*.net *.split]
Cadey has quit [*.net *.split]
layneson has joined #zig
fengb has quit [Remote host closed the connection]
Bastian[m] has quit [Read error: Connection reset by peer]
BaroqueLarouche has quit [Read error: Connection reset by peer]
Snektron has quit [Remote host closed the connection]
ifreund[m] has quit [Write error: Connection reset by peer]
return0e[m] has quit [Read error: Connection reset by peer]
alva has quit [Remote host closed the connection]
gpanders[m] has quit [Read error: Connection reset by peer]
hamoko[m] has quit [Read error: Connection reset by peer]
pmwhite has quit [Read error: Connection reset by peer]
Cadey has joined #zig
eddyb[legacy] has joined #zig
Snektron has joined #zig
_Vi has joined #zig
layneson has quit [Ping timeout: 256 seconds]
ifreund[m] has joined #zig
alva has joined #zig
return0e[m] has joined #zig
gpanders[m] has joined #zig
fengb has joined #zig
hamoko[m] has joined #zig
BaroqueLarouche has joined #zig
pmwhite has joined #zig
Bastian[m] has joined #zig
dingenskirchen1 has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen1 is now known as dingenskirchen
drewr has joined #zig
tsujp has quit [Remote host closed the connection]
<companion_cube> damn, dillo is pretty cool
<leeward> :)
dermetfan has quit [Ping timeout: 260 seconds]
xackus has joined #zig
KKRT has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
ask6155 has joined #zig
<ask6155> Hello!
<leeward> o/
<ask6155> I just wrote a function which gives !T but when wrote a test, like assert(func() == 34) it gives me error that 34 cannot be coerced into ErrorSet!i32
<Nypsie> That's because func() returns an errorset as it can fail. try assert(try func() == 34)
<ifreund> you can also use std.testing.expectEqual() iirc
<ask6155> yeah I had that doubt between assert an expect
<ask6155> *and
<ifreund> ask6155: in fact, you should never be using std.debug.assert in tests
<ifreund> it will be UB in release-fast/small on failure
<Nypsie> ^ good point
<ask6155> oh ok
adamkowalski has joined #zig
<adamkowalski> How do you call external processes from zig? For example if you want to call "ls" and then see if the return code was 0
<Nypsie> Maybe this is what you're looking for? https://github.com/ziglang/zig/blob/master/lib/std/child_process.zig
ask6155 has quit [Quit: Lost terminal]
opDispatch has quit [Quit: Konversation terminated!]
<ifreund> alternatively if you need more control you can fork, execve, and waitpid directly
<adamkowalski> Awesome, thanks!
dermetfan has joined #zig
cole-h has joined #zig
ronsor has joined #zig
<ronsor> hello, might anyone have any advice on exposing an allocator to a C program (i.e. implementing malloc/realloc/free using an instance of *std.mem.Allocator)?
<fengb> You’ll need to export C compatible functions
<ronsor> I've already done that
<fengb> Would it be using malloc/free? If so you should be able to link in your allocator via LD_PRELOAD
<ronsor> oh no I'm running on UEFI
<ronsor> I have created a FixedBufferAllocator
<ronsor> then I ran in to an issue, because it seems you need the original slice to use realloc, not just the pointer
<fengb> Ah yeah that’s a general problem with Zig->C allocators
<ronsor> so I tried making a struct that contains a single ?[]u8, and then putting it at the beginning of the allocated slice
<ronsor> then I add the @sizeOf() that struct
<fengb> Hmm
<ronsor> except it looks awful and I'm sure there's a better way to do it
<fengb> In general, you need an allocator implementation that's C compatible to use realloc/free
<ronsor> malloc() appears to work fine for a while, but the first time realloc() is called, I get #6 Invalid Opcode
<fengb> But thinking about it, it might be possible to have a wrapper that converts any allocator to be C compatible
<ronsor> Right now, the solution I've tried doesn't seem to work
<ronsor> using a different malloc() implementation with the C code (specifically the wasm3 interpreter with it's owned fixed heap allocator) works fine
<fengb> Yeah, Zig allocators aren't fully designed for C compatibility in mind
<ronsor> I'm curious as to why I'm getting "invalid opcode" specifically, instead of another exception
<ronsor> allocation always succeeds, but that happens when accessing the allocated memory
<fengb> Hmm that doesn't make sense
<andrewrk> ronsor, if your allocator implementation does not read the length of the freed slice, you can pass the Allocator interface fake lengths
<fengb> I think I can write a generic C compatibility allocator. But not right now since I’m at work >_>
<andrewrk> the lengths are part of the interface, but it's allocator-implementation-defined the semantics beyond that
<fengb> andrewrk: would that be useful in stdlib?
<andrewrk> what exactly?
<fengb> A wrapper allocator that can be compatible with C realloc/free
<fengb> Be able to wrap any allocator
dingenskirchen has quit [Read error: Connection reset by peer]
dingenskirchen1 has joined #zig
Ashpool_ has quit [Quit: Leaving]
<ronsor> andrewrk: so far, I've managed to store the original slice and use that for free
dingenskirchen1 is now known as dingenskirchen
<ronsor> it appears to work
marnix has quit [Ping timeout: 240 seconds]
<andrewrk> fengb, I'm not so sure. I think in this case one would want to avoid the unnecessary store/offsets and just pass 1 for the length every time
<andrewrk> oh, I see your point - if you want to use the normal zig allocators
<fengb> But that wouldn’t allow most allocators to work
<fengb> Yeah
<andrewrk> yeah I could see that being useful
<Nypsie> andrewrk: Could we have `Inst.Tag.fromOp`, similar to `Inst.Tag.fromCmpOp` that is used in cmpNumeric()? Would look cleaner than having switch statements for addBinOp(). Or perhaps you have a better way to get the IR tag from a Zir tag?
<andrewrk> we're gonna switch on the op anyway - I think it's cleaner to list them out in the main switch than to have a separate branch for it
<andrewrk> it helps to feel cleaner if you think from the perspective, "what is the computer going to do?"
<Nypsie> Ah, so you'd expect a function for each operator, rather than a more generic approach where the logic is shared?
<andrewrk> did I not push the commit yet where the logic is shared?
* andrewrk checks
<Nypsie> You did, but perhaps I misunderstood it
<andrewrk> is this what we're talking about?
<Nypsie> Here each branch has its own implementation, but the logic is very similar between the 2.
<andrewrk> ah gotcha. I'm expecting that to change to analyzeArithmetic. add, sub, and others all have the same IR type: BinOp
<andrewrk> castTag(.add) and castTag(.sub) both will cast the type to BinOp
adamkowalski has quit [Quit: Lost terminal]
<andrewrk> does that make sense?
<Nypsie> Great, that what I've been doing so far :)
<andrewrk> :)
FireFox317 has joined #zig
<andrewrk> if I understand correctly this is called "Data-Oriented Programming" where we start with the memory layouts of what will be in the heap, and then work the logic around that
<FireFox317> andrewrk, will you be streaming on self-hosted/stage2 development anytime soon? :D
<andrewrk> FireFox317, good point. I actually was thinking about streaming about the process to upgrade from llvm 10 to 11
<andrewrk> self-hosted would be another good candidate though
<Nypsie> However, if it requires runtime valuation, we use "addBinOp" to add the IR instruction, but this requires Inst.Tag, which is either .add or .sub in this case, hence requiring a switch inside analyzeArithmetic to set the correct tag. If that makes sense?
<FireFox317> is this coming up soon again? the switch from llvm 10 to 11?
<andrewrk> Nypsie, that's perfectly fine
<Nypsie> Oke great, thanks alot!
riba has joined #zig
<andrewrk> Nypsie, if you want you can even put `.add, .sub, ... => return self.analyzeArithmetic(scope, old_inst.cast(Inst.BinOp).?),
<andrewrk> FireFox317, yeah, they just cut the release/11.x branch
<andrewrk> it's probably a month or two until release but the API is now stable-ish
<FireFox317> Ah okay, im wondering how many ppl like to see this, it is something that only happends in like 6 months or so, so regarding contributions it is not so appealing as self-hosted :P
<FireFox317> Obviously most people will find it interesting for sure
<Nypsie> Ah thanks for the tip :)
<andrewrk> FireFox317, I was more thinking along the lines of if I got hit by a bus, there would at least be a tutorial of the process ;)
riba has quit [Ping timeout: 240 seconds]
layneson has joined #zig
Akuli has joined #zig
<FireFox317> Ha andrewrk, then it makes sense :P (Hopefully that won't happen lol)
<andrewrk> std.fs is getting to be quite a powerful, robust, and portable abstraction
marnix has joined #zig
KKRT has quit [Quit: KKRT]
<leeward> Woot, bug found with rr and fixed.
layneson has quit [Ping timeout: 260 seconds]
reductum has joined #zig
<danyspin97> using std.json, why root.Object.get("key") isn't optional? (zig-master version)
<leeward> Helgrind is telling me I have a data race where two threads are accessing the same region and "Locks held: none" but I'm using std.Mutex and not --single-threaded. Is this just Helgrind failing to comprehend zig mutexes? (mutices?)
<leeward> danyspin97: It looks like it does return an optional.
<pixelherodev> andrewrk: PT_LOAD is raw data, right?
Nypsie has left #zig ["Leaving"]
<danyspin97> leeward: http://ix.io/28qV
<danyspin97> what am I doing wrong?
<ifreund> danyspin97: current_type is no longer optional, you've unwrapped it with the if ( ) | |
<leeward> current_type is not optional; it's what happens if the value is not null.
<danyspin97> hmm
<danyspin97> I think I should reread the docs on the if
<leeward> if (optional) |unwrapped| { use unwrapped because it's not null } else { optional was null }
<danyspin97> but isn't the return value of get an optional?
reductum has quit [Quit: WeeChat 2.9]
<leeward> It is.
<danyspin97> so if (root_obj.get("key")) |unwrapped|
<danyspin97> should be fine
<danyspin97> shouldn't it?
<leeward> Yep, and it is.
<leeward> The error is on line 18
<leeward> current_type.?
<leeward> but current_type isn't optional
<danyspin97> okay now I see
<danyspin97> though the error reporting is wrong
<danyspin97> it says lines 17
<danyspin97> /src/Rules.zig:17:9: error:
<leeward> Yeah, it's definitely in need of improvement.
<danyspin97> thanks the explanation
<leeward> Once self-hosted is usable, work will get done on error messages.
<danyspin97> nice
marnix has quit [Ping timeout: 258 seconds]
<danyspin97> the language seems fine but I don't see advantages of using build.zig over meson
<danyspin97> i don't have testing working and I have no idea of how to enable it :/
<leeward> Testing, like running test blocks?
<danyspin97> yup
<danyspin97> I do `zig test file`
<leeward> Honestly, I don't think build.zig brings a lot to the table. Its stated reason for existing is to reduce dependencies for Zig source; since not everyone has Meson or Make or CMake or autotools already installed.
<leeward> danyspin97: This might be helpful https://github.com/ziglang/zig/wiki/Zig-Build-System
<danyspin97> it has sense for zig source
<danyspin97> but it might be good for the zig projects, imho
<danyspin97> thanks for the link!
<leeward> Though...it doesn't say how to make a test. Here's a sample that does: https://godbolt.org/z/j7cWYj
<danyspin97> do I need to create new var for every source I want to test?
<ifreund> no, you can have e.g. a test_main.zig that includes all the tests
<leeward> Hmm, I think the other method might not exist in std any more.
<danyspin97> Doesn't work though
<leeward> Time to pastebin some code, I think.
<danyspin97> http://ix.io/28su
<danyspin97> then `zig test`
<leeward> zig build test
<danyspin97> Ah, I see
<danyspin97> thanks!
<leeward> no problem
ur5us has joined #zig
FireFox317 has quit [Remote host closed the connection]
FireFox317 has joined #zig
* leeward looks at helgrind.h and valgrind.h and wishes translate-c were better at macros.
<leeward> From a comment: "Don't look too closely at them as they will rot your brain."
xackus has quit [Ping timeout: 246 seconds]
blinghound has joined #zig
Akuli has quit [Quit: Leaving]
<blinghound> is there a way I can embed a precalculated array? It takes a bit too long to just calculate at comptime, so I want to calculate it once and just embed into the executable
<leeward> @embedFile ?
<blinghound> wow that might be exactly what I'm looking for
<blinghound> I'll give it a shot, thanks!
<ifreund> andrewrk: @intCast(foo) is accepted not @intCast(_, foo) right?
<ifreund> imo the latter leads to duplicated functionality with @as()
<pixelherodev> How?
<pixelherodev> @as(_, foo) isn't valid
<ifreund> no, but @as(u8, @intCast(_, foo)) would be
<ifreund> i think it's cleaner to just get rid of the type parameter to @intCast() & co. as per the original proposal
<ifreund> and I disagree that @as() is clunky in your example by the way :P
<pixelherodev> @as(u8, @intCast(_, foo)) would be identical to @intCast(u8, @intCast(_, foo))
<pixelherodev> Both would be senseless
<andrewrk> ifreund, right. original proposal, no amendments
<pixelherodev> Unrelated, `TODO buf_read_value_bytes enum auto` gah
<ifreund> nice, it will certainly clean up a good bit of my code
<pixelherodev> Well I guess I'm never using Zig again! /s
<pixelherodev> :P
<ifreund> lol
<pixelherodev> Stage2 already has basic casting, right?
<pixelherodev> dumb question :P
<pixelherodev> I literally have the source open
<ifreund> pixelherodev: fwiw grepping through my codebase I have yet to find a place where I'd need @as(u8, @intCast(foo))
<pixelherodev> If ResultType gets added in, I'd probably end up using a metafunction for all casts
<pixelherodev> Which checks if dest type != given type
<pixelherodev> `blah = meta.intCast(u8, @ResultType(), val);` <- if type of `blah` changes, this becomes a compile error
<ifreund> that looks even clunkier :P
<pixelherodev> for sure
<pixelherodev> But it also means that changing a type *forces* you to think about all the impacts it has
<pixelherodev> In most cases, it'd mean changing the first param to the new type; in some, it might mean adjusted logi
<pixelherodev> logic*
FireFox317 has quit [Ping timeout: 256 seconds]
blinghound has quit [Remote host closed the connection]
blinghound has joined #zig
<blinghound> is there a way to cast the returned []u8 when reading a file into []f32?
<fengb> std.mem.bytesAsSlice
<blinghound> that was a whole lot easier than I was expecting
<blinghound> thanks fengb!
<fengb> Make sure you properly account for endianness
<fengb> Or just ignore big endian :P
<blinghound> will do ;)
<blinghound> this is temporary so I'm able to use @embedFile to avoid recalculating some big arrays
dermetfan has quit [Ping timeout: 260 seconds]
blinghound has quit [Remote host closed the connection]
cole-h has quit [Quit: Goodbye]
tdeo has quit [Quit: Quit]