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…]
zolk3ri has quit [Remote host closed the connection]
JinShil has joined #zig
donlzx has joined #zig
fjvallarino has joined #zig
dbandstra has joined #zig
<dbandstra> alexnask: https://pastebin.com/9csypnj2 this fails with vague "Unclean Exit"
adagio1 has quit [Quit: Leaving.]
andrewrk has quit [Ping timeout: 240 seconds]
andrewrk has joined #zig
dbandstra has quit [Quit: Leaving]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
xtreak has joined #zig
donlzx has quit [Quit: Leaving]
davr0s has joined #zig
relatingdata has joined #zig
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
Tobba_ has quit [Remote host closed the connection]
Tobba_ has joined #zig
mahmudov has quit [Remote host closed the connection]
relatingdata has quit [Quit: Page closed]
kristate has quit [Remote host closed the connection]
xtreak has quit [Remote host closed the connection]
xtreak has joined #zig
xtreak has quit [Read error: No route to host]
xtreak has joined #zig
alexnask has joined #zig
xtreak has quit [Remote host closed the connection]
quc has joined #zig
JinShil has quit [Quit: Leaving]
xtreak has joined #zig
xtreak has quit [Ping timeout: 276 seconds]
zolk3ri has joined #zig
<alexnask> @dbandstra Thanks, I'll look into it, defs should be an empty slice, perhaps it contains corrupted data somehow
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
zolk3ri has quit [Ping timeout: 248 seconds]
zolk3ri has joined #zig
noonien has joined #zig
zolk3ri has quit [Ping timeout: 245 seconds]
zolk3ri has joined #zig
kevw has joined #zig
adagio1 has joined #zig
kevw has quit [Ping timeout: 260 seconds]
xag has joined #zig
xag has left #zig [#zig]
kevw has joined #zig
fjvallarino has quit [Remote host closed the connection]
<kevw> I was trying to use the sokol library from zig (https://github.com/floooh/sokol) and ran into a few beginner questions
<kevw> I have code like:
<kevw> const desc:c.sg_desc = undefined;
<kevw> c.sg_setup(&desc);
<kevw> and i get
<kevw> main.zig:24:17: error: expected type '[*]const sg_desc', found '*const sg_desc'
<kevw> do the docs explain the difference between * and [*]?
<kevw> additionally, the sokol docs usually make that call like this:
<kevw> sg_setup(&(sg_desc){0});
<kevw> which is C for "initialize the struct to zero."
<kevw> is there such a shortcut in zig?
fjvallarino has joined #zig
<kevw> and finally, a third question1
<kevw> !
<kevw> i'm getting confusing behaviour with my c.zig file, and my @cInclude not picking up the sg_setup function
<kevw> @cDefine("SOKOL_IMPL", "1");
<kevw> @cDefine("SOKOL_GLCORE33", "1");
<kevw> @cInclude("sokol_gfx.h");
<kevw> is there a way to debug what exported functions from the header the cInclude is picking up?
<alexnask> @kevw
<alexnask> [*] is the equivalent to C pointer
<alexnask> it means that you are pointing to an unknown amount of the types
<alexnask> While * is a single item pointer, it is guaranteed to point to a single object of the type
<alexnask> sg_setup(&sg_desc(undefined)), it should work
<kevw> sg_desc(undefined) means "uninitialized memory" though, right?
<kevw> isn't that different than C's {0} init syntax?
<alexnask> I think it's planned for *T to be implicitely castable to [*]T
<alexnask> right, does the sg_desc need to be zero initialized?
<kevw> yes. I'm happy to write a zero init function, just wondered if there was a shortcut :)
<kevw> btw I ended up trying "const desc_ptr:[*]c.sg_desc = @ptrCast([*]c.sg_desc, &desc);"
<kevw> thanks for clarifying the difference though
<alexnask> Right, @ptrCast is the correct solution atm but I think it should be fixed soon
<alexnask> I don't think there is a shortcut for zero initialization
<kevw> as for a function not being picked up by cInclude, is there a verbose mode for the c header file stuff?
<alexnask> You can use 'zig translate-c' to basically get a .zig file of what @cImport does
<kevw> gotcha
<kevw> it's just extern void sg_setup(const sg_desc* desc); in the .h file
<alexnask> That way you can also fix function prototypes if zig's translation is not optimal
<kevw> it might be that my issue is that sokol is a "header only" library
<alexnask> translate-c should be able to pick them up
<kevw> it uses extern void to declare the function, and then you use a #define to implement the function
<alexnask> I've generated windows headers with it
<alexnask> Ah hmm
<kevw> now that i see the "mixing object files" section in the docs, I think one possible answer might be to have a main.c that does the #define SOKOL_IMPL
<kevw> and then the @cInclude without the @cDefine(SOKOL_IMPL) so that the declaration gets picked up
<kevw> but ideally I could just @cInclude the header twice(?)
<alexnask> Right you should be able to do a @cImport with the define and one without
<kevw> when i do translate-c without the IMPL define, the zig file has
<kevw> pub extern fn sg_setup(desc: ?[*]const sg_desc) void;
<kevw> ah, so @cImport twice does compile the zig file, but then I get an undefined symbol for _sg_setup in the linker
<kevw> i'm going to try the main.c thing
<alexnask> you should probably
<alexnask> just have a C file that defines SOKOL_IMPL and includes it
<alexnask> and compile that to an object file
<alexnask> then link that with the zig file that just @cInclude's to generate the function prototypes
<alexnask> I don't get the advantage of a header only library in C, I see why it makes sense in C++ :P
<kevw> the pains people go to deal with the lack of a module system
<kevw> just adding exe.addSourceFile("src/sokol-impl.c"); results in reached unreachable code _assert: 0x10461fec9 in ??? (???) _LibExeObjStep_addSourceFile: 0x1046381a4 in ??? (???)
<kevw> but perhaps addSourceFile needs to be from an addCExecutable like in the docs
<alexnask> Im not too sure about the build system sorry
<kevw> it's ok, thanks for your help!
<alexnask> I don't know if compilation of C files is available yet, you could just compile it once and keep the .o around
<alexnask> and add that to the linker objects in the build file
<alexnask> I guess headeronly libraries are useful if you want to build in a single translation unit
<kevw> I got it to link with an ugly call to addObjectFile: https://github.com/kevinw/sokol-zig/blob/master/build.zig#L29
<kevw> see also, how i got zero-struct-initialization to work https://github.com/kevinw/sokol-zig/blob/master/src/main.zig#L26
<kevw> now to figure out why the exe dumps with UncleanExit
return0e has quit [Remote host closed the connection]
return0e has joined #zig
<alexnask> You could also probably do: mem.set(u8, @ptrCast([*]u8, &dest)[0..@sizeOf(c.sg_desc)], []u8 { 0 } ** @sizeOf(c.sg_desc));
<alexnask> woops
very-mediocre has joined #zig
<alexnask> actually, mem.set(u8, @ptrCast([*]u8, &desc)[0..@sizeOf(c.sg_desc)], 0);
<alexnask> It's the same thing obviously, just saying :P
Hejsil has joined #zig
Hejsil has quit [Ping timeout: 260 seconds]
xtreak has joined #zig
darithorn has joined #zig
davr0s has quit [Quit: Textual IRC Client: www.textualapp.com]
fjvallarino has quit [Remote host closed the connection]
davr0s has joined #zig
xtreak has quit [Remote host closed the connection]
<kevw> that brings up a good question
<kevw> is there an easy way to make a macro that inlines to that? or to have a function that always inlines?
adagio1 has quit [Quit: Leaving.]
fjvallarino has joined #zig
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
kristate has joined #zig
btbytes has joined #zig
<alexnask> Functions marked as inline should always be inlined
<alexnask> I would suggest a zero_init(comptime T: type) T function
<MajorLag1> functions marked as inline that can't be inlined are a compile error
<kevw> great!
<kevw> yeah I'm stumped until I can pass a [*]const opaque_type pointer to the c library I'm trying to use, and calling @ptrCast results in the LLVM ERROR: Cannot select I pasted in the issue above
<kevw> really excited to try to get a small game loop going!
Ichorio has joined #zig
adagio1 has joined #zig
<alexnask> I'll take a look at the code in a bit, first time I come accross a LLVM error on @ptrCast personally
<kevw> i ran a zig debug compiler and got an assert: Assertion failed: (LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMPointerTypeKind), function gen_assign_raw, file /Users/kevin/src/zig/src/codegen.cpp, line 1769.
<andrewrk> hello
<andrewrk> kevw, you found a bug
<kevw> andrewrk: let me know if there's any more info i can provide
<andrewrk> if it's the same issue as the above linked github issue, I can reproduce the problem, so I have everything I need
<alexnask> @andrewrk Is there any way to create a TldVar without making AST nodes?
<alexnask> I know the type and ConstExprValue of the variable
<andrewrk> I think the ast node is allowed to be null at least for some of the kinds of Tlds
<alexnask> But it seems like all the logic is geared around AST nodes
<andrewrk> if not, the logic can be reworked
<alexnask> ir_gen_var_decl needs a type or expr AST node in the parent AstNodeVariableDeclaration
<alexnask> (which I am creating)
<alexnask> Anyway I'll look into bypassing it somehow for now
kristate has quit [Remote host closed the connection]
<alexnask> Hmm actually I think if I mark it as resolved I may be able to circumvent all that
<alexnask> But idk if it's a sane thing to do :P
<andrewrk> I think there are enough gotchas in that code that if we're going to add complexity to it, it should be by understanding the logic and reworking it to make more sense rather than trying to hack in a new feature
<alexnask> Seems to work
<alexnask> Right
very-mediocre has quit [Ping timeout: 260 seconds]
<alexnask> Well in this case I think it's more about me not having a complete mental picture of how all the passes etc work
<GitHub3> [zig] andrewrk closed pull request #1158: Fix os_path_join for case where dirname is empty (master...os-join-empty-path-fix) https://git.io/f49Tl
<GitHub120> zig/master 8e71428 Isaac Hier: Fix os_path_join for case where dirname is empty
<GitHub120> [zig] andrewrk pushed 1 new commit to master: https://git.io/f4740
<alexnask> But I do think it's actually correct to say the variable decl is resolved in this context, it is generated directly with a type and value (this is @reify code)
<andrewrk> ah, ok, in that case I'm fine with it
<alexnask> Which should be done (with no tests etc) in a couple of hours
<alexnask> Struct is done, union and enum are basically the same
<andrewrk> I'm hoping to use the self hosted code as a test bed for rewriting the zig compiler logic in a sound and clear way, and then maybe backporting it to stage1
adagio1 has quit [Quit: Leaving.]
<GitHub72> [zig] isaachier closed pull request #1157: Add fuzz test (master...fuzz-test) https://git.io/f4SP0
oats has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
kevw has quit [Ping timeout: 260 seconds]
davr0s has joined #zig
isd has joined #zig
noonien has quit [Quit: Connection closed for inactivity]
adagio1 has joined #zig
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<oats> how do arrays in zig know how long they are?
<oats> it appears you don't have to keep track of an array's length with another variable, like you might in C
<andrewrk> oats, the length is part of the type
<oats> so is there a maximum array length?
<andrewrk> if the length is known only at runtime, that's a slice - which is a struct { ptr, len }
<oats> interesting
jjido has joined #zig
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
btbytes has quit [Client Quit]
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
<GitHub140> [zig] andrewrk pushed 2 new commits to master: https://git.io/f47rM
<GitHub140> zig/master 11ca38a Andrew Kelley: fix crash for optional pointer to empty struct...
<GitHub140> zig/master af95e15 Andrew Kelley: rename get_maybe_type to get_optional_type
fjvallarino has quit [Ping timeout: 268 seconds]
jjido has quit [Ping timeout: 265 seconds]
btbytes has joined #zig
<GitHub154> [zig] andrewrk pushed 1 new commit to master: https://git.io/f47KB
<GitHub154> zig/master 4de60dd Andrew Kelley: langref: explicit cast section
fjvallarino has joined #zig
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mahmudov has joined #zig
<alexnask> @andrewrk I think stdcall on x86 expects a 4 byte aligned stack (as opposed to the win64 calling convention that expects a 16 byte aligned stack)
adagio1 has quit [Quit: Leaving.]
<andrewrk> ah
<alexnask> Although the MS official docs aren't clear on that :P
<alexnask> So I don't think the win32 test failures are due to the stack alignment, could be wrong though
isd has quit [Ping timeout: 256 seconds]
btbytes has joined #zig
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<oats> where can I find documentation on the standard library?
<andrewrk> oats, currently, only in the source code
adagio1 has joined #zig
<oats> in /usr/lib/zig then?
btbytes has joined #zig
<oats> also, I noticed that it says on the site that the standard library doesn't depend on libc
<oats> how do you get around that?
<oats> forgive my ignorance of programming language design, but I thought pretty much the only way to interface with the linux kernel is to use a libc of some kind
<andrewrk> oats, if you downloaded zig then the standard library is in there. if you're building it from source the std lib is in the `std` directory
<andrewrk> the linux kernel defines a stable ABI for syscalls
<andrewrk> it's like calling a function, but you use an interrupt to activate kernel mode
<oats> interesting
<andrewrk> that's what libc does internally
<oats> so a libc gives you an abstraction over making raw syscalls, do I understand that correctly?
<andrewrk> correct
<andrewrk> many libc functions are thin wrappers around syscalls
<oats> are there examples of syscalls in the zig stdlib I can look at?
isd has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<oats> ahhh, that makes sense that it's backed by asm
alexnask_ has joined #zig
<oats> I should've guessed :P
<oats> that is very informative, thank you
alexnask has quit [Ping timeout: 248 seconds]
Ichorio has quit [Ping timeout: 240 seconds]
<alexnask_> Does having a null union tag type result in auto generating an enum tag type make sense? (+ all union fields having an enum_field)
alexnask_ is now known as alexnask
<alexnask> ir.cpp is getting pretty crazy, I thought it was around 16k loc and is now 21.5k on my branch :P
<andrewrk> it's 20,702 on master
<andrewrk> self hosted will be more organized since there is no compilation speed / performance penalty for splitting stuff up
<andrewrk> alexnask, yeah I think null union tag type makes sense to represent union(enum)
<andrewrk> either that or union(enum) { Auto, Explicit: type }
<alexnask> Right, my idea is to use null for union(enum) {} when all union fields have enum_field != null and union {} when all union fields have enum_field == null
davr0s has joined #zig
<andrewrk> I believe I have created a many producer, many consumer, thread-safe, lock-free, runtime configurable buffer size Channel data structure that integrates with the userland event loop
<andrewrk> when the buffer is empty, consumers suspend and are resumed by producers; when the buffer is full, producers suspend and are resumed by consumers
<andrewrk> time to test it with a thread pool
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
fjvallarino has quit [Remote host closed the connection]
fjvallarino has joined #zig
fjvallarino has quit [Ping timeout: 240 seconds]
<oats> I really appreciate there being vim configs for zig already, that's super neat
<andrewrk> it supports automatically running zig fmt too if you set it up
<andrewrk> I've been using it
fjvallarino has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
btbytes has quit [Client Quit]
btbytes has joined #zig
btbytes has quit [Client Quit]
btbytes has joined #zig
btbytes has quit [Client Quit]
btbytes has joined #zig
tiehuis has joined #zig
<tiehuis> andrewrk: when was the timeframe for more effort on the self-hosted compiler? have an okay enough Rational implementation for the moment if that was wanted.
<tiehuis> just need to modify it to take by value vs. reference
<andrewrk> tiehuis, I started working on the self hosted compiler as the main "big thing" after 1 bug fix, 1 doc improvement, & dealing with PRs every day
<andrewrk> I think you've at least a few weeks until that becomes a blocker though
<tiehuis> great, just wanted to check to see the timeframe
<andrewrk> it's a slow start because I'm insisting on full multithreading / async I/O from the start
<tiehuis> yeah, fair enough, may as well start off right when we have a clean slate
<andrewrk> independent from that, though, I'm thinking that I'd like to make a well defined zig IR and start adding zig IR to zig IR tests and zig IR to llvm IR tests
<andrewrk> hopefully then we can grow the self hosted compiler without having to support everything at once
<andrewrk> I think with more focus on IR robustness we can solve most zig bugs
<oats> is a string literal a struct in disguise?
<oats> since I can do the_string.len
<andrewrk> a string literal is an array, so the length is known as part of the type: https://ziglang.org/documentation/master/#String-Literals
fjvallarino has quit [Remote host closed the connection]
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
fjvallarino has joined #zig
fjvallarino has quit [Ping timeout: 240 seconds]
<oats> yeah
<oats> that's the page I'm going through
<oats> it's the official "tutorial", right?