ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
ur5us has quit [Ping timeout: 246 seconds]
marijnfs has quit [Ping timeout: 250 seconds]
ur5us has joined #zig
ifreund has quit [Ping timeout: 240 seconds]
marijnfs has joined #zig
_Vi has quit [Ping timeout: 246 seconds]
<andrewrk> I love you all
<andrewrk> stay safe out there everybody
<hryx> 💚
<daurnimator> andrewrk: I assume you're locked up in your apartment?
<andrewrk> eh not by law
<daurnimator> andrewrk: no I mean just.... normally :P
<daurnimator> working from home isn't exactly novel for you
<andrewrk> my life is basically the same, except, due to a complete coincidence, my building still has no gas for cooking
<diginet> NYC finally shut down bars, restaurants, etc.
<diginet> thankfully
<diginet> long time coming
<hryx> same, over here in San Francisco
<diginet> yeah
<diginet> de Blasio was telling people to go have fun just a couple days
<diginet> no idea wtf is wrong with that guy's head
<fengb> UK is trying to spread it as fast as possible
<diginet> I heard
marijnfs has quit [Ping timeout: 264 seconds]
<pixelherodev> Should `try` have a higher precedence than arithmetic operations?
marijnfs has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
<andrewrk> it should require parens: https://github.com/ziglang/zig/issues/114
<shakesoda> i want precedence for basic operations (+-*/) but everything else I don't trust inherently and add tons of parens to anyways
<shakesoda> because of how confusing it all gets
<shakesoda> also, this encourages writing lines of code that aren't overly complex
<pixelherodev> I wasn't asking if it *does*, but whether it *should*
<pixelherodev> that's a compelling argument that it shouldn't
<pixelherodev> I like that proposal a lot
<daurnimator> andrewrk: with the new PR, does that mean that @TypeOf(foo[x..y]) is of different types depending on if x and y are comptime-known or now?
<daurnimator> s/now/not/
waleee-cl has quit [Quit: Connection closed for inactivity]
<andrewrk> daurnimator, yes
<andrewrk> there are other expressions in master branch where this is true
<daurnimator> seems.... weird to me. does that mean that in format/json/etc we should start treating pointers to arrays essentially the same as slices?
<andrewrk> yes - but that transition has been already happening
<andrewrk> for example `&array` coerces to a slice
<andrewrk> the difference between single-item-pointer-to-array and slice is merely whether the length is part of the type, or runtime known
<andrewrk> in the same way that it is generally preferable to have a comptime_int rather than fixed size integer when the value is known at compile-time, it is generally preferable to have a single-item-pointer-to-array rather than slice when the length is known at compile-time
<daurnimator> what about a sub-array?
<daurnimator> e.g. if I had `foo = [4]u8` `foo[1..3]` should return a `[2]u8`
<andrewrk> yep
<andrewrk> slices and single-item-pointer-to-array are fundamentally the same thing, with the difference only in whether the length is comptime or runtime known. the language should reflect that - it might take some adjustments, but this is in that direction
<daurnimator> k
<diginet> has anyone actually done work with zig on s390x?
<daurnimator> diginet: I recall someone came in for about half a day and did some playing around..... but not really I think?
<daurnimator> diginet: we'd love for someone to take it on
<diginet> ok, I was just kinda curious
<diginet> I know a little about z
<diginet> I am vaguely entertaining a port of LLVM to vax
<diginet> just for the hell of it
<diginet> that or m68k
<diginet> so it would be fun to see if zig could then be ported to one of those
<daurnimator> diginet: are you interested in just targetting it? or actually running the compiler on it?
<diginet> just targetting, not necessarily self-hosting
<daurnimator> then you don't need to port LLVM...
<daurnimator> diginet: how do system calls work there? is there a libc?
<diginet> for VAX?
<diginet> there is a port of glibc but not musl I believe
<diginet> VAX is weird in that it kind of has hardware-enforced calling convention
<diginet> oh, syscalls
<daurnimator> diginet: you started off with s390x
<diginet> oh
<diginet> right
<diginet> I;m not sure on s390x
adamkowalski has quit [Quit: Lost terminal]
<pixelherodev> Back to work on LLVM codegen :D
<pixelherodev> Parser is now sufficient for the simple tests I'm giving it (and Lexer is basically completely good when it comes to Zig output)
<pixelherodev> Register allocator design is simple and straightforward for the first target, so I hope to have the test running in the morning :D
<diginet> pixelherodev: codegen for what?
<pixelherodev> Custom 32-bit target called LIMN
<diginet> nice
<pixelherodev> I also plan on adding Z80 short-term, and x86 in the longer run
<diginet> x86 ..? it doesn't already have that?
<diginet> I've been considering porting LLVM to my own arch
<pixelherodev> This is a completely custom backend
<diginet> ah
<pixelherodev> It's self-hosted in Zig
<pixelherodev> It lexes and parses LLVM IR directly, builds AST, then passes that along to backend (with some room for optimization passes in the middle)
<pixelherodev> It's also lightning fast (runs in single-digit milliseconds in release mode), which is crucial because I plan on running it within the emulator it's targeting
<pixelherodev> And that'll of course have a massive performance overhead
<pixelherodev> Heck, if I can make a performant x64 backend, it'd probably be useful for reducing compile times in debug mode for Zig
<pixelherodev> But i haven't worked with x86 asm in so long I'm honestly not sure I'd be able to do that
ur5us has quit [Ping timeout: 246 seconds]
alichay has quit [Ping timeout: 240 seconds]
slowtyper has joined #zig
dddddd has quit [Ping timeout: 246 seconds]
slowtyper has quit [Quit: WeeChat 2.7.1]
tdog has joined #zig
<daurnimator> diginet: so what are you going to try? :) I'm intrigued
<diginet> daurnimator: depends on how much time I have
<daurnimator> diginet: it would be really cool to just target VAX or s390x from the regular zig compiler.
<diginet> I have my own compiler to work on
<diginet> daurnimator: yeah I think so
<daurnimator> diginet: for high tier support we'd need some record of the system functionality available (syscalls/libc)
<diginet> it would be neat to see zig code running on 4.3BSD/VAX
<daurnimator> diginet: what is your compiler? and if you're working on your own language; what brings you to zig?
<diginet> daurnimator: yes, own language. I've been following zig for awhile and I just like staying in the loop with emerging languages
<diginet> daurnimator: I am deeply sympathetic to zig's eschewing of any and all macros. the comptime system is conceptually a dual to the staging scheme I have in mind for my language
ur5us has joined #zig
ave_ has quit [Read error: Connection reset by peer]
lunamn has quit [Read error: Connection reset by peer]
ave_6 has joined #zig
lunamn2 has joined #zig
_Vi has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
Kingsquee has joined #zig
<Kingsquee> hol' up
<Kingsquee> is it possible to have comptime values as struct fields?
<daurnimator> Kingsquee: sure
<Kingsquee> error: expected type 'type', found 'comptime_int'
<Kingsquee> integer_bits: I
<mq32> what is "I"?
<mq32> sounds like I is an comptime_int and not a type
<Kingsquee> I's a comptime_int
<mq32> you have written "integer_bits: 4" ;)
<mq32> zig expects a type, if you want to a have a type with 4 bit width, look at @Int
<mq32> or how was it called?
<daurnimator> Kingsquee: that's a comptime-type. not a comptime-value
<Kingsquee> mq32: I essentially want rust's phantomdata on a type parameter
<mq32> what is phantomdata?
<mq32> can you elaborate that?
<Kingsquee> oh god what's a phantomdata
<Kingsquee> so if I have struct Foo<T>
<Kingsquee> but T is a type that's used only for storing information at compiletime, rather than defining the type of a field
<mq32> ah, just export it from your type instead of a field
<Kingsquee> you still have to store the type as a field somehow, or the compiler will complain about an unused type parameter
<Kingsquee> so we use a field of type PhantomData<T>
_Vi has quit [Ping timeout: 246 seconds]
<mq32> fn(comptime some : Something) type { return struct { pub const phantm = some; }; }
<Kingsquee> ooh const
<daurnimator> mq32: I was just writing the same thing :)
<mq32> just a public "static" war
<mq32> *var
<mq32> we don't need war, we need var! :D
<daurnimator> Kingsquee: comptime struct fields are something else entirely :)
<Kingsquee> VAR
<Kingsquee> WHAT'S IT GOOD FOR
<Kingsquee> alright this makes sense
<Kingsquee> thanks!
* mq32 sobs about bad software and compiler infrastructure
<mq32> kids, never use C++Builder!
<mq32> it is pain
<Kingsquee> so, is there a difference between struct { foo: u8 } and struct { var foo: u8 } ?
<mq32> yes
<daurnimator> Kingsquee: 1. is a field. 2. is a namespaced global
<mq32> the one thing is a field (the first one)
<mq32> damn you, daurnimator! :D
<Kingsquee> dat wpm tho
* Kingsquee swoons
<daurnimator> traditional cherry blues baby
<mq32> i should search my usb-ps/2 adapter
<mq32> model m masterrace *grin*
<diginet> model F is even better
<diginet> nkro
ur5us has quit [Ping timeout: 246 seconds]
<Kingsquee> so if I have fn Foo(comptime T1: comptime_int, comptime T2: comptime_int) and I want to return an integer with the number of bits T1 + T2
<Kingsquee> how would I do this
mq32 has left #zig ["Leaving"]
mq32 has joined #zig
<Kingsquee> i.e. const foo: u3 = Foo(1, 2);
<mq32> you want an integer with the width on T1+T2 bits?
<mq32> or with a value of T1+T2?
<Kingsquee> width
<mq32> const I = @Type(std.builtin.TypeInfo{ .Int = .{
<mq32> .is_signed = false,
<mq32> .bits = 40
<mq32> } });
<mq32> just replace "40" with T1+T2
<mq32> or some other arbitrary math that yields a comptime_int
<mq32> (note that *any* integer type coerces to comptime_int)
<Kingsquee> what would the return value be?
<mq32> ah, you're messing up type and value ;)
<Kingsquee> oh wait I'm being dumb
<Kingsquee> yes
<mq32> return value is a number :D
<Kingsquee> I HAVE A CONCUSSION
<mq32> it's a bit unusual to have "type is only a expression/value" semantic :D
<mq32> but its soooo powerful
<diginet> it would be interesting to attempt to provide a formal account of zip's type-level computation
<Kingsquee> this language is amazing
<Kingsquee> and my head hurts
<Kingsquee> goodnight
Kingsquee has quit [Quit: Konversation terminated!]
TheLemonMan has joined #zig
<diginet> ok
<TheLemonMan> porting Zig to linux/s390x should be pretty straightforward
_whitelogger has joined #zig
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
marijnfs has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
ifreund has joined #zig
<diginet> TheLemonMan: I want to see zig on VM or z/OS
<diginet> actually, no, MVS is always and I don't want to touch it, ever
<diginet> s/always/awful
<diginet> zig on VMS, on the other hand, would be cool
<TheLemonMan> zig on toasters, zig on mainframes, zig everywhere
<diginet> I am currently working on targetting my compiler for BLS, sooooo
mahmudov has quit [Ping timeout: 256 seconds]
<diginet> which is, btw, a sign-magnitude system
<diginet> well kinda. it's weird. BLS was JS before JS existed. It really on has floats.
<diginet> (well, and descriptors. but among numbers it only has octal floating point)
mahmudov has joined #zig
<mq32> diginet: zig has two's comlement integers by-definition, so you have to emualate that then…
<diginet> mq32: I thought default arith operators had error on overflow by definition?
<mq32> yes, but you have wrapping-operators
<diginet> well, those could be emulated
<mq32> Wrapping Addition.
<mq32> Guaranteed to have twos-complement
<mq32> also @bitCast: Convert i32 to u32 preserving twos complement
_Vi has joined #zig
zfoo_ has joined #zig
marijnfs has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #zig
marijnfs has quit [Quit: leaving]
marijnfs has joined #zig
marijnfs has quit [Quit: Lost terminal]
marijnfs has joined #zig
<marijnfs> how do i print a c string properly?
<marijnfs> i get u8@7f50108d5115
<marijnfs> when i format it
<mq32> {c}
<mq32> afaik
<fengb> diginet: there’s another recent language that’s writing it’s own OS 🙃
<fengb> Wait nvm, z/OS is a real thing. I’m being dumb
<marijnfs> as {s} seems to work as well
<marijnfs> how do i get field access to a c struct?
<mq32> use it like any other struct
<mq32> extern struct is not different in usage than c struct
<mq32> except you mean a c pointer
<mq32> then you need .*.
<marijnfs> m32 thanks! that works
<marijnfs> that doesn't work automatically huh
<mq32> yeah
<mq32> because zig does not allow direct pointer access to pointer-to-many
<mq32> and a C pointer is both pointer-to-one and pointer-to-many
<mq32> if you import your functions yourself, you can always use [*] or * instead of [*c]
dddddd has joined #zig
<marijnfs> mq32: ok because a c pointer might be used as an array
dingenskirchen has quit [Read error: Connection reset by peer]
dingenskirchen has joined #zig
<mq32> exactly
sammich has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
slowtyper has joined #zig
daex has joined #zig
daex_ has quit [Ping timeout: 240 seconds]
sammich has joined #zig
forgot-password has joined #zig
zfoo_ has quit [Read error: Connection reset by peer]
<forgot-password> Is there an explanation for builtin.AtomicOrder? I'm trying to grasp atomic operations in general, but I can't find any proper resources :/
<mq32> read the c++ documentation on those :D
<mq32> they are semantically the same
<mq32> damn :D
<mq32> today is the day of ninjas
<forgot-password> Well well, which one am I supposed to click? :P
<forgot-password> Thanks though
<mq32> it's a bit of work to get your head wrapped around those semantics
<mq32> especially as they are not relevant on x86 :D
<mq32> but on ARM
<forgot-password> Yours seem too shady, so I chose this one: https://en.cppreference.com/w/cpp/atomic/memory_order
<fengb> Fair point. I wouldn't trust my links either
<mq32> *laughing*
<marijnfs> is there a thread safe queue?
<forgot-password> There is @import("std").atomic.Queue, afaik
<marijnfs> ah nice
<marijnfs> it can be hard to find this stuff sometimes
<TheLemonMan> this video cleared any doubt I had about atomics https://www.youtube.com/watch?v=dQw4w9WgXcQ
<forgot-password> Wow, thank you for the enlightenment, I can only suggest everybody else to check it out :)
<forgot-password> Does an @atomicStore alone prevent torn reads?
<forgot-password> I feel like my questions seems kind of underspecified?
<mq32> i think it depends on the mode you pass in
<mq32> using seq_cst will create a barrier for reordering
<mq32> so all reads/writes before your store will be executed before the store
<mq32> no reordering will happen
alva has quit [Ping timeout: 245 seconds]
<forgot-password> So if I dereference a pointer on one thread, and change the pointer on another one, does it guarantee to fully load the pointee first?
AlexMax has quit [Ping timeout: 245 seconds]
AlexMax has joined #zig
<mq32> pointers should be inherently atomic as they can fit in a register
<andrewrk> the way that atomics relate to threads has only to do with data races. so the answer is yes, you will see one value or the other, but not a torn read
<andrewrk> the other important property of atomics is how they communicate to the compiler, and how atomic operations act on the same thread with respect to each other and other memory operations
<TheLemonMan> uh I think that since the atomic write locks the cache line it's writing to the deref will either read the old value or the new one
<mq32> i wonder…
<mq32> pointers are not atomic on AVR hardware
<mq32> so reading/writing a pointer is not an atomic operation and they should be load with an atomic operation (p = @atomicLoad(&ptr) instead of p = ptr)
slowtyper has quit [Quit: WeeChat 2.7.1]
Akuli has joined #zig
<mq32> huh. i just tried to compile a pointer load for AVR
<mq32> and the code exploded
<andrewrk> you might try llvm10 branch for AVR
<mq32> hm. i should update some day anyways :D
<mq32> but godbolt-avr right now is borked
<mq32> LLVM ERROR: Cannot select: 0x555556d20c40: i8,ch = load<(dereferenceable load 1 from %ir.result)> 0x555556d20b70, FrameIndex:i16<0>, undef:i16, example.zig:6:5
<mq32> 0x555556d20eb0: i16 = FrameIndex<0>
<mq32> 0x555556d21050: i16 = undef
<mq32> ah, AVR support in LLVM was experimental until now
<mq32> andrewrk: How's the 0.6.0 release going on?
<mq32> one month left if i read the milestone right?
<fengb> We need to increase the bus factor
<mq32> exp(bus)
marijnfs has quit [Quit: Lost terminal]
<andrewrk> mq32, yes that's right. it's about time to start working on release notes
<andrewrk> I'm sneaking in one more major language change first tho
<andrewrk> #4752
<mq32> oh, spoilers?
<mq32> oh nice! this is useful :)
<andrewrk> I expect llvm 10 to be released this week
<fengb> Sweet, that’d fix some of my weirdo workarounds
<mq32> nice! i feel sad that i don't have much time right now to continue my projects, but looking forward to it :)
<fengb> Hmm... would it be a problem if we further blend array pointers and slices?
discip has joined #zig
<mq32> want to finish my pet language project :)
Bekwnn has joined #zig
FireFox317 has joined #zig
<FireFox317> TheLemonMan, the video xd, i had to laugh :^)
<mq32> FireFox317: one of the best talks about atomics for sure
<FireFox317> definitely
mahmudov has quit [Ping timeout: 246 seconds]
<discip> Comptime is very useful but it's bloating compilation times significantly. Are there plans to improve its performance or should I just treat comptime like C++ templates?
<discip> (aka, use them sparingly)
<FireFox317> Does someone in here know why a global variable that is set to undefined ends up in the bss section? Like the bss section is for static data that is zero right? Shouldn't it end up somewhere else?
<forgot-password> discip: I noticed that as well. When I wanted to pre-populate a table with data it took multiple seconds at comptime and only a few milliseconds at runtime.
<TheLemonMan> FireFox317, is it 0xAA-filled when you read it back?
<BaroqueLarouche> don't judge comptime performance yet, it should be better in the self-hosted compiler
<TheLemonMan> yeah comptime is slow, check out #4055 for more info/news
<discip> forgot-password: My number are 15-20% increase in compilation time per comptime function. One of those functions I wrote myself and the other is allocPrint
<FireFox317> TheLemonMan, i'm doing bare metal stuff
<mq32> FireFox317: i think it's actually reasonable to put "undefined" variables into .bss
<mq32> because it imposes the lowest overhead
<Bekwnn> shouldn't caching make comptime not really a pain on rebuilds though?
<TheLemonMan> FireFox317, hm? you can still check the value and flash a led/print a message/blow up if the value is not correct
marijnfs has joined #zig
<FireFox317> TheLemonMan, yeah sure i'm doing qemu stuff now anyway so all the memory is already 0, but i remember for clashos (rpi) we had a big static buffer and on startup that took a long time to zero all that data
<TheLemonMan> oh, are you compiling in debug mode?
<TheLemonMan> you probably had a slow memset implementation heh
<FireFox317> But in that case i could probably use linksection to put it in a different section which i wouldn't zero out on startup
<FireFox317> TheLemonMan, yes maybe. But I was expecting global static undefined data in release mode to be really undefined, but it still ends up in the bss section
discip has quit [Remote host closed the connection]
<andrewrk> discip, I expect comptime perf to roughly match cpython's perf in the future. right now it is an order of magnitude worse
<FireFox317> I guess there is no such a section that isn't initialized, we only have .text, .data, .rodata, .bss
<TheLemonMan> yeah that's somehow expected in release mode, why should LLVM place garbage in those values? that'd be just a waste of space
<TheLemonMan> were you seeding some RNG with that data? :^)
<andrewrk> for non-freestanding applications, bss makes the most sense since it's "free". but for freestanding applications, it could make sense to have a truly undefined linker section, that the initialization code would not have to memset
<FireFox317> andrewrk, that is exactly what i mean, had some trouble explaining it
<andrewrk> actually we already kinda want something like this even for non-freestanding- I believe I opened a proposal to put undefined stuff in its own linker section and then memset it to 0xaa before main()
<FireFox317> only in debug modes indeed
<FireFox317> for now i guess i can just put the data in another section which i don't initialize at startup
<andrewrk> that should work
<TheLemonMan> I really doubt QEMU will pass you non-zeroed pages
<andrewrk> I believe the goal is to memset() fewer bytes on startup
<FireFox317> they pass zeroed data indeed, my code was working when i forgot to zero the bss section
<FireFox317> but thanks for the insights guys, i'm understanding it better now :)
<frmdstryr> FireFox317 you could just modify the startup asm / code to just not set the bss at all
<FireFox317> frmdstryr, that's a problem because if you define a global static variable and set it to zero it will also end up in the bss section
wilsonk has quit [Ping timeout: 256 seconds]
<pixelherodev> `linksection()`?
recombinant has joined #zig
wilsonk has joined #zig
jjido has joined #zig
<FireFox317> a wait, i think there is .sbss which is for zero initialized global stuff and normal .bss for uninitialized `var x: u32 = undefined`
<FireFox317> nvm s stands for small in this case lol
<TheLemonMan> IIRC it's not even used by ARM
jjido has quit [Client Quit]
<frmdstryr> Makes sense, why waste the flash space .... Sounds like you really need a separate section then.
<FireFox317> TheLemonMan, arm not, RISC-V apparently does
<andrewrk> FireFox317, you can linksection() all the undefined ones with ".myspecialbss", and then in the script, put .myspecialbss into the end of bss after the other bss, but capture the pointer address at that point. then when you memset, use that address as the end
<andrewrk> does that make sense?
<FireFox317> ha andrewrk thanks, yeah i knew how to do that :)
<FireFox317> maybe i should explain a bit more why i want this. I'm trying to write a bare metal app completely in zig. So obviously i need some inline assembly, but i also need some space for a stack and i defined that as a global undefined variable and did not expect the compiler to put it in the bss. There is no need to zero out the stack :) Thanks for the help guys!
<FireFox317> But the workarounds are clear now
<andrewrk> I think this can be improved eventually
<frmdstryr> Good luck. I spent part of the last 3 months porting parts of the stm32h7 hal to pure zig. It's a nontrivial time consuming task. Pretty sure the biggest reason why people __wont__ use zig for embedded is no vendor support
<FireFox317> well for now it's still a quite pleasant task actually :)
<andrewrk> if the hal is in c you can still use zig to cross compile it
zfoo_ has joined #zig
forgot-password has quit [Quit: leaving]
mahmudov has joined #zig
mattmurr has quit [Quit: ZNC 1.7.5 - https://znc.in]
<FireFox317> andrewrk: using `-target riscv64-freestanding-none -mcpu=baseline_rv64-c` still outputs compressed instructions, the c in cpu-features stands for compressed instructions, but i'm removing that. --verbose-llvm-cpu-features outputs `name=kernel triple=riscv64-unknown-unknown-unknown
<FireFox317> name=kernel target_specific_features=+64bit,+a,-c,+d,-e,+f,+m,`
<FireFox317> name=kernel target_specific_cpu_args=
<FireFox317> i'm using llvm10 branch btw, but that shouldn't matter?
<andrewrk> that debug output means that we have successfully requested "-c" from LLVM, so this may be an upstream bug
<andrewrk> the next step will be creating a small reproducible test case for an llvm bug report
<FireFox317> yes but the triple is riscv64-unknown-unknown-unknown is that correct?
<andrewrk> yeah that's riscv64-freestanding according to llvm
<pmwhite> I may have asked this here before, but is there a way to not display the command that failed on a compilation failure? I'm on nixos, and I'm linking several libraries, so the command that gets built up is pretty large and scrolls the errors off the screen when I get a compiler error.
alva has joined #zig
<FireFox317> okay, will try to make a small test case
<andrewrk> pmwhite, there is not, but maybe there should be
<andrewrk> FireFox317, if you can reproduce the problem with clang that would be 90% of the work of an llvm bug report
<andrewrk> if you cannot reproduce with clang, maybe zig is doing something horribly wrong
<fengb> "No discussion of things that are both controversial and off-topic." lucky for me I'm usually either-or 🙃
<FireFox317> andrewrk: happens with release-safe and release-fast only, release-small works fine. what is the clang equivalent of release-safe/fast?
<andrewrk> -O3
jzelinskie is now known as jzelinskie[m]
jzelinskie has joined #zig
zfoo_ has quit [Remote host closed the connection]
<FireFox317> andrewrk: i was missing a volatile, that was the problem xd
frmdstryr has quit [Ping timeout: 256 seconds]
<andrewrk> hmm how did that end up causing compressed instructions?
<ifreund> anyone haven a simple example build.zig I could copy from? docs seem to be sparse currently
<FireFox317> it didnt. I thought it was a compressed instruction, but it wasn't.
frmdstryr has joined #zig
<BaroqueLarouche> https://github.com/mlarouche/zigimg/blob/master/build.zig is that simple enough ?
<ifreund> BaroqueLarouche: that's great, thanks
<mq32> ifreund, what do you need on features?
<mq32> a default build.zig can be created via
<mq32> zig init-exe or zig init-lib
<ifreund> I'm planning on doing advent of code 2018 to get my feet wet
<ifreund> i think i'd just use addExecutable there instead of addLibrary in the zigimg example
ur5us has joined #zig
<andrewrk> FireFox317, ah ok that actually makes me feel better
<ifreund> mq32: thanks, init-exe was really what I was looking for it turns out
<mq32> you're welcome
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
Akuli has quit [Quit: Leaving]
marijnfs has quit [Ping timeout: 246 seconds]
tdog has quit [Ping timeout: 246 seconds]
ifreund has quit [Ping timeout: 246 seconds]
ifreund has joined #zig
jjido has joined #zig
ifreund has quit [Quit: WeeChat 2.7.1]
marijnfs has joined #zig
ifreund has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
alichay has joined #zig
marijnfs has joined #zig
ifreund has quit [Ping timeout: 250 seconds]
ifreund has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
<danyspin97> Is there any way to treat a literal string as []u8 instead of "*const []u8"
<danyspin97> found in the docs, thanks anyway!
<danyspin97> well the doc shows an example but do not solve it
<mq32> no, you cannot use a literal as a mutable string
<mq32> you can dereference the literal though, it's a pointer-to-array:
<mq32> var mut_string = "hello".*; mut_string[0] = 'A';
<danyspin97> that would be handy to do in tests at least
<mq32> just go with the reference-method, it's simpler
<mq32> and mutable string literals are a bad idea since C
<danyspin97> fn (myarr: [*]u8) ?
marijnfs has joined #zig
<mq32> this is something different ^^
<mq32> what do you want to achieve in the end?
<danyspin97> i have a function that takes []u8 because it will modify the string
<danyspin97> then in test I call foo("my literal")
<mq32> that's not the right way, as string literals are immutable ;)
<mq32> and no, it's not a good idea to allow this for tests or anything anyways
<mq32> just introduce a variable
<mq32> you should test the mutation anyways
<danyspin97> yea but that would mean 3 more variable per test
<danyspin97> 2 variables*
<mq32> so?
<danyspin97> hmm I'll try and see first
<mq32> do that :)
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #zig
ifreund has quit [Quit: WeeChat 2.7.1]
ifreund has joined #zig
shachaf has quit [Ping timeout: 255 seconds]
shachaf has joined #zig
FireFox317 has quit [Ping timeout: 256 seconds]
<danyspin97> if I have `var line : [4]u8 = " foo";`
<danyspin97> and a function parseKey(line: []u8) *const []u8
<danyspin97> how can I pass line as the arg of parseKey?
<mq32> parseKey(&line)
<mq32> why do you return a pointer-to-slice?
<danyspin97> const []u8 is considered a syntax error
<fengb> []const u8
frmdstryr has quit [Ping timeout: 256 seconds]
<danyspin97> which cannot be used with operator ==
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<fengb> Doing == is bad with any array value
jjido has joined #zig
<mq32> use std.mem.eql()
<danyspin97> sorry, I forget that zig is low level language
<danyspin97> Thanks!
<mq32> happens from time to time
marijnfs has quit [Ping timeout: 256 seconds]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has joined #zig
<danyspin97> if I change line inside this function, the change is not propagated outside: `parseKey(line: []u8)`
<danyspin97> which I guess is because the argument has been copied
<mq32> works for me™
<mq32> how do you modify line?
<danyspin97> line = line[start .. end]
<mq32> well
<mq32> this should not be allowed in the first place as aarguments in zig are immutable
<pixelherodev> Got my first function compiled using my new backend architecture :D
<mq32> also this will not change the slice you passed in
<mq32> but only exchange the refernce
<danyspin97> as arguments you mean start and end?
<mq32> no
<danyspin97> I get it
<mq32> if your funtion is "fn parseKey(line: []u8) ???" then you are not allowed to change "line"
<mq32> because "line" is immutable
<mq32> note that the contents of "line" are NOT immutable
<danyspin97> but the size is
<danyspin97> so I should use instead a pointer to u8
<mq32> no
<mq32> what should your function do?
<danyspin97> parse a line, get a key and the rest of the line
<mq32> so parsing something like " foo := bar"
<mq32> and return both "foo" and "bar"
<danyspin97> which I resolved using OOP first, but now that I am translating to zig I am changing the paradigm
<danyspin97> kind of that
<mq32> look at the following code (pllease wait, i'm typing as fast as i can)
<danyspin97> no problem, take your time
<mq32> here ya go
<mq32> that function will search for ":=" and will return what is in front of := as key, with spaces and tabs stripped
<mq32> same for value
<mq32> value is after ":="
<mq32> if no ":=" is found, "null" will be returned
<danyspin97> thanks!
<mq32> ah well
<mq32> it's index + 2
<danyspin97> now I think I need a huge refactor..
<mq32> but hey, aside from that it works :D
<mq32> danyspin97: much simpler than you initially planned?
<danyspin97> just different
<danyspin97> lemme show you
<danyspin97> it parses the line "foo=bar" and returns "=bar", then I call .key to get "foo"
<danyspin97> then I use another class that takes "=bar" and returns "bar" and another that check for quotes, but I guess it's time to rewrite this mess :D
<mq32> yep, sounds pretty overengineered
<danyspin97> mq32: just checked your code (with tests) and works file, thanks for your huge help!
<mq32> you're welcome
<danyspin97> and tests now look better :D
<danyspin97> since you've done the code and it is now on github, do yo
<danyspin97> u want your name on the copyright?
<mq32> i don't care
<mq32> it's nice to know that i helped you but that function isn't worth a copyright notice :D
<mq32> i'm off to bed
<danyspin97> g'n :)
recombinant has quit [Read error: Connection reset by peer]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]