waleee-cl has quit [Quit: Connection closed for inactivity]
keithdc has quit [Quit: leaving]
Jezza__ has joined #zig
traviss has quit [Quit: Leaving]
muffindrake has quit [Ping timeout: 264 seconds]
Ichorio has joined #zig
muffindrake has joined #zig
Ichorio_ has quit [Ping timeout: 264 seconds]
Jezza__ has quit [Ping timeout: 250 seconds]
chemist69 has quit [Ping timeout: 245 seconds]
chemist69 has joined #zig
mahmudov has quit [Ping timeout: 240 seconds]
chemist69 has quit [Ping timeout: 245 seconds]
chemist69 has joined #zig
voldyman has quit [Quit: Connection closed for inactivity]
ky0ko_ has joined #zig
ky0ko has quit [Disconnected by services]
ky0ko_ is now known as ky0ko
ky1ko has joined #zig
<ky0ko>
is it possible to get the size of an extern struct in zig? i'm working with (and porting) c code and i am trying to memset a struct to 0.
<mq32>
@sizeOf(StructType)
<ky0ko>
@sizeOf just gives me an error because it expected type 'type' and not '.cimport:2:11.server_t'
<mq32>
@sizeOf(@typeOf(your_server_var))
<ky0ko>
that worked, thanks
<mq32>
you'r welcome!
Ichorio has quit [Ping timeout: 250 seconds]
<nrdmn>
where's builtin.os defined?
<nrdmn>
hmm, I think I've found it
knebulae has quit [Read error: Connection reset by peer]
<mq32>
oh man. programming in zig is just a pleasant experience :)
<mq32>
aaand another bug
knebulae has joined #zig
jjido has joined #zig
<gonz_>
Quick check; there weren't a bunch of join/part/quit messages from my client recently, right?
<gonz_>
I've been fiddling around with using IRCCloud as a bouncer
<gonz_>
is why I ask
<gonz_>
I don't want it spamming when I open/close the client
<mq32>
nope, seems fine
lucus16 has quit [Quit: No Ping reply in 180 seconds.]
<gonz_>
Great
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
FireFox317 has joined #zig
jjido has joined #zig
FireFox317_ has joined #zig
Ichorio has joined #zig
<FireFox317_>
for the OS people in here, an other good resource might be SerenityOS by Andreas Kling (https://github.com/SerenityOS/serenity). It's a really well written kernel and userland libraries.
<mq32>
wow this looks cool
dingenskirchen has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<gonz_>
#serenityos for people interested in it as well
<gonz_>
The IRC channel is the main community spot, so it's not just a dead appendix hanging on for dear life
jmiven has quit [Quit: bye]
jmiven has joined #zig
keithdc has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
waleee-cl has joined #zig
<mq32>
hey
<mq32>
can someone help me a bit with inline assembly/x86?
<mq32>
_start gets called with with eax and ebx filled and i want to read them into certain values
<mq32>
ah damn. looks like this isn't possible in pure zig and debug mode
saskwach has joined #zig
<mq32>
can i export a symbol from inline assembler?
<nrdmn>
what do you mean by that?
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 240 seconds]
<mq32>
i need some pure assembler function
<mq32>
but i don't want to create a new assembler file for 4 lines of asm
<mq32>
so i want to export a symbol/label from the inline assembler
jjido has joined #zig
LLIypuk has joined #zig
LLIypuk has left #zig [#zig]
<saskwach>
I'm a little confused by the `if` syntax in Zig. Are `if (foo) |bar| { ... }` and `if (foo) { ... }` fundamentally different? It seems like the first one unwraps errors and executes the block regardless of value, while the second one only executes if bar's value is true. Is that right?
<saskwach>
(executes the block)
<waleee-cl>
saskwach: errors AND optionals
<saskwach>
Ok, so `if (a) |b|` has nothing to do with boolean values?
<waleee-cl>
from my relatively new experience, no, not in that form.
<saskwach>
okers
<saskwach>
Seems like an odd choice.
<waleee-cl>
well, otherwise you'd have to do a bit more ceremony for null-checking &c
<saskwach>
Or just use a different keyword. `unwrap (a) |b| { ... } or |c| { ... }` is a little longer, I guess, and adds a keyword to the language.
<waleee-cl>
I guess you have seen some longish unwrap-chains in rust?
<saskwach>
Maybe a bit.
<saskwach>
Though Rust seems to be all about the chains.
<saskwach>
I do really like just passing types around as values though. And it's refreshing to see something like D's scope statements again.
<nrdmn>
waleee-cl: rust has `if let Some(b) = a { ... }`
FireFox317_ has quit [Ping timeout: 240 seconds]
FireFox317 has quit [Ping timeout: 240 seconds]
<waleee-cl>
yeah, I have seen that one. Not terrible fond of it since it allows for unwrapping of any type
<waleee-cl>
(which can be a good thing)
<saskwach>
I find that weird in Rust. It makes me want to pattern match unwrap things in other contexts, but I can't.
<pixelherodev>
mq32, still need help?
<mq32>
yeah
<mq32>
struggling with exporting that symbol
<mq32>
and i can't use nakedcc as it will clobber eax,ebx in debug mode
<pixelherodev>
For Zig interfaces to I/O right?
<pixelherodev>
I *think* i have a better solution for you
<mq32>
ah no
<mq32>
for multiboot-to-os-entrypoint
<mq32>
but tell your idea
<pixelherodev>
Ah, you got the inline asm working then?
<mq32>
yes :)
<mq32>
i have output on the serial console
<pixelherodev>
Alright cool :)
<mq32>
yeah
<pixelherodev>
My multiboot stuff is all in Zig, no asm
<pixelherodev>
(though of course I forgot that a symbol is required for the label :()
<pixelherodev>
Ah, there's a problem with that too
<pixelherodev>
It puts it on the stack
<pixelherodev>
Minor optimization note: when calling a noreturn function with newStackCall, it still generates instructions after call
<pixelherodev>
(restoring the stack)
<pixelherodev>
More relevant optimization note @mq32 that `const magic` (I set it to const in mine since it's never changed :) generates "movl%eax, -4(%ebp) \ movl -4(%ebp), %ecx`
<pixelherodev>
Instead of moving it straight to ecx, it uses the stack first
<pixelherodev>
Even though it's literally never used for anything other than moving to ecx (which is the parameter used for the function call).
<pixelherodev>
As such, it's undefined behavior.
<pixelherodev>
Also gives the wrong value :(
<pixelherodev>
Hmm, what about pushing it straight to the stack slice? :P
<pixelherodev>
If there was @newStack with calling, this would be much easier :P
FireFox317 has joined #zig
FireFox317_ has joined #zig
mahmudov has joined #zig
<pixelherodev>
Got it working :)
<mq32>
pixelherodev, got it working here. i don't use local variables for the multiboot stuff
<pixelherodev>
Neither am I anymore
<pixelherodev>
Though I am using an @inlineCall to multiboot.parse instead of doing it manually
<pixelherodev>
There is a bug I noticed though, and not with my code, with the Zig compiler: we *can't* generate `movl%edx, -4(%ebp)` in start, but it does so as part of newStackCall
<pixelherodev>
It moves the old stack into ebp, the new stack in place, then pushes the old stack to -4(ebp)
<pixelherodev>
ebp isn't set by the entry point, which means it's *undefined*
<andrewrk>
pixelherodev, it might not be possible to do @newStackCall soundly with llvm
<pixelherodev>
The real problem then is is that practically speaking, ebp is zero at start for me
<pixelherodev>
Which means `ebp - f` is potentially writing to e.g. MMIO at the top of the address space
<pixelherodev>
andrewrk, that makes sense, but is also concerning
<pixelherodev>
Is there no operation for "load stack" without saving the old stack?
<pixelherodev>
@newStackCall as it is makes perfect sense on all non-freestanding targets
<pixelherodev>
And even on freestanding, it's only problematic within the entry point
<pixelherodev>
""The ‘llvm.stacksave’ intrinsic is used to remember the current state of the function stack"
<pixelherodev>
That's exactly the problem
<pixelherodev>
We shouldn't use that in the entry point on freestanding
<pixelherodev>
Better yet: that gets back to my optimization note from before
<andrewrk>
oh I see what you're saying
<pixelherodev>
When calling a function marked `noreturn`, we shouldn't use that
<andrewrk>
that's a good point, and should be easy to implement
<pixelherodev>
I'll see if I can implement this one myself
<andrewrk>
codegen.cpp:4212
<andrewrk>
you can look at src_return_type->id == ZigTypeIdUnreachable
<pixelherodev>
Wow yeah that is easy
<pixelherodev>
Just need to test it
<pixelherodev>
GitHub PR the preferred method of sending in patches for ziglang?
<andrewrk>
yes please
<andrewrk>
mikdusan, I wonder if ConstGlobalRefs is the culprit in #3502
<andrewrk>
either that or ConstParent
<andrewrk>
these are used to identify that a value is an array element or a struct field of a parent value
<andrewrk>
so if you interned one of them, that would potentially move it to the wrong parent
<andrewrk>
unless the ConstParent data is out-of-band of the interned value
<mikdusan>
ah i'll take a look at that
<andrewrk>
this would explain why it works for type-has-one-possible-value, because such types have 0 bytes at runtime, and so can't really have meaningful parent values
<andrewrk>
this ConstParent thing is necessary for comptime pointer reinterpreting
<andrewrk>
ConstGlobalRefs is more of an implementation detail of code-generating constants
<pixelherodev>
Found another optimization issue: there's an explicit `andl $15, %edx` generated for all align(16) objects, which shouldn't be there
<pixelherodev>
(that's an example, but it's true of all align() types)
<pixelherodev>
It's explicitly set to 16-byte alignment in the assembler anyways, so it accomplishes nothing
<pixelherodev>
(just going over the produced asm manually and I noticed this, not touching this now)
<pixelherodev>
There's about three extra instructions whenever an aligned pointer is used AFAICT
<pixelherodev>
Plus it requires usage of another register, which is both unnecessary (it could just use andl 0xFFFFFF00 on the original instead of using andl 0xFF on a copy and subtracting the copy) and potentially damaging in a function that already requires a lot of registers
<saskwach>
andrewrk, it looks like that's about implementing the allocator at comptime. I'm just trying to store which one was chosen in the struct.
<andrewrk>
that should be fine
<saskwach>
Yep, it works now; just surprising to have `comptime allocator: *Allocator` in the `new` method and `allocator: comptime *Allocator` in the struct definition.
<andrewrk>
`allocator: comptime *Allocator` the comptime is redundant here and I think there is a proposal to make such a redundant thing be an error
<andrewrk>
expressions which have expected type of `type` are always comptime evaluated
<saskwach>
Ah, I get it.
<andrewrk>
there's no such thing as comptime struct fields, but that is in fact planned
<saskwach>
Ok, so if the struct field's type is of type type, it's comptime and there's nothing I can do about it. If I wanted to store "7" but at comptime, that's a planned feature?
<saskwach>
Or, I guess, more usefully, if I wanted to store a function pointer.
<andrewrk>
there's a good chance your use case is solved with a global const
<andrewrk>
are you making a generic struct?
<saskwach>
I'm making a data structure library.
<saskwach>
Something stupid and easy for learning the language, not something useful.
<andrewrk>
you probably want `pub const foo = bar;`. is there a reason it should be a field?
<saskwach>
It's the allocator that was used to instantiate the struct. I want it to know how to make more of itself (or free itself) without having every function get passed an allocator.
<saskwach>
s/function/method
waleee-cl has quit [Quit: Connection closed for inactivity]
lunamn_ has quit [Ping timeout: 240 seconds]
lunamn has joined #zig
jjido has joined #zig
<andrewrk>
saskwach, have a look at the implementation of std.ArrayList
<saskwach>
will do
<saskwach>
Yeah, that's exactly what I'm doing. Glad it works.
<andrewrk>
it's almost like this musl code is trying to use error sets: https://clbin.com/dTGNk
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<pixelherodev>
Heh :P
<pixelherodev>
Are macros ignored in @cImport blocks?
<pixelherodev>
Seems both macros and typedefs don't work...
<andrewrk>
macros and typedefs work, if they result in an actual prototype. translating a macro itself into something usable by zig is inherently heuristic based