<adamkowalski>
In the first I have a struct which has a generic type T. Because T is now in scope, I can have a member function which takes in a struct which uses that type T as well as a value which is of the same type
<adamkowalski>
This makes the test code nice and clean
<adamkowalski>
In the second case however, I cannot do the same because I try to make it into a free function. I have to pass the type explictly and then I can use it further on in the arguments. It makes the API much more clunky
<adamkowalski>
The solution I've thought of is to make the function accept parameters by var, then use introspection to check if the types match, but that makes the functions much more verbose
<adamkowalski>
Any ideas?
<adamkowalski>
I would like for everything to be a free function so I don't have to cram everything into the struct just to avoid writing the type down explicitly for every function
leeward has quit [Quit: *Poof*]
adamkowalski has quit [Quit: Lost terminal]
<mikdusan>
letoram: `zig build ...` is going to create various artifacts that go in hash'd dir names, but the _install_ artifacts dir is somewhat configurable
<mikdusan>
leeward ^^
<Snektron>
leeward, i think its `exe.setOutputDir`
<Snektron>
can you combine that with the testing functionality?
<Snektron>
i would rather make a VulkanBackend and an OpenGlBackend (for example)
<Snektron>
And then return that from Backend
<dimenus>
yeah, good point
<andrewrk>
yeah put some logic in the BackendContext function
<dimenus>
i had a brain fart, my bad guys. I thin using function pointers is probably too C like here. better to return a regular struct with functions with similar names
<andrewrk>
that sounds much better
<andrewrk>
zig is allergic to runtime-known function pointers
<dimenus>
yeah, that would require having completely common function signatures
<dimenus>
which is bleh
<Snektron>
andrewrk: one this i was wondering about is whether std.sort.min/max should return ?T in case the slice is empty
<Snektron>
s/this/thing
Akuli has joined #zig
<andrewrk>
Snektron, I could see there being value in any of the following APIs: * provide default value as parameter, return is T * assert len > 0, return is T * allow len 0, return is ?T
<Snektron>
I suppose version 1 is encompassed by version 3
<Snektron>
and version 2 is equal to version 1 and a `.?`
<Snektron>
suppose a function `f` is `fn(a: i32) ?i32` and one writes `f(x).?`
<andrewrk>
I think I like the ? version, because you can get the first version with `orelse` and the second version with `.?`
<Snektron>
Would `f` internally still return whether the call was successful?
<Snektron>
or does that depend on wether `f` gets inlined in that expression?
<andrewrk>
that would be up to the optimizer. high chance that it could figure it out
<Snektron>
Why does the function return what it does when b = 0
<andrewrk>
oh I see, that branch should in theory be eliminated
<Snektron>
i suppose it isn't perfect though
<Snektron>
also, why exactlky is it accessing the stack in the b != 0 part?
<andrewrk>
if you replace `null` with `unreachable` then llvm figures it out. so yeah there's room for improvement here
<andrewrk>
zig could help too, if we wanted to try that. for example zig could generate a specialization of div where returning null is unreachable, since the callsite has .?
<andrewrk>
but I don't think such an optimization belongs in stage1
<Snektron>
I suppose to optimize that it would need to look at the entire expression including expressions in called functions
<Snektron>
maybe .? should be a special case though, but i agree that thats maybe too much for now
<Snektron>
I am still wondering about the stack part though
<andrewrk>
I think that's a constant to represent `@as(?i32, null)`
<andrewrk>
llvm didn't figure out to inline it
<Snektron>
hm, odd
<Snektron>
Anyway i'll make the changes to std.sort.min and max
<andrewrk>
yeah especially strange because the constant is all zeroes. that's pretty easy to inline
<Snektron>
also strange how eax is first stored to [rsp - 8], and then loaded again
<Snektron>
peephole optimization should have taken care of that
<andrewrk>
I guess llvm is not magic after all :)
<Snektron>
certainly not, but this case should be rather trivial
<andrewrk>
I think it's safe to say that this case will be solved in the future. there's nothing fundamentally preventing it from working
qbradley has quit [Ping timeout: 260 seconds]
<andrewrk>
emekankurumeh[m], I'm going to finally unblock #2598 for you
return0e has quit []
<Snektron>
alright, i've made min/max return ?T,
<Snektron>
i've also added argMin and argMax, these return the index of the min/max item instead of the item itself
FireFox317 has joined #zig
traviss has quit [Remote host closed the connection]
FireFox317 has quit [Ping timeout: 265 seconds]
<dimenus>
man, debugging c++ is just not fun
FireFox317 has joined #zig
<andrewrk>
dimenus, true that. one thing I've learned is that it's worth it to invest in debug infrastructure
<andrewrk>
if you're debugging some zig internals, I should teach you the new debug stuff I added
<dimenus>
nah, vulkan examples from sascha willems (but I will take you up on that at some point)
<frmdstryr>
Could zig do just in time compiling? It'd be awesome to have something like ipython to test code on the fly/embed and debug
<andrewrk>
nope, zig is an Ahead Of Time compiler
<dimenus>
zig's type information makes for a nice api, i can store the type in my resource pool to ensure that there's no stomping on other buffers or memory corruption (well much less of a risk anyway)
lunamn has joined #zig
<Snektron>
frmdstryr: i usually use `zig run`
<Snektron>
at least, thats what i've been using for aoc
<Snektron>
dimenus: if you have Vulkan problems, i could try to answer those as well. I have some amount of experience.
<FireFox317>
andrewrk, another stream today? :))) It's so fun to see you coding xd
<andrewrk>
FireFox317, not today, but maybe some more zasm this weekend :)
wootehfoot has joined #zig
<FireFox317>
hahah no problem man! Appreciate your streams yesterday and the day before :^)
<andrewrk>
that was so fun to get hello_world.s assembling directly into an ELF binary and running it
<andrewrk>
that's full bootstrap, baby! no C++, no LLVM
<bgiannan>
i'd like to do something for each case of an enum, can i iterate over it somehow ?
<andrewrk>
stratact, I just marked it contributor friendly
reductum has joined #zig
<stratact>
andrewrk: alright, I'll take it. I guess better to do something about it than wait ;)
<FireFox317>
andrewrk: the new code in start.zig doesn't work for freestanding/clashos, you mind adjusting it? I'm getting errors that it is trying to find root.main and system.exit etc. I'm not sure what the correct thing to do will be regarding freestanding, that's why i'm asking
return0e_ has quit [Ping timeout: 240 seconds]
ltriant has joined #zig
return0e has joined #zig
<FireFox317>
still working on a PR btw, but uni is time consuming :)
ltriant has quit [Ping timeout: 250 seconds]
lunamn has quit [Ping timeout: 250 seconds]
<andrewrk>
FireFox317, yeah, taking a look
lunamn has joined #zig
<dimenus>
Snektron, thanks. I'll keep that in mind. Atm I'm building the learnopengl.com breakout game but in Zig & Vulkan
<dimenus>
probably use libsoundio for sound instead of irrklang as well
<andrewrk>
FireFox317, I have local tests running, should have fix pushed soon
<andrewrk>
pixelherodev, this might be a breaking change for your use case, but hopefully in a good way. if you were relying on your _start symbol being found for your custom os app, you'll want to use the new `other` OS rather than `freestanding`
<stratact>
hahaha, what did I get myself into? I started watching a youtube video about TUIs with Miguel de Icaza (the GNOME creator) speaking, to help me learn terminfo a bit better, and as brilliant as that guy is, the first thing he is says is creating these UIs is "relatively painful" and "very annoying" ... ๐๐๐
<andrewrk>
I mean if your entry point was _start it will continue to work the same but if you were using `pub fn main` then this will affect you
<andrewrk>
stratact, personally, I'd start with reading the lua implementation and understanding what they're doing. it seemed like the "data" component of it was most of the code, the actual logic was just a couple functions
<stratact>
Fair enough, I should take advantage of daurnimator's existing work. I let curiousity get the best of me.
<FireFox317>
andrewrk: Thanks!
lunamn has quit [Ping timeout: 240 seconds]
<andrewrk>
stratact, well geez I wouldn't put it that way. if you were inspired to learn stuff, that's great
<stratact>
Ah, thank you. Well that's part of my strategy is just to get into unfamiliar terrirority and learn how it works, so it takes away the uncertainty/fear.
lunamn has joined #zig
<andrewrk>
good plan
<stratact>
I need to find material that ressonates with me though. Reading the details in the very detailed man page for terminfo makes it hard for me to jump into, so I'm looking for prerequisite material to make it easier to reference
<stratact>
With all that said, I still very much would love to have a curses lib for Zig and use it for a project.
<andrewrk>
dimenus, you're missing comptime on backend_type
<andrewrk>
so the switch is not comptime
<dimenus>
thank you sir
<andrewrk>
one way to diagnose this is to put comptime in the switch target expression, it would have said "unable to evaluate constant expression" and that would be a clue
<andrewrk>
FireFox317, fix pushed to master
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
ur5us has joined #zig
marmotini has quit [Remote host closed the connection]
ky0ko has joined #zig
<andrewrk>
frmdstryr, huh, actually llvm does seem to be able to understand zig's interface pattern: https://godbolt.org/z/avZe7Z
<andrewrk>
it even figures it out with --release-safe
<andrewrk>
oh no!! it's the std.mem.copy
clktmr has joined #zig
<andrewrk>
frmdstryr, in your experiment, try removing all the std.mem.copy and replace with @memcpy
<Sahnvour_>
andrewrk: is @memcpy based on a llvm intrinsic ?
<andrewrk>
pixelherodev, looking at Indomitable, I think it does not affect you, since your entry point is `start`
<andrewrk>
so, nothign to see here
ur5us_ has quit [Ping timeout: 265 seconds]
<pixelherodev>
Looking at that commit I don't think it should affect that regardless
Akuli has quit [Quit: Leaving]
<pixelherodev>
Either way, that _start is only exported if root file doesn't have _start
<pixelherodev>
Now, it's not exported regardless
<pixelherodev>
The practical difference to me is that there isn't an unused function _start being optimized out
<andrewrk>
`export` guarantees that it is considered "used"
<pixelherodev>
Ah right - either way it doesn't matter
<pixelherodev>
It wasn't being used, so its presence isn't a concern
<pixelherodev>
If I rename to _start, nothing will happen (except that there will no longer be an entry pointer since my linker script expects `start`)
wootehfoot has quit [Read error: Connection reset by peer]
kapil_ has quit [Quit: Connection closed for inactivity]
<daurnimator>
frmdstryr: suprising that its not as fast.... what does perf say? Could you do a flame graph?
qbradley has joined #zig
protty has joined #zig
<daurnimator>
frmdstryr: oh also, you don't have to take the address of it
plumm has joined #zig
<daurnimator>
not sure if that will make a difference
<plumm>
andrewrk: is there any reason `fmt.ParseUnsinedError` is private? I wan't to merge error sets with it
clktmr has quit [Ping timeout: 240 seconds]
vexu has quit [Quit: WeeChat 2.6]
<andrewrk>
plumm, it's public now
<andrewrk>
thx
<fengb>
Hmm, I think I'm starting to understand why int ranges are important
<lupine>
bruteforcing day 4 was fast
traviss has joined #zig
<plumm>
andrewrk: are compile errors the go-to debug tool? I wonder if instead of telling me the file & which errors I don't have merged into my set, could it just tell me which set I'm missing (if there is one); is that reasonable ?