<Barabas>
I also don't write that much tests usually when doing projects for myself
<mq32>
it's not about testing, but about crunching down the possible states of a game so much that you can brute-force the optimal solution
lunamn has quit [Ping timeout: 255 seconds]
<fengb>
The bytecode parser will have more tests. Arguably a unit test because I consider it a unit, but it’ll go through much more stale code than a traditional “unit”
<mq32>
fengb, i'll write a test for the byte code parser that will check every possible instruction if it gets decoded at least correct :D
<fengb>
Basically... if it has a semi obvious in->out cycle that’s non-trivial, I’ll “unit test” it
dsego has quit [Quit: dsego]
daurnimator has joined #zig
<fengb>
If it’s mucking around with deep internal state... that’s a brittle test and I don’t find a lot of value
<fengb>
Or alternatively if it’s trivial or tautological, not much value either
<mq32>
oh btw
<mq32>
best kind of test: smoke test
<fengb>
Yeah I smoke when I test
<Barabas>
lol
<fengb>
Wait what?
<mq32>
so you failed the smoke test? :D
<fengb>
I actually am enjoying backend code again. My day job is mostly frontend and I really don’t value tests there :P
<Barabas>
> After about a year of execution time on six CPU cores
<Barabas>
Ehmm... ok two months of optimizing?
dimenus has joined #zig
<pixelherodev>
To add my two cents to the TDD discussion: I think TDD is a useful tool, just like a lot of other things
<pixelherodev>
It's not often the right tool to use
<pixelherodev>
But there are certain contexts where it can be very useful
<mq32>
pixelherodev: yeah, true. if the API is known beforehand (reimplementation of an existing library for example), it's a great tool
<fengb>
I really like the trailing comma hinting at how args should be wrapped
waleee-cl has quit [Quit: Connection closed for inactivity]
dddddd has quit [Ping timeout: 265 seconds]
alexnask has joined #zig
dimenus has quit [Ping timeout: 258 seconds]
SimonN has joined #zig
SimonNa has quit [Ping timeout: 240 seconds]
slowtyper has quit [Quit: WeeChat 2.7]
slowtyper has joined #zig
slowtyper has quit [Client Quit]
slowtyper has joined #zig
<daurnimator>
andrewrk: i'm around now for an hour or so. I could look at 3972 now if you want?
metaleap has joined #zig
LER0ever has quit [Remote host closed the connection]
LER0ever has joined #zig
neceve has joined #zig
metaleap has quit [Quit: Leaving]
LER0ever has quit [Remote host closed the connection]
LER0ever has joined #zig
metaleap has joined #zig
mforney has quit [Excess Flood]
mforney has joined #zig
slowtyper has quit [Quit: WeeChat 2.7]
slowtyper has joined #zig
araspik has joined #zig
metaleap has quit [Quit: Leaving]
forgot-password has joined #zig
mforney has quit [Excess Flood]
mforney has joined #zig
<forgot-password>
Is there a way to join anonymous struct literals (var args) at runtime? Since @Type doesn't support structs right now
ur5us_ has joined #zig
ur5us_ has quit [Ping timeout: 240 seconds]
wootehfoot has joined #zig
xackus has quit [Remote host closed the connection]
waleee-cl has joined #zig
<mq32>
forgot-password: you can concat them with ++ afaik
<mq32>
but i don't know if that works for runtime values
<forgot-password>
It doesn't, sadly. Somebody already suggested it, but exactly that was the problem :/
<mq32>
probaby you can do some comptime magic
<mq32>
why do you want to merge them?
return0e has joined #zig
return0e_ has quit [Ping timeout: 260 seconds]
<forgot-password>
I'm trying to build a very basic wrapper around objective-c's objc_msgSend and want to pass the id and selector automatically
<forgot-password>
I'm currently trying to do some comptime magic, I'll get back to you in a bit :)
carlog has quit [Quit: WeeChat 2.7.1]
<forgot-password>
Is .{@as(u8, 42)} not basically the same as instatiating a struct of type struct{ @"0": u8 }?
<mq32>
BaroqueLarouche: are you mlarouche on github?
wootehfoot has quit [Ping timeout: 258 seconds]
<forgot-password>
If I pass .{@as(u8, 42)} to @call it works fine, but (struct{ @"0": u8 }){.@"0" = 42} doesn't. Even though `std.meta.fields` tells me, that they have the same fields
<forgot-password>
Okay, apparently there is StructSpecialInferredTuple, which I probably can't set manually...
dddddd has joined #zig
forgot-password has quit [Quit: leaving]
mahmudov has quit [Ping timeout: 246 seconds]
slowtyper has quit [Ping timeout: 258 seconds]
<BaroqueLarouche>
mq32: yes
<mq32>
ah nice
<mq32>
how far is zigimg?
<BaroqueLarouche>
Very early, only read BMP for now
<mq32>
i have two modules for PCX and NetBPM written in Zig
<mq32>
a test suite with a lot of test cases for the bitmap format
rappet has quit [Ping timeout: 246 seconds]
rappet has joined #zig
<BaroqueLarouche>
I already have it linked IIRC
<mq32>
ah nice :)
<betawaffle>
is there currently any way to do `extern var @"OBJC_CLASS_$__MTLDevice": ?id;` where the name there is a comptime string passed to a function?
mahmudov has joined #zig
decentpenguin has joined #zig
<mq32>
betawaffle: look at @export
<betawaffle>
but i'm trying to import
<mq32>
ah, hm
<mq32>
just generate the code?
_Vi has joined #zig
return0e has quit [Remote host closed the connection]
dingenskirchen has quit [Quit: dingenskirchen]
dddddd has quit [Ping timeout: 240 seconds]
dingenskirchen has joined #zig
dimenus has joined #zig
slowtyper has quit [Ping timeout: 260 seconds]
slowtyper has joined #zig
<mq32>
huh
<mq32>
i get a segfault 0x00 when doing zig build test
<Barabas>
I'm trying to assing something to a global variable, but it crashes with a segfault when I run the tests
<Barabas>
If I try to make some minimal example which just assigns to a global and prints it it works.
<Barabas>
Oh wait...
<Barabas>
I had a
<Barabas>
? too many
<andrewrk>
Cadey, this can be changed, but I think best bet right now is to override $HOME because it's going to use $HOME/.cache/zig for the global cache
<andrewrk>
it's planned that if you slice with a comptime known length you get a pointer to an array
<TheLemonMan>
god damn it, you can't even blink without hitting a bug :(
<andrewrk>
well that's not a bug, it's a language improvement
<andrewrk>
I've just been using @ptrCast until that's done. then the @ptrCast can be removed in favor of e.g. x[0..4]
<TheLemonMan>
if the CI passes for #4497 I'll mark it as ready for review
<TheLemonMan>
and then I'll open the floodgates and merge the DWARF-based frame unwinder
<TheLemonMan>
and the PDB-based frame unwinder
<TheLemonMan>
and then we'll finally have stack traces in release mode!
<Barabas>
Cool
<andrewrk>
wow amazing
return0e has quit [Remote host closed the connection]
waleee-cl has quit [Quit: Connection closed for inactivity]
metaleap has quit [Read error: Connection reset by peer]
o_O has joined #zig
o_O is now known as Guest85056
Snetry has quit [Ping timeout: 240 seconds]
<shakesoda>
I'm trying to use SDL_GL_SetAttribute and I'm not sure how to convince zig that SDL_GL_CONTEXT_PROFILE_MASK (c_int) is what it really wants (apparently, enum_unnamed_38)
<shakesoda>
is there a good way to tell it to shut up and accept my integer
<shakesoda>
or a bad way
<TheLemonMan>
@intToEnum ?
<andrewrk>
shakesoda, is enum_unnamed_38 inaccessible from the @cImport ?
<TheLemonMan>
hmm, you should probably be able to use an enum literal too
Snetry has joined #zig
<shakesoda>
it's accessible, but I'm not sure how much I trust it to always be enum_unnamed_38, and it seems a bit ridiculous to write out that way
<shakesoda>
I'll do it, though
<shakesoda>
andrewrk: ah, no, it's private
<shakesoda>
inaccessible :(
<TheLemonMan>
how is it defined?
<andrewrk>
hmmmm, yes so we have a problem with anonymous c enums with casting
Guest85056 has quit [Quit: Leaving]
<shakesoda>
worked around with extern fn SDL_GL_SetAttribute(flag: c_int, value: c_int) void; for now
<andrewrk>
I did have a related idea the other day, which would be to remove the type argument of many of the casting builtins... they would work based on result location instead
metaleap has joined #zig
<andrewrk>
to get current behavior you would do @as(T, @intToEnum(x))
<shakesoda>
oh, should be an int return
<andrewrk>
and it would solve this particular use case
<dimenus>
andrewrk: for detecting libc, do we want to read through /usr/bin/env directly and find libc?
<dimenus>
or run ldd
<TheLemonMan>
shakesoda, have you tried using .sdl_gl_context_profile_mask ?
<shakesoda>
TheLemonMan: it's an int
<shakesoda>
I'll try, since I guess it's... both?
<TheLemonMan>
the parameter is a SDL_GLattr
<shakesoda>
very mysterious
<TheLemonMan>
SDL_GL_CONTEXT_PROFILE_MASK is a macro that's translated as an int
<andrewrk>
dimenus, ideally would be to directly read the ELF header data for /usr/bin/env and find the dynamically linked libc
<andrewrk>
I think that is a high quality heuristic for detecting what is the native libc
<shakesoda>
TheLemonMan: that worked
<shakesoda>
c headers cause a lot of awkward situations.
<dimenus>
andrewrk: understood
<Barabas>
Yes
<TheLemonMan>
C ultra-lax casting rules are the main source of awkwardness
Akuli has joined #zig
dddddd has joined #zig
<shakesoda>
anyone know how to set windows subsystem
<BaroqueLarouche>
shakesoda: you need to have WinMain in your root file
<shakesoda>
BaroqueLarouche: how about using one of these _only_ when building on windows target?
tane has joined #zig
return0e has joined #zig
<andrewrk>
@export in a top-level comptime block
<shakesoda>
any examples of that?
<shakesoda>
my comptime-fu is weak
ave_ has joined #zig
<andrewrk>
lib/std/special/start.zig
<shakesoda>
thanks
<shakesoda>
I ended up making a separate win32 entry file and updating my build.zig to reflect that for release builds
<shakesoda>
easier to understand
<pixelherodev>
To use type as an identifier within a struct, the `@""` syntax is usable, correct?
<pixelherodev>
`const a = struct { @"type": void };`?
<andrewrk>
shakesoda, there's also a --subsystem parameter, and `zig build` exposes it with `foo.subsystem = .bar;`
<metaleap>
pixelherodev: yup
<metaleap>
(had the same question popping up with lsp-spec's json-structs =)
<pixelherodev>
If I have two slices of one larger, constant slice, *and I have access to the original slice*, what's a *good* way to obtain a slice containing both subslices?
<pixelherodev>
Of course including anything in between the two slices as well
<pixelherodev>
I'm thinking @ptrToInt and then a bit of basic math there, but that also feels really ugly
<pixelherodev>
Though I suppose this is an ugly use case :P
<shakesoda>
andrewrk: it still wants the winmain if I do that, so it seems to work out the same way?
<andrewrk>
pixelherodev, it sounds like you might be better off with a different data structure than slices. e.g. carrying around the parent buffer and some indexes
<andrewrk>
if you only have a slice, you're not really supposed to peek outside the boundaries
<andrewrk>
I mean you can but there's probably a better way to model the logic
<pixelherodev>
Yeah, that's what I have *now*
<pixelherodev>
But I wanted to clean up the lexer by replacing index + len with a slice
<pixelherodev>
Then I realized what that would mean for the AST generation, which needs to combine slices
<pixelherodev>
So yeah, probably going to leave that as is and leave an explanation in the todo list as to why it isn't feasible
knebulae has quit [Read error: Connection reset by peer]
jessermeyer has joined #zig
jcharbon has joined #zig
<jcharbon>
About a month ago some great people helped me with a zig 'ls' implementation. School has had me tied down for awhile so I stopped trying to get it to work but I finally have some time to try to iron out the rest of the issues I'm having ... Can someone take a look at my most updated version and help me understand why I'm experiencing issues? https://yld.me/raw/qXI.c
<jcharbon>
The main issue I'm having is using './ls /etc' or './ls /home' or any other root directories
<jcharbon>
It's just not listing anything
<pixelherodev>
Well, for starters, I wouldn't use std.os.linux.stat directly
<pixelherodev>
I'd go through std.fs
<jcharbon>
Sure yea that was the thing I was going to do next, just didnt know by what means. I will look into std.fs more
<pixelherodev>
What I'd do is this: first, try opening as a file. If works, print as file. Else, try opening as folder. If works, print as folder. Else, error out.
<jcharbon>
Yeah that makes sense! I'll give it a try. Thanks for the advice
<pixelherodev>
Maybe switch to using std.heap.page_allocator instead of a fixedbufferallocator?
<pixelherodev>
For show_directory *
<andrewrk>
std.fs is the higher level, cross platform abstractions. it's recommended to start there before reaching lower into std.os
<pixelherodev>
Also, if it's not printing directories as is: try `gdb`?
<pixelherodev>
Step through the code and see what's going on
<pixelherodev>
Ah right, arena over page_allocator. Smart
<pixelherodev>
I'd propose an edit to that though: if the program uses more than N MB of RAM, should free it before the end to avoid hogging unneeded resources
<shakesoda>
is there a good way to invoke an external tool as part of the build
<shakesoda>
e.g. shader compiler or something
<pixelherodev>
std.ChildProcess.exec?
<andrewrk>
pixelherodev, free it before the end? you mean right before the OS frees it for you?
<pixelherodev>
No, I mean as soon as it's not needed
<andrewrk>
ahh I see
<pixelherodev>
I meant *before* the `arena.deinit` that would be at the end
<andrewrk>
got it
<jessermeyer>
If the target is 64bit, the address space is enormous, and for short lived programs, it is quite rare for even large allocations to feel like they hog system resources due to system paging.
<jessermeyer>
But it's a trade off analysis, always.
<jcharbon>
so actually just changing my allocator to the one recommended by andrewrk fixed my ls issue! Everything working as expected now. I will still go in and get rid of my std.os though. Thanks much guys!
<pixelherodev>
:)
<andrewrk>
jcharbon, if you end up using only std.fs and other high level APIs like that, your `ls` program will work on Windows too
<pixelherodev>
Suggested improvements for your project: clean up output (e.g. print newlines); add in support for some simple command line options like `-l`; colorize output
<jcharbon>
yes that will be in the works pixelherodev haha. Just needed that baseline functionality first.
<jcharbon>
when I wrote this to begin with I was oblivious to a bunch of zig stuff so thats why I mistakenly used the std.os but will do my best to avoid it in the future :)
lunamn has joined #zig
lunamn_ has quit [Ping timeout: 272 seconds]
<shakesoda>
pixelherodev: thanks, that's what I was looking for
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<pixelherodev>
No problem
iohzrd23 has joined #zig
wootehfoot has joined #zig
<pixelherodev>
`In summary, Jimmi made a good attempt at implementing a StringSwitch in comptime and concluded that good old chained if statements were fastest.` Okay, but if it was in the language, it could just be directly translated to the equivalent of chained mem.eqls...
<pixelherodev>
That is, the compiler could just rewrite switch([]u8) into an if/else chain and then compile that
<pixelherodev>
Not that I'm advocating that that is a good idea :P
<shakesoda>
aren't slices supposed to be able to coerce to [*] or do i remember wrong
<shakesoda>
or is this an issue specifically with [*c] (argh)
<fengb>
slice.ptr
<shakesoda>
sure enough
<shakesoda>
fengb: thanks
iohzrd23 has quit [Remote host closed the connection]
iohzrd has joined #zig
<iohzrd>
yo
<iohzrd>
I'm starting to play with zig and trying to figure out the equivalent to scanf but cant find anything in the docs. Can anyone help?
Xatenev has joined #zig
<iohzrd>
tried searching the src.io but couldn't find much
<iohzrd>
src of std.io*
<pixelherodev>
AFAIK there is no such method yet
<pixelherodev>
Emphasis on *yet*
<iohzrd>
gotcha
<andrewrk>
hello iohzrd
<iohzrd>
hi!
<iohzrd>
love the project, am a sponsor on github...
<andrewrk>
I recognize your name :)
<iohzrd>
:)
<andrewrk>
a scanf-inspired API would be a fun contributor project, I think
<iohzrd>
hmm, will look into it
<metaleap>
andrewrk ast.Token.Id has no notion for the `type` keyword, so the way to go here is mem.eql(u8, "type", myIdentNodesTokenSlice) ?
knebulae has joined #zig
<metaleap>
its not ever gonna change i guess :D
<andrewrk>
metaleap, `type` is a primitive builtin, like `bool`
<metaleap>
just assume the std.zig.ast user wants to check whether some *Node represents it
<andrewrk>
but since it's not possible to shadow any identifiers, including primitives, it is currently true that if an identifier is "type" then it is necessarily the type primitive
<pixelherodev>
Here's an interesting proposal: expose language features through a builtin package similar to, well, the builtin package
<metaleap>
gotcha thx! the no-shadowing is hopefully here to stay
<pixelherodev>
Then, library code can do `if (!zigfeatures.blob) {@compileError("this version of zig is unsupported!");}`
<pixelherodev>
Would probably be a bit of a challenge to include *all* language info, but not impossible. e.g. `primitives` could be a `[][]const u8` containing `type`, `bool`, etc
<andrewrk>
pixelherodev, I think rather a package will simply declare the major version it is targeting, and when the major version is rolled, it will support all zig versions. e.g. imagine if python3 supported python2 code and it Just Worked
mforney has quit [Excess Flood]
mforney has joined #zig
<pixelherodev>
I can see advantages and disadvantages to that, but I definitely like the concept
<iohzrd>
''' if sys.version_info[0] == 3 and sys.version_info[1] >= 5:'''
<iohzrd>
lol
<pixelherodev>
Well, combined with Zig's lazy evaluation it would actually be useful
<pixelherodev>
As a comptime-known if, the no-longer-valid code would just never be analyzed
<shakesoda>
can i force a build step to run regardless of if any changes have been made