<andrewrk>
what does it looks like on the zig side/
<fengb>
Returning a pointer and length
<fengb>
Pointer is implicitly the offset to the memory buffer
<fengb>
I have a dumb hack to kludge both into a f64
<fengb>
Because JS doesn’t support u64 yet
<andrewrk>
but how do you write the bytes into the buffer on the zig side
<fengb>
Hmm, on the Zig side, you can return an allocated buffer or global buffer
jonase has joined #zig
<fengb>
In fundude, I pass in the byte buffer from JS, but that’s manually allocated via a shim
<andrewrk>
extern fn stderr(msg_ptr: [*]const u8, msg_len: usize) void; this prints some integers to the console on the js side but there doesn't appear to be a way to access the wasm memory buffer
<fengb>
Yeah that’s a raw pointer
<fengb>
You need to fetch the wasm instance and grab the memory off it
techtirade has joined #zig
<fengb>
I remember having problems trying to reference the instance before it’s created hmmm
<andrewrk>
I don't think the wasm instance has a memory property
<leeward>
I have a construct that's not behaving the way I expect. Am I being an idiot, or is this a bug in Zig? `var on = false; while (true) { light(on); on = !on; delay(500) }`
nycex- has joined #zig
<leeward>
I expect this to alternate between on and off, but when I set a breakpoint inside the loop, the debugger tells me that on is always false.
<leeward>
And when I look at the assembler output, I see nothing that suggests it's changing on's value.
<leeward>
Yeah, I don't in my actual code. It could be that my light function is doing something unexpected.
<leeward>
ok, this is special: `const mask = ~(various() | functions()) & old;` and my debugger says old is 0x0. What's mask? 0x3b
<vesim>
is the debug info generated by zig compiler valid?
<daurnimator>
vesim: should be.
<leeward>
Yep, I use it all the time.
<vesim>
I tried to set breakpoint at codegen.c.genHeader and it is never hit, but the file was generated
* leeward
currently has a debugger attached
<vesim>
setting it at c.zig:394 doesnt work either
<vesim>
or the -femit-h is using different code path? O_o
<leeward>
And you're running stage2?
heronwr has joined #zig
<vesim>
yep
<leeward>
head scratchy
<vesim>
i built it using ./zig build -Dstage1=false and after that running it like this ./zig-cache/bin/zig test lib/std/child_process.zig -fno-emit-bin -femit-h=foo.h
<vesim>
and also for me -fno-emit-bin is still hitting the linker, so i had to modify the allocateDeclIndexes function to do nothing for .elf, otherwise it was crashing the compiler
heronwr has quit [Quit: WeeChat 3.1-dev]
jonase has joined #zig
<leeward>
Well, my problem was indeed something going on in the function.
<leeward>
Not sure why it's doing what it's doing though.
jonase has quit [Ping timeout: 256 seconds]
owner has joined #zig
owner is now known as heronwr
ur5us_ has quit [Ping timeout: 264 seconds]
<vesim>
hmmm, is -femit-h even supossed to work? O_o
heronwr has quit [Quit: WeeChat 3.1-dev]
waleee-cl has quit [Quit: Connection closed for inactivity]
<leeward>
oh, hey, I think it's not
<leeward>
I vaguely remember something about that...
<leeward>
It might be in release notes. I don't see it in bugs.
<ifreund>
Yeah, I'm also really not a fan of that API
<ifreund>
still using setenv in river myself as I don't use childprocess
<ifreund>
and I haven't had time to improve std.ChildProcess or relace it with something nicer yet
<mikdusan>
"don't use childprocess" <-- what are you using?
<ifreund>
fork and exec
<kbd>
I'd still prefer unsetenv here, since it happens once at the beginning of the program and not in every call to `run` (+ getEnvMap, + .delete).
<mikdusan>
execve ?
<ifreund>
yes, that
<mikdusan>
🍴💣
<ifreund>
well, it's a little more complicated in one case as I double fork and do some cleanup to get the child process inherited by pid 1
<daurnimator>
ifreund: but why? that's so 90s
<ifreund>
river has a command that lets you run arbitrary programs. I don't want to need to wait(2) all of them
<ifreund>
that's the job of pid 1
<daurnimator>
I guess...
<ifreund>
if there's some other way that's better I'd be open to it, but I don't know of any /shrug
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
<daurnimator>
ifreund: more that I like my processes to.... be in a tree. if I started a program from river I usually would want it to stay in the tree under river
<daurnimator>
xyproto: mpz_init takes a pointer-to MP_INT
<daurnimator>
xyproto: you're going to want to do: `var x: MP_INT = undefined; gmp.mpz_init(&x);`
<xyproto>
daurnimator: thanks! I'll try that.
<daurnimator>
and don't forget `defer gmp.mpz_clear(&x);`
Cynthia has left #zig [#zig]
<xyproto>
cool, thanks. I'm trying to port the one benchmark program from the Benchmark Game where C is faster than Rust, to Zig, to compare the performance.
<xyproto>
There are probably faster ways than using gmp, but I want to try that first.
<daurnimator>
xyproto: go for it :)
<daurnimator>
xyproto: your 2nd version could try zig std libraries built in bignum support. but it probably isn't as fast as gmp... but maybe it is
<xyproto>
daurnimator: I'll compare them both, if I can make the gmp version work :)
greeb has left #zig ["WeeChat 2.9"]
olabaz has joined #zig
<olabaz>
Is there a way to redirect std.log.info to a file?
<daurnimator>
olabaz: declare a `pub fn log` in your root file
<olabaz>
hmm, and then what?
<daurnimator>
write to the file you want?
<xyproto>
then use the log function, where the body of the function writes to the file you want?
<daurnimator>
olabaz: see the big doc-comment in std/log.zig
<olabaz>
ok thanks I'll take a look
<daurnimator>
xyproto: okay now I'm looking closer... which benchmark is this?
<daurnimator>
need to use a buffered stdout.... more time spent in printing than anything else :P
<olabaz>
How can I check if an array is undefined?
<daurnimator>
olabaz: you don't
<olabaz>
daurnimator: hmm, what's the approach if I want to do something like: var input = read_line() catch undefined; if (input == undefined) { a();} else { b();}?
<daurnimator>
olabaz: undefined isn't what you're looking for, try `null`
<daurnimator>
xyproto: https://zig.godbolt.org/z/7cc1zo not very fast compared to gmp. seems like our multiplication routine could be a lot faster
<daurnimator>
(I'm getting 0.5 seconds for gmp vs 2.5 seconds for pure-zig)
<olabaz>
once I have checked that input != null, how can I change it from optional to its child type?
<daurnimator>
olabaz: `if (optional) |not_optional|` or just `.?`
<olabaz>
daurnimator: passing in input.? to a function I'm getting an error about acessing union field 'Pointer' while field 'Optional' is set
<olabaz>
oh wait nvm
<olabaz>
I was freeing input instead of input.?
kbd has joined #zig
l1x has quit [Quit: Connection closed for inactivity]
ehaas has joined #zig
waleee-cl has joined #zig
tosemusername is now known as nvmd
hnOsmium0001 has joined #zig
jokoon has joined #zig
kbd_ has joined #zig
kbd has quit [Ping timeout: 264 seconds]
tosemusername has joined #zig
nvmd has quit [Ping timeout: 260 seconds]
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
fputs has joined #zig
Akuli has joined #zig
xackus has quit [Ping timeout: 256 seconds]
gpanders is now known as greande
sawzall has quit [Read error: Connection reset by peer]
LanceThePants has joined #zig
LanceThePants has quit [Read error: Connection reset by peer]
LanceThePants has joined #zig
tnorth has quit [Ping timeout: 260 seconds]
tosemusername is now known as nvmd
GreaseMonkey has quit [Remote host closed the connection]
<justin_smith>
a const slice of const slices of 8 bit unsigned values - eg. if you split stdin by lines where each line is a slice
danyspin97 has left #zig ["WeeChat 3.0"]
<olabaz>
ah ok makes sense
cole-h has joined #zig
xackus has joined #zig
cren has joined #zig
marijnfs has joined #zig
marler8997 has joined #zig
donniewest has quit [Read error: Connection reset by peer]
donniewest has joined #zig
leeward has quit [Ping timeout: 260 seconds]
owner has joined #zig
owner is now known as heronwr
waleee-cl has quit [Read error: Connection reset by peer]
waleee-cl has joined #zig
ur5us_ has joined #zig
<marijnfs>
I'm using a c-library with aio callbacks, but they are in callconv(.C). Is there a way to still use async there?
<andrewrk>
marijnfs, no, C does not support zig's async calling convention
ltr has quit [Read error: Connection reset by peer]
<marijnfs>
:(
<marijnfs>
yeah i figured, but is there maybe a pattern
ur5us has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]
<marijnfs>
i guess i could hand over the resources in the c callback, into my own event loop
<marijnfs>
there i can use async
<andrewrk>
there is a pattern you can do
<andrewrk>
you'll have your function suspend, put its frame pointer into some data structure, then in the callconv(.C) callback, you have it mark the frame pointer as "ready" in the data structure, then you wake up the event loop so that it gets looked at and the event loop calls resume
<andrewrk>
zig's async/await semantics are extremely flexible, I promise you can accomplish what you want to
<marijnfs>
ah that's cool
<marijnfs>
yeah you can store the anyframe anywhere, seems very flexible
<marijnfs>
it's hard for your brain though
<marijnfs>
is my whole callstack stored in there or something?
<marijnfs>
even loris said he didn't quite understand it fully, and he wrote the main tutorial:P
<fengb>
I can grok the low levels of where the frame is and how the suspend/resume works, and the high level of awaiting for data
<fengb>
My brain gets fried whenever I try connecting the two
<andrewrk>
marijnfs, just the 1 call frame is stored in that function's frame
<andrewrk>
but the callsite probably is storing the callee's frame in its own, and so on
<andrewrk>
at every call site though, it is obvious where the frame memory is stored
cren has quit [Quit: cren]
sord937 has quit [Quit: sord937]
<marijnfs>
but how is the memory of all these frames handled
<andrewrk>
marijnfs, pick any async function. where its local variables are stored is decided by the callsite
<andrewrk>
if you do `var x = async foo();` then the frame of foo is stored in x
<marijnfs>
and whats exactly in the frame
<marijnfs>
return address and local variables/
<marijnfs>
?
<andrewrk>
local variables only
xackus has quit [Ping timeout: 240 seconds]
<marijnfs>
that's actually not so complicated
<marijnfs>
but also it needs to know where in the code to continue?
<marijnfs>
or is that comptime
<andrewrk>
yeah it stores that in there too, so that when you resume it, it goes to the correct place
<companion_cube>
but can you suspend from a function inside?
<andrewrk>
can you refrase that?
<andrewrk>
*rephrase
<andrewrk>
I don't understand the question
<companion_cube>
as in, could a "frame" contain several stack frames, where the yield/suspend is from an inner function
<companion_cube>
not the outer one
<andrewrk>
calling an async function is a suspend point
<andrewrk>
an async function suspends itself in order to call an async function. then when the function returns it resumes the callee
<companion_cube>
hmm so by construction, each async function has its own separate frame?
<companion_cube>
(psosibly allocated in a different place)
<marijnfs>
i think this is the main confusion
benjif has joined #zig
marijnfs has quit [Ping timeout: 256 seconds]
marijnfs has joined #zig
<andrewrk>
yes exactly
<andrewrk>
this is also known as "stackless coroutines"
nvmd has quit [Quit: Later nerds.]
<companion_cube>
interesting
<companion_cube>
it's a bit more manual than stackfull ones, but also easier I guess
Akuli has quit [Quit: Leaving]
<andrewrk>
they play more nicely with manual memory management
<companion_cube>
and yet, I suppose it'd work well with a local allocator
<andrewrk>
or a statically allocated global variable