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/
shollrollah951 has quit [Quit: Leaving]
shritesh has joined #zig
xbat has quit [Remote host closed the connection]
karrick has joined #zig
kristoff_it has joined #zig
karrick has quit [Remote host closed the connection]
kristoff_it has quit [Ping timeout: 246 seconds]
shritesh has quit [Quit: Leaving]
kristoff_it has joined #zig
<daurnimator> hryx: huzzah, merged :D
kristoff_it has quit [Ping timeout: 245 seconds]
<hryx> \o/ your arena allocator fix got in there -- thanks for leaving that note
<daurnimator> hryx: when I get home tonight.... or, uh, maybe tomorrow; I'll rebase the linked list PR
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 258 seconds]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Quit: a_chou]
<andrewrk> hryx, I dedicate this link to your new parser code https://www.youtube.com/watch?time_continue=7384&v=Bz3eZinhyoE (2:03:04)
<daurnimator> andrewrk: so, when do we get tail call elimination in zig? :)
<hryx> OMGahh amazing
<daurnimator> andrewrk: thanks for the link.
<hryx> andrewrk: that was so much more Disney chiptune than I was expecting to experience today
<daurnimator> andrewrk: makes me think about how @tailCall and the existing @inlineCall aren't really builtins, but "magic"
<andrewrk> yeah builtins are not necessarily "functions"
<shachaf> Tail recursion seems to me like the most uninteresting type of tail call. If your function is tail-recursive you should probably just write a loop.
<daurnimator> andrewrk: I assume that tail calls would also be possible if the builtin is *not* used?
<shachaf> Other tail calls might be easier to justify.
<andrewrk> zig is allowed to do tail call optimization in general if you don't use "noinline"
<andrewrk> so the question is how to semantically guarantee it if you need that
<andrewrk> it's going to become more clear how TCO fits into the language once we have coroutines and safe recursion
<andrewrk> all that stuff is related
<andrewrk> both the existing and planned coroutine implementations, for example, depend on tail call optimization to work correctly
<shachaf> One thing I'd like is to be able to know at compile time exactly how much stack space a function can use.
<shachaf> Clearly that's related to coroutines, which allocate stack frames statically.
<andrewrk> yes
<hryx> andrewrk: back from mother's day stuff and gonna give some translate-c-2 a shot. I've never dealt with LLVM or libclang directly - any suggestions for starting point?
<shachaf> I guess I can see how the coroutine thing would be implemented in terms of tail calls.
<hryx> I was eyeing the TODO for struct decls, though it seems structs are wrapped in a "record" abstraction
<andrewrk> hryx, start with: ./zig build --build-file ../build.zig test-translate-c
<mikdusan> heh sorry andrewrk i nuked my comment in the linux renameat syscall thread. i was assuming WSL could handle SYS_renameat but doesn't appear so.
<andrewrk> hryx, and then have a look at test/translate_c.zig to see all the cool stuff that the c++ version can do
<hryx> okdk, will do. thankee
<andrewrk> then try `zig translate-c-2 foo.c` where foo.c is `void foo(void) {}` and look at src-self-hosted/translate_c.zig to see how it works
<andrewrk> next try to make it ever so slightly more complicated and see if you can make it work! if you get hooked then you know you'll be into it :)
<andrewrk> the libclang API is pretty difficult to navigate, in my opinion, but most of it is already figured out in src/translate_c.cpp
<hryx> gotcha! I'll start there and see how it goes
<shachaf> What's the most up-to-date thing to read about the coroutine plans?
shawn_ has joined #zig
shawn_ has quit [Ping timeout: 268 seconds]
<daurnimator> has anyone looked into run-time struct construction?
jevinski_ has joined #zig
jevinskie has quit [Ping timeout: 258 seconds]
kristoff_it has joined #zig
occivink has quit [Ping timeout: 250 seconds]
qazo has quit [Ping timeout: 246 seconds]
kristoff_it has quit [Ping timeout: 245 seconds]
tdc has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 255 seconds]
hio has joined #zig
kristoff_it has joined #zig
neceve has joined #zig
occivink has joined #zig
voldial has joined #zig
avoidr has quit [Quit: leaving]
very-mediocre has joined #zig
return0e has quit [Ping timeout: 246 seconds]
return0e has joined #zig
rivten has joined #zig
<rivten> hello everyone ! Sorry I've mostly been spending time here asking questions, I hope it's not too overwhelming. Anyway, I've got another one. I've got some code that I use on Linux and Windows, the same code does not work in Win32. After tracing it, it boils down to a call to std.io.readFileAlloc. Just after entering the readFileAlloc function, my Filename which was fine in the stack trace just before is now completely wrong inside the re
<rivten> Could it be possible that the function messes up the registers for the functions ? Making it point to something wrong in Win32 only ?
<rivten> it seems very unlikely, but I can very clearly press f11 to step into readFileAlloc on Visual Studio and see that the path pointer is clearly different from just before up the stack
<rivten> hmm I wonder if it's not the Align stuff that makes the difference, because the address diff between my Filename string and the path string in readFileAllocAligned is only 10 in hexa
<tgschultz> daurnimator, runtime? wouldn't that basically be an allocator with an index?
<tgschultz> hmm... address being off by 0x10 bytes sounds familiar. Someone had a mysterious ABI related issue like that a few weeks(?) ago but I don't know if they ever worked it out.
<rivten> yeah it's weird... I would need to expand my knowledge on the C ABI about rsp and rbp to investigate further
heitzmann has joined #zig
heitzmann has quit [Quit: WeeChat 2.4]
heitzmann has joined #zig
shawn_ has joined #zig
<kristoff_it> Hi all! I finally re-wrote my cuckoofilter implementation in Zig. The experience was amazing, not joking. Comptime is amazing. The last time I was this impressed is when I started using macros in lisp.
<kristoff_it> I have a couple of questions. One is about unions and switch. I have a tagged union that I give as a parameter to a function in order to change the function's behaviour. I can't make the parameter comptime because the payload is not comptime known, but the case is.
<kristoff_it> Is there a way to resolve the switch at comptime? An alternative would be to break the union into an enum and an extra parameter to the function, but I think it's more expressive to bundle optional parameters like that one in an union instead of having an extra argument that sometimes lies unused.
<kristoff_it> *and add an extra parameter
odc has quit [Ping timeout: 250 seconds]
r1b has quit [Ping timeout: 250 seconds]
dch_ has joined #zig
dch has quit [Ping timeout: 252 seconds]
dch_ is now known as dch
dembones has quit [Ping timeout: 248 seconds]
euantor has quit [Ping timeout: 250 seconds]
dembones has joined #zig
odc has joined #zig
r1b has joined #zig
euantor has joined #zig
<tgschultz> kristoff_it I don't believe there's any way (currently) to have part of a container be comptime variable and the other runtime. What you could do is change from a union to a struct and generate it using a comptime function. The struct's field type would be based on `mode` and there'd be a pub const enum definition in the struct the says which mode it is in. The function would then take `var` and switch on `@typeOf(parameter).mode`.
<tgschultz> frankly that seems a bit convoluted for this use case though.
<kristoff_it> tgschultz: thanks, I'll try to see how that looks like. Using unions to drive behavior is a pattern that is used extensively in Swift and that imo fits well into Zig
<kristoff_it> also because it allows the IDE to suggest what the options are when you are writing code.
TheLemonMan has joined #zig
<TheLemonMan> andrewrk, ping
shawn_ is now known as scientes
halosghost has joined #zig
shawn_ has joined #zig
scientes has quit [Read error: Connection reset by peer]
scientes has joined #zig
shawn_ has quit [Ping timeout: 258 seconds]
dimenus has joined #zig
johnLate has joined #zig
redj has quit [Read error: Connection reset by peer]
redj has joined #zig
Tetralux has quit [Ping timeout: 256 seconds]
rivten has quit [Ping timeout: 256 seconds]
<euantor> Is this the recommended way to add a path for tests when putting tests in a separate directory? I had a look at some example projects where others were just doing `@import("../src/foo.zig")` but that caused errors about imports outside a project root or something... https://github.com/euantorano/ip.zig/blob/master/build.zig#L11
komu has joined #zig
<johnLate> Hi, I'm trying out zig for the first time. Where can I find documentation or an overview for zig's std lib?
Zaab1t has joined #zig
<hryx> johnLate: not yet unfortunately, but aiming to fix that before the next release. for now I recommend just looking at the stdlib source
<andrewrk> hi TheLemonMan
jevinski_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Zaab1t has quit [Remote host closed the connection]
<TheLemonMan> andrewrk, would you be against having a python script to auto-generate a file containing the syscall stubs for a given architecture?
scientes has quit [Remote host closed the connection]
<TheLemonMan> that way we don't have to hand-edit everything for every OS and architecture
<andrewrk> TheLemonMan, yeah, it's gotta be in zig :)
<andrewrk> no python dep
scientes has joined #zig
<TheLemonMan> no problem, I can rewrite it in zig heh
<andrewrk> it's not so bad, zig can be relatively script-like when you run in debug mode and you can throw errors willy nilly
<TheLemonMan> here's the autogenerated file containing the stubs https://gist.github.com/LemonBoy/5371300e30f30a8bbe4460887dd8bfdd
<TheLemonMan> the biggest problem is that I don't know where to put them, ideally I'd have a #include "syscall_stubs.c" followed by a #ifdef IS_32BIT_TARGET\n#include "syscall_32bit_compat.c"\n#endif
<TheLemonMan> in the linux.zig code, but there's no way to "textually" include some files
<andrewrk> I don't think you can completely avoid hand-editing the auto generated output
<andrewrk> sometimes * pointers will be appropriate; sometimes [*]
<andrewrk> there are probably other examples
<TheLemonMan> well, the prototypes are specified in the txt file so you can use whatever pointer flavour you like
<halosghost> though, having the thing generate the list and just maintaining a patch to correct things would still be much better, I imagine
<johnLate> If I want to read command line arguments, I need something like «const args = try std.os.argsAlloc(allocator);»? But what do I use as allocator?
<andrewrk> johnLate, we have windows API to thank for having to use an allocator to deal with args
<andrewrk> you can use a fixed buffer allocator if you want to impose a maximum byte size of args
<TheLemonMan> halosghost, ideally you shouldn't have to do anything by hand, beside writing the missing stubs and the .txt file for your OS
<halosghost> that'd be cool
<andrewrk> johnLate, what allocator are you using for the rest of your app?
<andrewrk> TheLemonMan, I think this is an interesting idea, if you're willing to task the risk of it being sort of experimental and not guaranteed to be merged into master
<TheLemonMan> andrewrk, sure thing, this is the last step needed before getting zig to target 32bit ARM systems running Linux
<TheLemonMan> I'd leave the script in python tho, if you give then green light then I'll re-write it in Zig
via has quit [Remote host closed the connection]
<andrewrk> makes sense to me
<TheLemonMan> expect a draft PR in a few hours then o/
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<johnLate> So this are my very first steps with zig. I'm trying to reimplement a small command line tool written in C that opens a file and counts how many bytes are 0x00. https://ziglang.org/documentation/master/#WASI was all I found about commandline arguments so far and I tried std.heap.c_allocator.init() which didn't work, so I tried using c_allocator directly and zig crashed :(
<johnLate> (I'm using zig 0.4.0 from arch)
qazo has joined #zig
<johnLate> So I guess, while it shouldn't crash even if what I'm doing is wrong, I should first try to build zig master before I stumble around further?
<komu> JohnLate, your program works okay for me
<komu> I'm using zig from master
<kristoff_it> sholudn't the allocator be var instead of const?
<kristoff_it> uhmm no I tried, works for me too
<johnLate> Oh, it works when I try: zig run zeroscan.zig --library c -- a b c
<johnLate> just crashes with no args
<komu> I ran with: zig build-exe main.zig && ./main --name komu --age 31
<johnLate> What do you get when using 'zig run' with and without arguments?
drewr has joined #zig
<johnLate> Ah, so it seems argv[0] isn't set correctly with 0.4.0
<johnLate> My build from master just finished, works as expected now. Thanks.
<komu> cool
<johnLate> < kristoff_it> sholudn't the allocator be var instead of const? -> should it? I guessed allocator is like a reference to the real allocator object, and that reference will not change. Is it wrong to think about it this way?
<kristoff_it> no don't worry I tried your script, it works, I'm a Zig noob too :)
<tgschultz> for c_allocator there is no state so it doesn't matter if it is const or not
<tgschultz> but also, std.heap.c_allocator is a pointer, and a `const *T` != `*const T`
<komu> I'm also new to zig and have a question regarding reading files; https://gist.github.com/komuw/98111edb30262f0c34d93e3aa7f537ed
<kristoff_it> buffer is an array, while the function wants a slice
<kristoff_it> they are similar in usage, but different in nature
<kristoff_it> komu: Go has the same distinction
meheleventyone has joined #zig
<komu> my question is `os.File.getEndPos()` returns a u64; why cant be able to use its return value in `var buffer: [file_size]u8 = undefined;`
<komu> where `file_size` is return value of `getEndPos()`
<tgschultz> file_size is a runtime value
<tgschultz> array lengths are by definition comptime known
<komu> ohh, that makes sense. thanks
kristoff_it has quit [Ping timeout: 252 seconds]
komu has quit [Ping timeout: 256 seconds]
komu has joined #zig
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
stratact has quit [Quit: WeeChat 2.4]
komu has quit [Ping timeout: 256 seconds]
Zaab1t has joined #zig
Zaab1t has quit [Remote host closed the connection]
wootehfoot has joined #zig
occivink has quit [Quit: WeeChat 2.3]
<andrewrk> johnLate, for a command line application, I recommend this pattern: https://github.com/ziglang/zig/blob/08d41da916787ab0c19130dc4dc4e7b0e75c9fa8/std/special/build_runner.zig#L15-L25
<andrewrk> johnLate, and then use that allocator everywhere and don't even worry about freeing memory, let the OS do that for you.
neceve has quit [Read error: Connection reset by peer]
shawn_ has joined #zig
scientes has quit [Ping timeout: 252 seconds]
_whitelogger has joined #zig
andrewrk has quit [Ping timeout: 246 seconds]
andrewrk has joined #zig