ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<unique_id>
First of, I'm an absolute atomics noob. I now see that the wikipedia page says that on x86 this is implemented via CMPXCHG.
<unique_id>
From a noob's perspective these seem very different. CAS modifies the atomic only if the atomic is equal to some given value
<unique_id>
xchg always modifies the atomic, returning the previous
<scientes>
thats the cmp of cmpxchg
<scientes>
i don't think zig has a xchg without the cmp
<unique_id>
I'm not sure I understand you. On atomicRmw: "This builtin function atomically modifies memory and then returns the previous value."
<unique_id>
In the system I'm designing I have atomics that can be in 3 states (0, 1, or 2). A streaming thread can bring an atomic from 0 to 1. That's a lock. Then it can take it from 1 to 2 (finish), or from 1 to 0 (cancel). With this design, which made be dumb as hell, atomic xchg is not good enough because a thread might bring a 2 to 1 having thought it was at 0.
<unique_id>
I have all of that. This is for something else.
<unique_id>
sorry for the language btw, I used the H word :)
<unique_id>
I can split the 3 state atomic into two 2 state atomics, that'll work in my case.
<unique_id>
One last thing, sorry for being so unclear and mixing singular and plural like that. I actually have lots of these atomics, one per memory/communication 'slot'. That's what I'm unsure about but at least it's simpler to implement than all alternatives.
<andrewrk>
hmm maybe my next stream should be on atomics
<unique_id>
that would be awesome
redj has quit [Read error: Connection reset by peer]
<scientes>
andrewrk, are you still getting hash mismatch?
<scientes>
perhaps just remove the secret, as with pull requests it already executes untrusted code
<unique_id>
Why am I so blind? ... @cmpxchgStrong, @cmpxchgWeak
<wink_>
andrewrk: Adding * gives me error: expected type '*(anonymous opaque at opaquetype.zig:12:31)', found '*S'
<wink_>
assert(S.getValue(ps) == 1);
<MajorLag>
because `S.getValue(ps)` becomes `getValue(S, ps);`, you're passing type `S` in and the function definition expects @OpaqueType().
<scientes>
I really need first-class functions, otherwise I'm going to have to copy the whole of mem.sort.sort just so I can have more control over the compare function
<scientes>
I need to iterate over an array of strings, sorting by each character in turn
<hoppetosse>
scientes: what do you mean by first class functions? you can pass function pointers just like in c
<scientes>
But the number of functions would be the possible length of a string (usize)
<hoppetosse>
you can also pass an array of function pointers
<scientes>
I guess I could hack it with a global
<scientes>
thats what i'll do
<hoppetosse>
good luck =)
<scientes>
you see the problem?
<scientes>
I need to pass compareByChaR(left, right, whichChar: usize) to sort.sort()
<scientes>
but there is no way to generate a function with that argument filled in
<scientes>
whichChar
<scientes>
I think this is a problem for closures
<scientes>
(wehich is what i'm doing with a global var)
<hoppetosse>
Oh, I see
<hoppetosse>
is whichChar known att compile time?
<scientes>
no, i'm iterating over the string, sorting repeatedly
<scientes>
strings
<scientes>
(I basically writing gperf in zig)
<scientes>
but all this is basically done at comptime(eventually, it depends on the comptime allocator), and a global means wasting memory at run-time
<hoppetosse>
How about generating one function for each character at compiletime?
<hoppetosse>
yeah, but check how much memory it actually takes before saying it's too much
<scientes>
4 or 8 bytes
<hoppetosse>
I just realized whichChar refers to the index of the char in the string, and not which chatacter to sort "around"
<scientes>
yeah
j`ey has joined #zig
<j`ey>
in Zig the std lib is distributed as source, right?
<hoppetosse>
yep
<j`ey>
is it expected to always be like that?
<hoppetosse>
I think so
<hoppetosse>
It has its advantages
<hoppetosse>
in terms of optimization, from inlining to link time stuff
<j`ey>
but also have to reparse and build every time!
<j`ey>
but I guess the file watching async thingy will counter that
<scientes>
maintaining shared libraries is a PITA
<j`ey>
which files does the comptime evaluation in src/?
<scientes>
mainly ir.cpp
<scientes>
but i don't know the source too well
<j`ey>
ir_eval_const_value might be it
<scientes>
comptime is too limited, maybe there is a way I can return llvm IR from a funtion, and then have the function run at compile-time
<j`ey>
I was actually wondering if it used LLVM's jit infrastructure
<scientes>
I want to write gperf in zig
<scientes>
and comptie doesn't do it, and it would be cool if I could avoid generating source code
<scientes>
my idea is to have "comptime" functions, that return LLVM IR, and are run at compile-time
<scientes>
meh generating source code isn't horrible, I just want to generate it every time and keep it out of source control
return0e has quit [Remote host closed the connection]
return0e has joined #zig
mahmudov has quit [Remote host closed the connection]
<j`ey>
andrewrk: what are you going to do with translate_c with the self hosted compiler?
<andrewrk>
j`ey, have a C API wrapper around libclang's c++ API, and then convert the c++ implementation to zig, using the C API wrapper to call into libclang
<j`ey>
OK, that's what I was expecting!
<andrewrk>
and then stage1 loses the ability to do translate C
<j`ey>
doesnt it need that?
<andrewrk>
no, it only has to build stage2
<j`ey>
but doesnt stage2 use that feature?
<andrewrk>
yeah but it doesn't need to. it'll be cleaner anyway to define llvm extern functions in .zig declarations
<wink_>
Me neither, so it seems like a weird problem, off the top of my head if we have the full source history of StageN then that history could be audited and we'd be able to "prove" StageN is non-corrputing. But just a guess.
<andrewrk>
it matters how easy it is to build zig from source in practice
<scientes>
nope, you don't understand the ken thompson hack
<andrewrk>
in practice, when building zig from source, people have gcc/clang installed and do not have zig installed