<companion_cube>
is godbolt limited to C ABI functions?
ManDeJan has quit [Ping timeout: 252 seconds]
<very-mediocre>
companion_cube: looks like it, if you remove `export` from `export fn...` there's no output
<companion_cube>
yeah :/
<very-mediocre>
`export` seems infectious, if you add a function `bar` that's exported, and you call `foo` inside it, you do get an output for `foo`
<very-mediocre>
(which obviously makes sense)
<very-mediocre>
I was away from zig for a while, months ago there was the idea floating around that zig could be like "comptime-eager" - as in infer the intent to have comptime execution in some cases
<very-mediocre>
e.g. calling the `fn whatever(a: []const u8)` with a comptime-known value for param `a`, even though it's not labeled comptime in the function signature
<very-mediocre>
has anything happened re:this?
_whitelogger has joined #zig
very-mediocre has joined #zig
<very-mediocre>
Actually I'm dumb, this should be the same as my previous question about `if` statements [12:40] <very-mediocre> withdrawn!
<gamester>
companion_cube, very-mediocre: you're literally just describing how Zig works, it has nothing to do with godbolt.
gamester has quit [Quit: Leaving]
marmotini_ has joined #zig
<very-mediocre>
gamester you've misread, companion_cube was just asking about godbolt.
<very-mediocre>
my questions were about zig, godbolt was used to provide answers
<very-mediocre>
I concede I am extremely messy at writing on irc so I understand it's hard to follow.
marmotini_ has quit [Ping timeout: 264 seconds]
<Sahnvour>
andrewrk, how is building with C source files supposed to work wrt. libc, especially on windows ? I'm trying to mix zig and C code on windows but the zig cc command line generated does not contain a path providing libc headers, and so they are not found
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 252 seconds]
porky11 has joined #zig
porky11 has quit [Client Quit]
<scientes>
Sahnvour, it probably just isn't tested on Windows yet, as it is a new feature
<scientes>
Sahnvour, but on Linux it explicitly does _not_ link against libc
<scientes>
so you have to do so manually
wootehfoot has joined #zig
Xe has joined #zig
Ichorio has quit [Ping timeout: 252 seconds]
<Xe>
How would I get zig to import arbitrary functions from the environment in WebAssembly? I'm trying to get Zig working on top of an arbitrary WebAssembly runtime (https://github.com/Xe/olin) and I'm having trouble figuring out how to import extern functions.
<shritesh>
Xe, if you compile with --release-small, --release-fast or even --release-safe, the optimizations will turn on and the gas used might be even lower
meheleventyone has joined #zig
<Xe>
(gas == number of instructions)
<shritesh>
I am aware :)
<Xe>
lol
<Xe>
release-fast made it 5 instructions
<shritesh>
Great!!!
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
meheleventyone has joined #zig
<andrewrk>
Sahnvour, you have to use `--library c` in order for libc headers to be in the include path
<andrewrk>
scientes is incorrect; C source compilation is fully tested on windows in the main test suite
<scientes>
oh, I should check
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<daurnimator>
andrewrk: how goes?
very-mediocre has quit [Ping timeout: 256 seconds]
<andrewrk>
hi daurnimator
<daurnimator>
andrewrk: you took the weekend off? :)
<andrewrk>
that's one way to put it. I ran 16 miles yesterday
<daurnimator>
intentionally I hope?
<andrewrk>
haha
<daurnimator>
vs "my car broke down in the middle of nowhere" :P
ben_e has quit [Ping timeout: 256 seconds]
<shritesh>
andrewrk: What'll it take for wasm32 to be tier 2? ;)
<andrewrk>
let's have a look
<Xe>
how would I add my own OS interface to zig's standard lib?
<andrewrk>
I think it's tier 2 now that your preliminary support patch is merged
<shritesh>
Woo Hoo!!!
return0e has quit [Ping timeout: 250 seconds]
<andrewrk>
wasm64 should probably be 4 though - afaik it's not standardized yet
<shritesh>
Correct
return0e has joined #zig
<andrewrk>
shritesh, to get to tier 1, I think we need to make a WASI interpreter :)
<shritesh>
I'll work on that in two weeks after I graduate college :D
klltkr has quit [Quit: Leaving]
<Xe>
andrewrk: how would I add an OS backend to zig's standard library? I already have function calls for things like file operations in a bit of a self-made webassembly environment.
<andrewrk>
Xe, that's a great question. Let me think about that for a moment
<andrewrk>
cool, yeah this is the use case I need to consider
<shritesh>
Oh wow. I remember this project. This blew my mind when I first saw it in Rust circles.
<Xe>
shritesh: yeah, i'm still working on it. I've been kinda set back by life circumstances, but I want to push this into high gear now.
<andrewrk>
Xe, so the status quo answer to your question is that you fork zig, add support for your OS (you can follow the "Zen" OS example), and then submit a pull request to upstream your changes
<Xe>
andrewrk: awesome
<Xe>
how do you qualify the type of a string?
<Xe>
like of a size-independent string
<andrewrk>
I don't currently have a solution to the use case of e.g. extending Zig with more operating systems without going through master branch / upstreaming process or maintaining a fork
<shritesh>
andrewrk: submitted a PR to bump wasm tier
<andrewrk>
Xe, zig doesn't have strings - what are you trying to do?
<andrewrk>
shritesh, bump it up to where the other 2's are
<andrewrk>
hmm this table is getting big. maybe we move the support table to ziglang.org and delete it from the readme, and then it will be easier to have more columns
<Sahnvour>
andrewrk, thanks, how do I do the equivalent to `--library c` in a build file ?
<shritesh>
Better worded question: Right now all extern functions get imported from "env" in wasm32. How would I make it import from whatever is in the string after `extern`?
<Jenz>
(test fails, and val of `str` stays "hello", as everyone [in this channel] but me probably knows just by looking)
<shritesh>
Jenz: I think you need to use mem.copy
<Jenz>
shritesh: OK, thanks, I'll try that :D
<shritesh>
`mem.copy(u8, str[2..4], replacement[0..]);` in line 8
mnoronha_ has quit [Ping timeout: 246 seconds]
<Jenz>
Ooh, yes that worked, thanks a ton shritesh!
<shritesh>
:)
mnoronha_ has joined #zig
<Jenz>
But then, what did my `str[2..4] = replacement[0..];` do?
<shritesh>
I'm confused as well.
<shritesh>
When I try to run inside a comptime block, I get an `error: cannot assign to constant`. So maybe this is a compiler bug?
<Jenz>
Seems like a weird place to place a compiler bug (stupidness intentional - initially an attempt at a joke)
<Jenz>
(When your "joke" needs that much of an explanation, you know it's an absolute failure XD)
<very-mediocre>
a slice is a pointer and a length; the left side evaluates to a pointer to one of the items in the `str` array, but then you're just pointing it elsewhere
<very-mediocre>
imho. it's like doing `var ptr = str[2];` followed by `ptr = replacement[0];`
<Jenz>
But str[2] refers to the u8 value, whilst str[2..4] refers to the pointers to the values in the array, not the actual values, doesn't it? That's why I thought setting those pointers to some other pointers (replacement[0..]) would change the actual values of the array `str`. Though clearly it did not
<scientes>
<Jenz> But then, what did my `str[2..4] = replacement[0..];` do?
<scientes>
yeah this doesn't work
<very-mediocre>
Jenz you're right, my example should read `var ptr = &str[2]`
<Jenz>
Oh ok
<Jenz>
So the ptr is copied, kinda? (I'm probably using these terms wrong)
<very-mediocre>
you're expressing a new pointer to an existing element
<very-mediocre>
and then that pointer is being pointed at another element
<very-mediocre>
so the first elemented being pointed to is no longer referenced
<very-mediocre>
try this `str[2..4].ptr.* = replacement[0];`
<Jenz>
Yeah, ok, thanks very-mediocre. I think I get it now (though I'm not sure if I actually do)
<very-mediocre>
if you dereference on the left side, then you're expressing the actual content being pointed to, then when you do = you're assigning to that value
<Jenz>
Huh, cleary you know what you're talking about. Thanks again for the extensive explanation. Though despite all the help, I don't get why str[2..4].ptr.* resolves to only one element
<very-mediocre>
that's just by design, because a slice is really just a pointer to a single element, and a length
<Jenz>
And I'm sorry for being so ignorant :) -- that's the reason I'm trying to understand now (and because I find zig absolutely awesome)
<very-mediocre>
`str[2..4]` is a structure that contains 1. a pointer to str[2] and 2. length=2
<Jenz>
"to str[2] and 2" ? I'd thought: "to str[2] and str[3]"
<very-mediocre>
that's point #2
<very-mediocre>
• pointer to str[2] and • length=2
<very-mediocre>
and there's no need to be insecure, i'm pretty mediocre at zig too :)
<Jenz>
Haha, then zig has sky-high standards
<Jenz>
(Which I guess is true, having just looked at the std.mem implementation. And having followed zig for a while)
<shritesh>
I think we all are. Except Andy lol
<very-mediocre>
i'm super brain damaged from working with high level languages for 10 years
<very-mediocre>
zig is the "no more excuses" moment for me to go back to lower level stuff
<Jenz>
I've been "playing" (probably the most correct term for me) solely with high-level languages for like what, 4 years? not much, but for as long as I've been programming (I'm 17 now)
<very-mediocre>
yeah, just to be clear that's good for understanding what's going on, but the more correct way to do that would be `for (replacement) |char, i| {str[2 + i] = char;}`
<Jenz>
Which is pretty much the exact implementation of mem.copy
wootehfoot has quit [Read error: Connection reset by peer]
<very-mediocre>
because we're dealing with bytes here, yes it'll be the same
<very-mediocre>
but imagine you were replacing structs in an array of structs, then you'd want the `for` loop, which would let zig decide whether to actually make a copy or pass a pointer
<Jenz>
Thanks again for the help, it was seriously clarifying
<very-mediocre>
don't mention it, this is a pretty helpful place, andrewrk and others were very patient with me when i first joined here
* Jenz
:)
mnoronha_ has quit [Ping timeout: 252 seconds]
mnoronha_ has joined #zig
very-mediocre has quit [Quit: Page closed]
wootehfoot has joined #zig
wootehfoot has quit [Client Quit]
wootehfoot has joined #zig
mnoronha_ has quit [Ping timeout: 255 seconds]
Jenz has quit [Ping timeout: 246 seconds]
mnoronha_ has joined #zig
<Xe>
shritesh: how do you make zig call a webassembly trap instruction?
<shritesh>
unreachable
<Xe>
ah, thanks
<Xe>
so i just make the panic handler in any .zig file?
<shritesh>
Yes. You can only have at most one
Sahnvour has quit [Quit: Leaving]
<shritesh>
Xe: does olin export all functions in the "env" module?
<Xe>
yes, as a hack because rust didn't let me use an arbitrary name, it should also work with the `olin` module
<shritesh>
Gotcha. I'm trying to get modules to work with Zig.
<shritesh>
Do you have any thoughts on WASI?
<Xe>
wasi isn't radical enough
<Xe>
they limit things like file descriptors to the posix filesystem
<shritesh>
Hmm
<Xe>
also i seem to be segfaulting the compiler
mnoronha_ has quit [Ping timeout: 252 seconds]
wootehfoot has quit [Read error: Connection reset by peer]