ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
shmibs has quit [Quit: leaving =o]
shmibs has joined #zig
<andrewrk> daurnimator, I've been thinking about your lua demo. I'm typing up a proposal
<benjikun> what was that for?
<andrewrk> daurnimator demoed how the same lua functions can be used in a blocking or async manner
<andrewrk> so that you can write event-loop-or-blocking-agnostic code
<benjikun> oh I see
<benjikun> andrewrk: I'm sorry to pester you about adding to wikipedia again, but do you have any ideas about what languages I should add to a `influenced by`
<benjikun> I'm thinking: C (obviously) for manual memory management ideas, go for defer
<benjikun> I'm sure there are specific things coming from C++ and whatnot too
<benjikun> just wanna make sure there is more places for people googling 'zig' to refer to, wikipedia being one
<benjikun> I'm going to slowly start adding more to rosettacode and change things that need to be changed overtime with language changes
oconnor0 has joined #zig
<benjikun> ooh and I can add jai to the influenced by section for the allocators stuff
<andrewrk> benjikun, C, Rust & Go for syntax, nodejs for @import/async/await, llvm ir for builtins and other misc semantics. standard library influenced by musl libc and wine
<benjikun> tyvm I'll add em
<andrewrk> I'd say jia for compile time function evaluation, even though I ended up going a very different direction with it
<andrewrk> error handling inspired by `on error resume next` from VB6
<andrewrk> just kidding\
<benjikun> lmao
<benjikun> I unironically used VB6 at one point
<andrewrk> it was my first programming language
<benjikun> forever ago, and then VB.net & C#
<benjikun> those were some of my starters too :p
<presiden> <andrewrk> error handling inspired by `on error resume next` from VB6
<presiden> ^ qotd
litonico has joined #zig
<litonico> hey friends, i'm new to zig as of today! anyone up for a few beginner's questions?
<benjikun> always
<benjikun> I'll try, at least :)
<litonico> awesome, thank you!
<litonico> ok, first off, i've tried to create a static array of functions inside a method. doing that particular thing has raised a few questions:
<litonico> what is a 'bound function' versus a plain 'ol function?
<litonico> (i see this in the error: `expected type 'fn(MyStruct) void', found '(bound fn(MyStruct) void)'`)
<litonico> (when writing `const list_of_fns = [](fn(MyStruct)void) { self.my_function }`)
<andrewrk> litonico, try using `MyStruct.my_function` rather than `self.my_function`
<litonico> it works! thank you
<andrewrk> mostly the only thing you can do with a bound function is call it
<andrewrk> it's an implementation detail of method calls
<benjikun> what makes it bounded?
<andrewrk> a.b syntax
<andrewrk> where `a` is not a type
<benjikun> oh I see
<litonico> i'm sorry, you may have to break this down a little further for me
<litonico> the 'bound' function is different than a pointer to the function on the type? (this question may not make sense, because i'm still not solid on how zig structs/methods work)
<andrewrk> I think it would start by ignoring the idea of bound functions, and ignoring the idea of methods. All we have are normal functions
<andrewrk> *it would help to start by
<andrewrk> now, introduce the idea that you can put a function inside a struct, and refer to it with MyStruct.my_function
<andrewrk> still, nothing special about functions or function pointers
wootehfoot has quit [Read error: Connection reset by peer]
<litonico> ok, all clear so far
<andrewrk> now, introduce the idea that you can use this syntax: `a.b()` which is syntax sugar for `@typeOf(a).b(a)`
<andrewrk> the fact that the expression `a.b` evaluates to a "bound function" is an implementation detail which you can completely ignore
<litonico> going to run some code for a sec to make sure my next question is correct
<litonico> ok
<litonico> i am confused then by, if the syntactic sugar is `@typeOf(a).b(a)`, why it works to call MyStruct.my_function, and not self.my_function, rather than the opposite:
<benjikun> `self` is an instance of the type MyStruct
<litonico> yes!
<litonico> shouldn't that then expand to
<litonico> MyStruct.my_function(an_instance_of_MyStruct)
<litonico> which seems correct?
<andrewrk> yes exactly
<andrewrk> only simple method calls work. you can't put a bound function in a list
<benjikun> hmmm
<litonico> oh, i finally get it
<litonico> thank you!
<litonico> i'll be back another day w/ more questions, i'm sure. thank you for your time!
litonico has left #zig [#zig]
<daurnimator> andrewrk: yay :)
<daurnimator> andrewrk: let me know if you need any help or another demo
<andrewrk> daurnimator, I almost finished typing it up. I'm interested in your feedback
<daurnimator> andrewrk: also FWIW... I don't like "bound functions". it's one of the *most* confusing things in Javascript and a source of bug reports I get weekly...
<andrewrk> zig doesn't really have bound functions. it's just a implementation detail of syntax sugar
<daurnimator> I know :)
<daurnimator> lua 'solves' this with the `:` 'operator'. a.b() is just calling a.b. a:b() is the same as a.b(a)
<andrewrk> we might change the syntax for function pointer calls. I think that would kill bound functions
<daurnimator> andrewrk: I have a lot I want to talk about but don't want to waste your time/distract you. :P
<daurnimator> andrewrk: will be enthusiastic to read over this proposal.
<benjikun> where did you learn lua from originally?
<daurnimator> andrewrk: how goes copy ellison?
<daurnimator> benjikun: me? I learned it back in ~2005 due to writing homebrew for the PSP.
<benjikun> ah
<andrewrk> copy elision - slow but steady progress
<benjikun> I remember using it in Gmod and roblox lmao
<andrewrk> if you look at my commit messages in the PR, you can see some code snippets and corresponding LLVM. compare those to master branch and you'll see some big improvements
<benjikun> forever ago, and config files
<andrewrk> I sadly spent a few hours today chasing down a regression that scared the shit out of me, but it turned out to be an LLVM quirk, easy to work around
<daurnimator> benjikun: I use lua all the time, both for work and fun.
<andrewrk> change the i != 10 to i < 10 and observe the difference
<daurnimator> andrewrk: huh? what difference
<daurnimator> I just see `ret`
<benjikun> it breaks immediately
<andrewrk> what do you see when it says i != 10?
<daurnimator> andrewrk: ret
<MajorLag> i != 10 should be a loop
<daurnimator> andrewrk: though your original link uses i == 1
<andrewrk> I mean in the for line
<andrewrk> for (unsigned i = 0; i != 10; i += 1) vs for (unsigned i = 0; i < 10; i += 1)
<andrewrk> plz tell me I'm not crazy - I just tried this in private browsing mode
<benjikun> is the loop not working at all with `i<10`?
<MajorLag> with != 10 I see a loop. with i < 10 you just get ret, I imagine i is set to literal 1
<MajorLag> I imagine because i is set to literal 1
<benjikun> why?
<andrewrk> just `ret` is the correct optimization
<andrewrk> note that gcc finds this answer
<MajorLag> i is < 10, this is guaranteed.
<andrewrk> msvc doesn't find it either way
<benjikun> oh I understand now I think
<daurnimator> andrewrk: yeah I see it now
<benjikun> so just a matter of compiler optimizations
<andrewrk> right. I had changed from i < N, to i != N, in for loops, in the copy elision branch, and I was worried that it was the copy elision code that was worse, but it was just this one thing
<andrewrk> copy elision code is much better :)
<benjikun> woohoo
<benjikun> I'm happy zig is taking the decentralized approach for the future package manager
<daurnimator> andrewrk: so I have a different question: in zig, is it possible to attach metadata to a slice? Internally you obviously keep the length, but what if I want to store other data, e.g. "isValidUtf8" (related to the utf16/wtf8 issue). or to pick another issue that already exists "noNulls"
<andrewrk> daurnimator, that is not currently possible
<MajorLag> isn't that what structs are for?
<benjikun> you could just wrap it with structs, for sure
<benjikun> s/structs/a struct/
<daurnimator> Also related to the utf16/utf8 issue: I wonder if we just need a type "FilePath" that is distinct from u8[]
<daurnimator> that way we don't do needless conversions if you're going from e.g. a directory iterator to opening files.
<MajorLag> I've been thinking anyone writing a new OS should just make paths a `[][]const u8`
<benjikun> I wouldn't oppose that being in std/io daurnimator
<daurnimator> MajorLag: array of arrays??
<MajorLag> slice of slices actually. each slice is the name of a directory in the path. No separator characer, all bytes valid.
<daurnimator> though I'm afraid FilePath might end up being a middling solution that makes things more difficult while leaving some corner cases unhandled. e.g. I think different filesystems have different limitations: some are case insensitive, windows will blow up if you use the non \\??\ syntax and use filenames like NUL
<benjikun> true
<benjikun> hard to tell if it's worth including in stdlib
<benjikun> with zig's goal of maintaining its small size
<andrewrk> MajorLag, what about how to represent paths to users?
<andrewrk> daurnimator, stick around if you can, I'm just finishing up the last section
<andrewrk> of the I/O proposal
<daurnimator> andrewrk: will do
<MajorLag> Not an issue in a GUI. For commandline, reserve a special graphic that can only be printed by the kernel.
<MajorLag> or something
<daurnimator> If you all want to be distracted, go check out arcan/durden. It's a project to write a graphics stack (to replace e.g. xorg/wayland). I really like it...... eventually I'll do some zig stuff with it
<MajorLag> I've been keeping an eye on it.
oconnor0 has quit [Ping timeout: 268 seconds]
<benjikun> its logo looks like the anarchy symbol
<benjikun> "game engine"
<benjikun> hmm
<benjikun> looks cool
<benjikun> dang durden looks nice
<benjikun> I've been stuck on i3 for years
<daurnimator> the next release of arcan is finally looking usable: it brings wayland seamless support. so you'll be able to run normal wayland and X (via Xwayland) applications
<benjikun> neat
<andrewrk> is there a page that describes its goals/comparison to wayland
hio has joined #zig
<MajorLag> There's some blog entries describing the problems they see with wayland and how they're different, IIRC.
<hio> Hi, is it possible (in the language) to read JSON into a struct like Newtonsoft in c# does or java in GSON? I mean automatically, without having to assign fields myself
<daurnimator> andrewrk: not in one place.
<andrewrk> hio, I don't remember where the status on that is, but I think the compile time reflection features of zig are good enough to implement that
<andrewrk> MajorLag probably knows what the current roadblocks to that are better than me, actually
<benjikun> andrewrk: Despite being primarily about arcan v. X11, this post goes over some differences between it and wayland too https://arcan-fe.com/2018/10/17/arcan-versus-xorg-approaching-feature-parity/
<MajorLag> I think it is maybe possible, but with existing comptime it's a bit complicated. It wouldn't be struct, since we can't generate arbitrary new struct fields at comptime, but it could be something similar to Hejsil's userland tuple implementation.
<andrewrk> I would say that is in scope though- parsing json into a struct is a valid use case of zig
<daurnimator> If no one has done that with json yet then I might play with it now
<benjikun> I wanna help more lol
<hio> cool, that is good to hear. One of the most needlessly long C code that I've ever written was when I had to parse JSON.
<benjikun> I've just been writing small filetype parsing libs
<MajorLag> We have a JSON implementation don't we? It just doesn't create structs.
<daurnimator> hio: https://25thandclement.com/~william/projects/json.c.html takes an interesting approach
<benjikun> MajorLag: yes
<hio> yeah I saw that daurnimator but the problem with that is that when the JSON changes, you have to correct all these paths inside strings where you dont get IDE help
<daurnimator> hio: the problem with converting to structs is that in many cases it results in pointless copying.
<hio> that's why having it as a language feature is important in my opinion, whether it be full struct creation or just a much more convenient sort of dynamic syntax for going down an arbitrary object tree in general
<daurnimator> hio: we have the dynamic going down the object tree.
<hio> how do you mean?
<daurnimator> What *could* be useful though is converting an (almost) arbitrary struct to json. lazy serialisation for the masses
shmibs has left #zig ["WeeChat 2.3"]
oconnor0 has joined #zig
<benjikun> yea that'd be cool
<benjikun> I'm not sure how you could do that currently
<daurnimator> benjikun: I'm going to give it a try now
<MajorLag> I have an idea how the feature could work without going full @reify: @addField(Prototype: type, field: []const u8, FieldType: type) type. Keep a var S = type while you parse and keep replacing it with the new type generated by @addField.
<benjikun> lmk how it goes
<hio> it doesnt show the harder part when it becomes really nested. Like accessing the 5th item in the json array or iterating over the json array in general, or the nested object. But yeah it's not terrible
<hio> but imagine if I have to do that on a 5mb json file... having to specify the subparts as "string" will give me no intellisense when I type it out
<daurnimator> What is the syntax for creating a new var of a new type + initializing it? something like: var foo = struct {x: u32}({x=42});
<andrewrk> oh sorry this isn't an answer to your question, this is the proposal I just wrote up
<andrewrk> struct {x: u32}{.x = 42}
<daurnimator> andrewrk: thanks and thanks. will review now
<daurnimator> andrewrk: I'm not sure you understood it entirely
<daurnimator> andrewrk: the primitive isn't "tell main loop to do thing"
<daurnimator> andrewrk: but should be "resume me on condition X"
<andrewrk> this is not a proposal to model zig coroutines like lua's
<daurnimator> where X might be that an fd becomes writable, or that a futex is readable, or whatever your event loop wants to support
<andrewrk> oh, I see, I should have picked a different example than a file system operation
<andrewrk> it is as you say, however file system operations must be queued on a special purpose thread
<andrewrk> so that's the "nonblocking". for a different thing such as a socket it would be suspend { event_loop.resumeMeWhenFdIsReady(socket_fd, @handle()) }
<daurnimator> andrewrk: right. so the code should probably be "h = createAsyncIoOperation(); loop.waitforiocompletion(h);"
<andrewrk> what are you trying to solve?
<daurnimator> andrewrk: that the primitive should be "wait for event" not "do thing and get back to me"
<andrewrk> I don't see what you are trying to distinguish between
<andrewrk> in english those sound like the same thing to me
<andrewrk> in my examples, it involves the coroutine putting its handle into the e.g. epoll set, and then suspending, to be resumed when the epoll fd becomes active
<daurnimator> okay lets come back to this point later
<andrewrk> are you in agreement with the main goal? "ability to write code that is agnostic of blocking vs async I/O"
<daurnimator> yes
<daurnimator> different point: I think the io_mode thing is complicated and unnecessary
<andrewrk> let's discuss on the issue
<daurnimator> trying to organise my thoughts...
reductum has joined #zig
reductum has quit [Quit: WeeChat 2.3]
JinShil has joined #zig
hio has quit [Quit: Connection closed for inactivity]
<JinShil> Hello. I'm trying to port a D program to Zig (first Zig program) and I need to call some Windows API functions, specifically `SetWindowsHookEx`. I didn't see that in `std/os/windows`.
<JinShil> In fact `std/os/windows` looks pretty light. What's the plan there? Does it just need to be filled out with `user32` and others?
<JinShil> Or does `std/os/windows` only contain what's needed to support standard library functionality on Windows?
<hryx> JinShil: is SetWindowsHookEx a plain C function you can call by including a .h file?
<benjikun> Isn't that just in some .dll that you can include?
<JinShil> Yeah, I'm pretty sure I can get it working by just doing the work myself. My question was really to make a contribution to Zig. That is, if I'm going to go through the work of writing a zig FFI, I might as well submit a PR to the zig repository. But I'm not sure if that's the intent with `std/os/windows`
<JinShil> `SetWindowsHookEx` comes from user32.dll
<benjikun> You can just include `user32.dll` and it will
<benjikun> yeah
<JinShil> Ok, so I think I can do `@cInclude("windows.h");` or whatever the .h file is.
<hryx> hm, I dunno what the scope of the std/os modules are. you can definitely submit an issue to see if it would be accepted into the stdlib
<JinShil> Then link with user32.dll, right?
<JinShil> Or is `@cInclude("user32.dll");` a thing in zig?
<hryx> you were right the first time, @cInclude("whatever.h")
<benjikun> there is also `windowsLoadDll` in std/os
<benjikun> I've never used it, though
<benjikun> `pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8)`
<hryx> benjikun: I can't find that, where is it?
<hryx> it sounds like runtime loading though, not dynamic linking
<benjikun> oh, true
<hryx> but TIL, thanks
<JinShil> Thanks folks giving a few things a try.
<daurnimator> andrewrk: okay.. I replied in that issue. Hopefully my thoughts are coherant
<daurnimator> Yes I did just spend 3 hours composing that reply >.<
<benjikun> daurnimator: were you doing that all this time
<benjikun> holy
<benjikun> dedication
<hryx> d.a.n.g.
<daurnimator> Now time to walk the dog
<benjikun> lol
<JinShil> How do I give the zig compier an include path for resolving `#include` statements in a `@cInclude`d C file?
<benjikun> `--library yadayada`
<benjikun> or you can add it in a build.zig file if you want
<JinShil> That'd be cool to put it in a zig source file, but one thing at a time. --library looks like a "link" argument not an "include" flag.
<benjikun> Do you mean like the `-I` gcc flag
<hryx> -isystem [dir] add additional search path for other .h files
<hryx> according to `zig help`
<JinShil> ah, that's it. Thanks.
<benjikun> sorry for wrong answer
<JinShil> No worries. Happy to have the help.
<hryx> nah benji
<benjikun> hryx: I was lookin at your website
<benjikun> cool music
<hryx> aw shux, thanks!
<benjikun> I enjoyed listening to a lot of it :)
<hryx> <3
<hryx> releasing some more in 2019
<benjikun> chiptune or some other style?
reductum has joined #zig
<hryx> one or two (or three?) soundtracks - some pseudo-chiptune, some not at all
<benjikun> interesting
<benjikun> looking forward to giving it a listen :p
_whitelogger has joined #zig
<hryx> or if it's an optional return type (signified with a "?") or errable type (signified with "!"), you'd need to handle those
<JinShil> hryx. Thanks.
<hryx> JinShil: sure thing - looks like the IRC logger went offline for a sec, so let me know if you missed any of that
<daurnimator> benjikun: thoughts on my reply?
<daurnimator> hryx: ^?
<hryx> I'll peep it daurnimator
<hryx> I'm no async smartypants tho
<hryx> daurnimator: It looks well thought-out. Showing language and stdlib proposals will surely help with feedback. I admit the finer points go over my head because I have limited experience with coroutines
<daurnimator> hryx: this isn't a bad starting point: I don't think any prior knowledge is required
<hryx> Here you write "some code will *need* an event loop". I don't understand exactly what you mean
<JinShil> zig build-exe main.zig -isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\" --library-path "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\x86\" --library user32
<JinShil> Unexpected extra parameter: Files
<JinShil> It looks like --library-path doesn't like spaces in the directory.
<JinShil> Is there anything I can do about that?
<hryx> JinShil, your -- flags need to go before the argument (main.zig)
<hryx> .....I think
<daurnimator> hryx: e.g. if you want to create a promise library that includes a call `myPromise.wait()`. then you probably want it to be an error to call it outside of an event loop
<JinShil> zig build-exe -isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\" --library-path "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\x86\" main.zig
<JinShil> Unexpected extra parameter: (x86)\Windows
<JinShil> I still think it's struggling with the spaces
<hryx> hmmm that looks like it should work. this is the stock windows cmd shell?
<hryx> I dunno the escaping rules but that seems ok
<hryx> daurnimator: interesting, I'll have to watch the discussion unfold and learn from it :>
<JinShil> hryx, Tried generic windows shell and power shell. Same result.
<hryx> JinShil: from src/main.cpp, it looks like -isystem simply passes the argument to clang. Now I'm not sure about this, but clang may be splitting that string at spaces, even if your shell (and zig) passed it as a single arg.
<hryx> as a last resort, try prepending the spaces with \ or \\ (not sure which)
<hryx> failing that, someone more familiar with LLVM or Windows would be better suited to help troubleshoot than me
<hryx> I don't know what argument processing clang does but you could also try -isystm "'C:\Program Files (x86)...'" (with double AND single quotes around the path)
<JinShil> This worked: zig build-exe main.zig --library "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x64\User32.Lib"
<JinShil> Apparently I didn't need -isystem, but I don't know how it was able to locate my imported windows.h
porky11 has joined #zig
<hryx> straight up xmas miracle
<JinShil> lol
<daurnimator> expected type 'fn(*Buffer, []const u8) anyerror!void', found '(bound fn(*Buffer, []const u8) @typeOf(Buffer_append).ReturnType.ErrorSet!void)
<daurnimator> ^ what should I be using there?
<daurnimator> I guess @typeOf(Buffer.append).ReturnType.ErrorSet works
reductum has quit [Quit: WeeChat 2.3]
<JinShil> `WinUser.GetMessage(&msg, null, 0, 0)` --> error: expected type '?[*]struct_tagMSG', found '*struct_tagMSG'
<JinShil> What's that telling me?
<JinShil> `msg` is a type of `struct_tagMSG`
<JinShil> `msg` is variable of type `struct_tagMSG`
<JinShil> Declaring `msg` as `var msg: ?[*]WinUser.MSG = null;` did the trick, but from what I can tell that just allocates enough memory for the pointer, not enough for the entire `WinUser.MSG` struct.
<hryx> JinShil: You are right that the underlying type (child type) is `struct_tagMSG`. Are you familiar with what these prefixes mean: `?[*]`
<hryx> In zig, declaring a variable of type `?T` does not mean it's a pointer, it means `a T or maybe not a T`
<JinShil> My understanding is that `?` means optional (i.e. may be `null`), correct?
<hryx> `?*T` is close to the C equivalent of a pointer which may be NULL, but in zig the pointer itself is guaranteed to never be null. that's why there is `?`
<hryx> yep, but ? doesn't mean "null pointer", as in address 0x0
<JinShil> Ok, then what's the C equivalent of [*]? Would that be a double pointer (e.g. void**)?
<hryx> I'm out of my league here, but I think that `?T` actually holds enough space for T plus a flag saying if it is NULL or not
<daurnimator> Does std.fmt not handle comptime int?
<JinShil> Ah, interesting (re-reading the docs with that understanding).
<hryx> anyway, the reason you have all this crazy crap `?[*]` is because: since something was translated from a C pointer, we don't know if it's null (so we add ?), and it could either be a pointer to a single object OR any array (so we add [] around *)
<hryx> yeah JinShil search the docs for [*] -- I admit I haven't done much zig-C interation yet so I hope I'm not being confusing!
<JinShil> hryx, you've been quite helpful. Thanks.
<daurnimator> hio, benjikun, andrewrk, MajorLag: json serializer play-thing I promised earlier: https://gist.github.com/daurnimator/9eb082f126a4d0394a1dd9d4590d9d93
<hryx> daurnimator: any specific function in std.fmt? what output are you seeing?
<daurnimator> hryx: formatIntValue. I get: /usr/lib/zig/std/fmt/index.zig:683:23: error: type 'comptime_int' does not support field access
<hryx> ooooh interesting. formatIntValue calls formatInt on line 683. Then @typeOf(value).is_signed -- the .is_signed is triggering a "field access"
<hryx> so maybe comptime_int does not support is_signed
<hryx> this might be a bug
<hryx> just going off my spidey senses here
<hryx> two relevant lines in the compiler which print that error, both in ir.cpp https://github.com/ziglang/zig/blob/master/src/ir.cpp#L14996
davr0s has joined #zig
errpr has quit [Ping timeout: 252 seconds]
wootehfoot has joined #zig
<JinShil> Does Zig (or will Zig) have anything to ensure compile-time memory safety. e.g. Rust's borrow checker or D's `scope` and `return` lifetime annotations?
<JinShil> I mean verify memory-safety at compile-time.
<hryx> JinShil: That kind of analysis doesn't happen currently, and I believe that Andrew has stated that something like Rust's borrow checker is out of scope for Zig.
<JinShil> :-(
<hryx> The language is evolving so nothing is quite set in stone, but closed github issues may reveal which specific ideas have been rejected previously
<hryx> Zig is more like C without the horrible headaches -- in the sense that the programmer promises to handle (de)allocation
<hryx> I hope that isn't discouraging though. Zig is almost euphoric when you embrace its balance of power, safety, and simplicity.
<JinShil> Well it is quite discouraging, but maybe I don't get it. What are Zig's "safety" features?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
JinShil has quit [Quit: Leaving]
<daurnimator> Can you add information to zig error messages?
Hejsil has joined #zig
hio has joined #zig
<hio> this error makes no sense to me: "error: incompatible types: '[22]u8' and '[]u8'"
wootehfoot has quit [Read error: Connection reset by peer]
<hio> `var chars = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch "bla";`
<hio> if i do "bla"[0..2] it works but I get a different error: `unable to determine libc lib path: executing C compiler command failed`
<Hejsil> "bla" is type [N]u8 (array of N items), and std.io.readFileAlloc returns []u8 (slice to mutable data). Arrays do implicitly cast to []u8.
<hio> that's what I expected, that it would cast implicitly but then why is there an error unless I make it into a slice
<Hejsil> const __global_bla = "bla"; var chars = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch __global_bla;
<Hejsil> Because your code is the same as what I just wrote
<Hejsil> And __global_bla is const, so you can't take a mutable slice to it
<Hejsil> when you do "bla"[0..], you get a []const u8, and []u8 casts to []const u8
<Hejsil> And arrays casts to []const u8 too
<hio> yes, your code is the same and it also doesnt work. But you said it should cast implicitly? I still get "error: incompatible types: '[3]u8' and '[]u8'"
<Hejsil> No, my example is just to make it more clear why it doesn't work
<Hejsil> [N]u8 -> []const u8. [N]u8 does not cast to []u8
<hio> oh okay, dont you think that this should automatically convert? to me [3]u8 and []u8 really dont look different enough to justify giving out a compiler error
<Hejsil> They are very different types though
<Hejsil> Zig gives you the const slice for free, because it is a lot safer than then mutable one
<Hejsil> So you have to be explicit about it, when you want to mutate it
<Hejsil> Do you want @typeOf(chars) to be []u8 or []const u8, btw?
<hio> I generally want as little const pollution as possible, to me this is just annoying
<Hejsil> Then this is probably what you want: var bla = "bla"; var chars = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch bla[0..];
<Hejsil> Or maybe this is probably the most correct way (so you can free chars regardless of error)
<Hejsil> var chars = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch try mem.dupe(u8, "bla"); defer a.free(chars);
<Hejsil> But idk what you're trying to do
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<daurnimator> Hejsil: what if you wanted the result to be const?
<daurnimator> ==> how do you cast the result of readFileAlloc to const while doing the catch as well?
<Hejsil> var chars = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch "bla"[0..]; will get you a []const u8
<Hejsil> because @typeOf("bla"[0..]) == []const u8
<Hejsil> and []u8 -> []const u8
<Hejsil> I think copy-elision will allow this: var chars: []const u8 = std.io.readFileAlloc(a, "/home/pc/test/myclass.dart") catch "bla";
<Hejsil> Which is a lot cleaner
davr0s has joined #zig
<andrewrk> Hejsil, the problem with that is you don't know what to defer for cleanup on the next line
<MajorLag> hryx, I think the idea is to eventually remove the type.field method of getting bit_count, is_signed, etc. in favor of using std.meta. To that end, a PR I did recently includes adding 'std.meta.trait.isSignedInt/isUnsignedInt', which works with comptime_int. I don't know if it will be as simple a fix as replacing that one piece of code, but it could be.
<Hejsil> andrewrk, ofc. I just mostly decided to look over the fact of freeing chars because it wasn't really part of the question
<andrewrk> fair
<Hejsil> And he could use an arena for that
<andrewrk> good point
<daurnimator> andrewrk: I'm about to head to bed now. Anything questions you have now before I do?
<andrewrk> daurnimator, nope but I should have a response for you when you wake up
<andrewrk> thanks for taking the time to make that comment
oconnor0 has quit [Ping timeout: 268 seconds]
<daurnimator> andrewrk: I don't thinK I was super clear in what I said. hopefully the psuedo code speaks for itself.
oconnor0 has joined #zig
<andrewrk> I'm probably going to ask some follow up questions - it seems like we have different ideas of how this would be implemented
<daurnimator> also I just read about @newStackCall. my example can probably be implemented more than I thought....
<andrewrk> I think you're advocating for stackful coroutines and I'm advocating for stackless coroutines
<daurnimator> yeah I am currently advocating stackful ones
<andrewrk> I think that's the fundamental disconnect. maybe I need to address that question directly in the proposal
<daurnimator> perhaps you could post your rationale of stackless vs stackful?
chewzerita has joined #zig
errpr has joined #zig
porky11 has quit [Ping timeout: 252 seconds]
chewzeri1a has joined #zig
oconnor0 has quit [Ping timeout: 268 seconds]
oconnor0 has joined #zig
oconnor0 has quit [Quit: Quit]
oconnor0 has joined #zig
oconnor0 has quit [Ping timeout: 250 seconds]
oconnor0 has joined #zig
chewzerita has quit [Quit: leaving]
<andrewrk> Hejsil, I know in my head how we can support structs with comptime fields, and I think it is the solution to var args / tuples
<Hejsil> The only way I come up with, was to make comptime fields be definitions of the type
<andrewrk> we might not expose the feature in struct {} syntax, but fields themselves can be comptime. if you iterate over the fields, these are included as one of them. but the value is a comptime constant
<Hejsil> Was playing around with generating types (in userland) that could have both comptime and runtime fields, and I just ended up having a list of runtime fields which had storage, and then a list of comptime fields, which where "definitions" of the type it self
<andrewrk> the comptime fields and values will be part of the struct type (really, every anonymous struct literal will create its own type just for that value)
<Hejsil> I see, so we came to the same conclusion on that
<Hejsil> I guess that could work for ano structs
<andrewrk> I think this is good. I feel confident about this as a resolution to var args / tuples
oconnor0 has quit [Quit: Quit]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<andrewrk> woo!! empty main function with simple panic handler now compiles & runs in copy elision branch
<Hejsil> Wuuh!
<andrewrk> that means that bootstrap.zig, builtin.zig, and compiler_rt is all working
<andrewrk> well. at least that they're able to build
davr0s has joined #zig
<andrewrk> diltsman, you're working on an arm os right? is your code open source?
<andrewrk> I'm looking at freebsd and linux source for how to do PSCI interop but it's rather convoluted
<errpr> On my PC, `@intCast`ing a negative c_short to u32 at runtime gives me max 32 bit integer instead of a runtime error. The other signed C types still cause an error though.
<errpr> is this for compatibility or something?
<andrewrk> errpr, let me see if I can reproduce the behavior. what value are you casting?
<errpr> var value: c_short = -1;
<andrewrk> errpr, I just confirmed the behavior and it's a bug. It also should be easy to fix, so let me have a look.
<errpr> cool.
chewzeri1a has quit [Ping timeout: 268 seconds]
<andrewrk> errpr, I created a fix - now I'm just running the tests
<andrewrk> errpr, fixed. a new build should be available on ziglang.org/download within 2 hours
chewzerita has joined #zig
reductum has joined #zig
<diltsman> andrewrk: Right now I am working on blinking an LED. I have an issue where my code to initialize .bss is hard faulting. I haven't had time to track it down yet (relatives visiting).
<andrewrk> diltsman, what target are you using? aarch64 or armv8?
<diltsman> armv7m
<andrewrk> ah, ok. I'm targeting aarch64
<andrewrk> sounds like we'll overlap a little, but not quite as much as I thought
<diltsman> I do embedded systems. Cortex-M is about as large as I ever get to.
<diltsman> Honestly, the last project I did at work had a PIC with 768 bytes of RAM.
<andrewrk> fun!
<andrewrk> I'm happy you're exploring this space with zig - I'm sure you'll run into some stuff that needs fixing
<andrewrk> how much ROM did that system have? for code and constant data?
<diltsman> 2k words of code space, no EEPROM.
<diltsman> 14-bit instruction size.
<diltsman> 32.768 kHz clock.
<diltsman> Right now I am trying to figure out the most efficient way to handle the memory mapped I/O for the ARM. From what I have seen, Zig packed structs don't do nearly as much as I would need. I have to ensure that reads/writes happen in 32-bit chunks, no matter the size of the fields.
<andrewrk> right, and we still have that related bug https://github.com/ziglang/zig/issues/1761
<diltsman> Yep.
<diltsman> I will work up an initial RFC or something related to what I would need from packed structs for them to be useful in my use case. I expect that most/all of it won't be adopted, but I suspect that it would be interesting to see what I don't see as being possible with them.
<diltsman> Of course, with family in town, it could be a while.
<andrewrk> that would be much appreciated. at the very least, the use case you are presenting must be solved in some satisfactory way
<andrewrk> (or at least have a planned solution)
<diltsman> Sure. Everything that I want/need to do can be done with u32 arrays and bit masking, but it would be nice to be able to use a language feature instead.
chewzerita has quit [Ping timeout: 250 seconds]
errpr has quit [Ping timeout: 252 seconds]
Hejsil has quit [Ping timeout: 256 seconds]
reductum has quit [Quit: WeeChat 2.3]
<suirad> anyone there mind giving me a hand?
<benjikun> whatcha tryin to do?
hio has quit [Quit: Connection closed for inactivity]