<frmdstryr>
Can @setCold be made to work on if / switch branches?
<pixelherodev>
I don't think so
<pixelherodev>
I could be wrong, but I think @setCold(true) changes the used calling convention to coldcc
<pixelherodev>
Which isn't something that can be done to branches without adding in a function call
<pixelherodev>
Which has a greater cost than any gains would likely be anyways
<daurnimator>
Does that mean we need a 'likely' builtin?
<mq32>
daurnimator: i remember this topic i think
<pixelherodev>
I don't think there's any practical way to do this anyways
<mq32>
andrewrk said something about the "positive" branch is always preferred or something, i can't remember fully anymore, but there was something like that
<pixelherodev>
There's no real optimization you can do as the compiler / assembler
<pixelherodev>
Yeah, that seems to use a GNU extension
<Snektron>
is likely/unlikely in assembly just swapping the branch cases?
<daurnimator>
Snektron: its also a hint to the optimiser
darithorn has quit [Read error: Connection reset by peer]
<Snektron>
yes, but i mean on an assembly level
<pixelherodev>
That's the only thing I remember doing, but I never claimed to be a good asm optimizer :)
<daurnimator>
Snektron: it may e.g. refactor the code so that the "likely" branch is assumed, and the "unlikely" branch is only branched on later and the work that the "likely" branch did is undone
<daurnimator>
I recall there was lots of discussions around choices of instructions. particularly around when to prefer cmov
<mq32>
pixelherodev: random thought on optimization
<mq32>
but it's better to put the likely branch in the "jump not taken" part, so caches will not be violated as you continue with linear execution
<mq32>
if you jump, you may instantly trigger a cache invalidation which should not happen with cache preheating from linear execution
<daurnimator>
In any case, are you looking for @errorName
<pixelherodev>
daurnimator, ah right :P
* pixelherodev
facepalms
<pixelherodev>
Of course there's a built in for it :P
<Cadey>
is there such a thing as an assert that works in release mode?
<daurnimator>
Cadey: if (!x) @panic(...)
<Cadey>
fair neough
<Cadey>
enough*
lunamn has joined #zig
<Cadey>
how do you use a fixed length array as a slice?
<Cadey>
ah @bytesToSlice
hyu has joined #zig
<Cadey>
nope
<pixelherodev>
Cadey, have you tried `array[0..]`/
<pixelherodev>
?
<pixelherodev>
You can take a slice of an array
<daurnimator>
Cadey: &
ur5us has quit [Ping timeout: 245 seconds]
<daurnimator>
IIRC taking the address of an array returns a slice.
<daurnimator>
otherwise yeah, [0..]
<Cadey>
yep that works too
<Cadey>
thanks for the help, kinda rusty on zig lol
<daurnimator>
<insert joke about Rust (the language)>
frmdstryr has quit [Remote host closed the connection]
frmdstryr has joined #zig
<Cadey>
i love how small the compiler output is though
<Cadey>
i just got a case where a binary was smaller than its source code
<Cadey>
(webassembly)
hyu has quit [Quit: Leaving]
hyu has joined #zig
ur5us has joined #zig
deesix has quit [Ping timeout: 276 seconds]
deesix has joined #zig
hyu has quit [Quit: Leaving]
hyu has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
hyu has quit [Ping timeout: 252 seconds]
<stratact>
<daurnimator> <insert joke about Rust (the language)>, "Rust programmer: Hey I thought a made a copy, where is the original? Compiler: Original? What are you talking about? :P"
merlyndmg has joined #zig
<daurnimator>
stratact: the pun should be related to Cadey's "rusty on zig""
<Cadey>
but seriously
<Cadey>
holy crap zig uses almost no memory in webassembly
<Cadey>
my cat clone uses 2 pages (128k), but that seems to be the minimum amount
<daurnimator>
Cadey: time to figure out why its not smaller
<daurnimator>
WebAssembly is marked experimental. I have no idea if it works...
<andrewrk>
Cadey, 0.5.0 has a really primitive allocator for wasm. It does not have the ability to free pages. fengb recently improved it, and it adds about 1K to the binary size
<Cadey>
daurnimator: i'm not talking binary bloat
<Cadey>
i'm talking runtime bloat
<andrewrk>
a "cat" program shouldn't need to use heap allocation though, so you shouldn't have to pay that cost
<Cadey>
right now it uses 2 pages of webassembly ram, however it seems to only do stuff in the first page of ram
<daurnimator>
Cadey: oh. you shouldn't have any runtime allocations at all for a program like yours
<Cadey>
yeah
<daurnimator>
andrewrk: you beat me to it >.<
adamkowalski has joined #zig
<Cadey>
that's why it's like 652 bytes of wasm binary lol
<Cadey>
it looks like if i had a buffer of exactly 928 bytes, i could fit it all within one page of ram
<fengb>
LLVM pegs the wasm stack size at around 66K. I'm not sure why. It's not from any sane heuristic as far as I can tell: https://github.com/ziglang/zig/issues/3735
<daurnimator>
Cadey: yes I know. use `std.fifo.LinearFifo(u8, .{ .Static = 2048 });` instead.
<andrewrk>
daurnimator, why?
<daurnimator>
andrewrk: it allows you to easily do a partial read after a partial write.
<andrewrk>
ah
<andrewrk>
we still have an issue with std.os.write not exposing partial writes
<andrewrk>
this makes it so that the zig std lib can work, and application writes just have to put `pub const os = @import("cadey's olin package");` in their root source file
<Cadey>
oh sweet
<andrewrk>
then a cross platform cat app will work in olin, with that one line
<Cadey>
andrewrk: is it normal for the zig low level warn support to assume that stdout is the same file descriptor?
<pixelherodev>
So, hypothetically, if it shows heap allocated: 0, that's a mistake?
<pixelherodev>
Out of date valgrind or something?
<daurnimator>
Cadey: no
<adamkowalski>
Can somebody help me figure out why my test is failing? I am trying to wrap an allocator with an arena inside of a struct rather then in the test block and this leads to the failure. Here is the code befire: https://pastebin.com/bTY3upgn and after: https://pastebin.com/Z3598Z2d
<daurnimator>
pixelherodev: are you sure you allocated on the heap? :)
<adamkowalski>
The test is on line 46
<Cadey>
ah i see
<adamkowalski>
and 55 respectively
<pixelherodev>
daurnimator, I tried with both std.heap.page_allocator and std.heap.c_allocator
<daurnimator>
pixelherodev: got a runnable snippet ?
<adamkowalski>
andrewrk: I tried following the pattern I saw in the standard lib, where the struct stores the arena, and then every other field that needs to allocate starts as undefined. Is there a way to avoid that?
<pixelherodev>
... well... no?
<pixelherodev>
daurnimator, I was trying to measure RAM usage of my LLVM parser
<daurnimator>
adamkowalski: fails with what?
<adamkowalski>
Test [1/2] test "constant"...
<adamkowalski>
Tests failed. Use the following command to reproduce the failure:
<adamkowalski>
daurnimator: I get a bad access when allocating, which doens't make senes
<adamkowalski>
If I just pass the allocator directly to ArrayList rather then wrapping in an arena then doing &arena.allocator I can make it compile and run
<daurnimator>
adamkowalski: `graph.constants = std.ArrayList(Constant(T)).init(&graph.arena.allocator);` that might be pointing to the arena on the stack
<mikdusan>
yup
<adamkowalski>
Ah, I thought it would be named return value optimization
<adamkowalski>
Wouldn't it allocate at the callers memory
merlyndmg has quit [Ping timeout: 260 seconds]
<adamkowalski>
daurnimator: so I have to allocate on the heap?
<adamkowalski>
or pass in a pointer to the graph which the caller allocated on the stack and then set that?
<daurnimator>
adamkowalski: sounds like you have a great example of why we need @resultLocation
<daurnimator>
I recall there was an open proposal but I can't find it
<adamkowalski>
What would you recommend for now?
<mikdusan>
adamkowalski: you could change `pub fn init()` to require `init(self: @This(), ...)` and at callsite and at caller, do `var graph: Graph(f64) = undefined; graph.init(allocator);`
<adamkowalski>
Is the way I had things originaly idiomatic?
<adamkowalski>
The only issue I had with how I did things in the first version is that it assumed the allocator passed in was an arena because I want the entire graph to have the same lifetime
<adamkowalski>
mikdusan: yeah I might do that, thanks! I prefer to avoid undefined if possible, but I supposed it's the most reasonable option here
<daurnimator>
adamkowalski: yes you had idiomatic code and it should work (maybe with a @resultLocation() added) or error (which would be the `fixed`/`nocopy` proposal).
<mikdusan>
adamkowalski: i've used that pattern to allow for both stack/heap choice for caller
<daurnimator>
adamkowalski: mikdusan has give you a good workaround there: you should make a note in #2765 about your type of usecase
<adamkowalski>
thanks! I'll use mikdusan's solution for now. daurnimator result location should give us the same benefit of being agnostic about stack/heap right. Since it's "return by value" so the caller decides where it is stored
<daurnimator>
adamkowalski: it would let you do: `graph.constants = std.ArrayList(Constant(T)).init(&@resultLocation().arena.allocator);`
<Cadey>
what is the stdlib zig way to grab data from stdin?
<daurnimator>
what sort of data?
<Cadey>
yes
<Cadey>
bytes
<daurnimator>
`const stream = &io.getStdin().inStream().stream; n = try stream.read(....)`
<adamkowalski>
daurnimator: I think named return value optimization would be even cleaner. Since we already have a pattern wher init usually returns the struct
<adamkowalski>
why is that different then saying if I have a variable which I later return, just store that at the callers memory instead
<adamkowalski>
mikdusan: I tried your solution and it now compiles and runs just fine! Thanks. I guess my C++ background is failing me and I need to be more C like haha
<Cadey>
andrewrk: i think the varargs patch broke the sample app :D
<Cadey>
std.debug.warn("All your base are belong to us.\n"); no longer compiles
<pixelherodev>
Almost got the test program emitting valid assembly for my LLVM backend! :D
<pixelherodev>
Register allocation is good, basically just need to implement function calls (and register push / pops for them)
<Cadey>
huh
<Cadey>
it does look like the std.debug.warn code relies on a known file descriptor for stderr
<Cadey>
unless i am doing this very wrong
<Cadey>
which i might be
<Cadey>
i am trying to do this:
<Cadey>
pub var STDERR_FILENO: fd_t = resource.io_get_stderr();
<Cadey>
(in the os definition)
<pixelherodev>
It does require a FD, but you have to return it from os.open IIRC
<Cadey>
/home/cadey/prefix/zig/lib/zig/std/io.zig:48:30: note: referenced here
<Cadey>
return File.openHandle(os.STDERR_FILENO);
<Cadey>
the compile error for that is "unable to evaluate constant expression"
<Cadey>
is there a way to defer that expression evaluation to runtime?
muffindrake has quit [Ping timeout: 252 seconds]
<pixelherodev>
What did you define fd_t as?
<Cadey>
i32
<Cadey>
which is also the return type of resource.io_get_stderr()
<pixelherodev>
Right
<Cadey>
its actual definition is `pub extern fn io_get_stderr() i32;` (because it's imported from the webassembly environment)
<Cadey>
or is the fd_t distinct from i32?
<daurnimator>
Cadey: have a look at the windows path
muffindrake has joined #zig
<daurnimator>
it grabs it from the PEB
<Cadey>
yeah, i think we might need to add a openHandle patch from the root module
traviss has quit [Quit: Leaving]
<daurnimator>
Cadey: huh? the `io.getStderr()` is what would call `io_get_stderr`
<Cadey>
er yes sorry
<Cadey>
i'm getting tired
<Cadey>
either way
<Cadey>
i'm not seeing how to make io.getStderr call io_get_stderr
qbradley has quit [Remote host closed the connection]
darithorn has quit [Read error: Connection reset by peer]
<stratact>
Hey folks, I have a philosophical question, why are allocated slices in the std library API hinted as Owned Slices?
sammich has quit [Read error: Connection reset by peer]
sammich has joined #zig
<daurnimator>
'hinted'?
<daurnimator>
stratact: guessing at your question here: but the idea is that you *own* the returned slice, and are hence responsible for freeing it/cleaning up
ur5us has quit [Ping timeout: 245 seconds]
darithorn has joined #zig
<stratact>
daurnimator: so just to understandd this correctly, in Zig you can't pass multiple copies of the allocated slice pointer around to other variables from the original pointer?
<pixelherodev>
That's more of a standard library thing than a Zig thing
<pixelherodev>
The values returned by some zag functions are *owned* by the caller
<pixelherodev>
You can pass the pointer around as much as you want
<pixelherodev>
But you're responsible to deallocate it
<pixelherodev>
And once you do, every pointer to it is invalid
adamkowalski has joined #zig
marmotini_ has quit [Remote host closed the connection]
adamkowalski has quit [Ping timeout: 268 seconds]
<stratact>
I see, so the Zig ownership model is programmer driven from the mind. Rust ownership model is driven by the compiler. That's the difference.
<stratact>
I had a misconception, I thought ownership meant compiler driven only
<pixelherodev>
It actually works! :D
<pixelherodev>
Not just for an infinite loop
<pixelherodev>
Wrote a simple entry point that utilizes inline asm to extract bootloader-provided pointers from registers
<pixelherodev>
Added in a touch of optimization, and the generated code is now 100% identical to the handwritten version :D
<pixelherodev>
(or at least it would be if I didn't deliberately change it to make it fit Zig more readily)
mahmudov has quit [Remote host closed the connection]
ltriant has quit [Read error: Connection reset by peer]
ltriant has joined #zig
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
stratact has quit [Quit: Konversation terminated!]
<daurnimator>
bgiannan: hmm? `x.?` is the same as: `if (x) |tmp| tmp else unreachable`
<bgiannan>
rightm that's what i meant
<Cadey>
andrewrk: daurnimator: i got it working!
<Cadey>
$ cwa -main-func _start cat2.wasm
<Cadey>
All your base are belong to us.
<mq32>
cwa is a webassembly runner for the terminal?
<Cadey>
for my olin environment, yes
<Cadey>
but either way, it's more proof that the bring-your-own OS concept works
<mq32>
olin?
<Cadey>
https://github.com/Xe/olin it's kinda my playground for webassembly, it's used as a mediator between the outside world and a webassembly VM for a functions as a service project of mine
<mq32>
hmm
<mq32>
is there a library with C api out there to use web assembly in custom projects?
<mq32>
would like to play around some day with that
<mq32>
because i'd like to experiment using Wasm in a Zig based game project as a scripting API
<fengb>
We’ve been talking about building a wasm interpreter in std
<mq32>
:O
<mq32>
so we can host wasm in wasm? :D
<Cadey>
...can we go deeper
<fengb>
Existing WASI VMs aren’t very robust and Zig already has better cross platform support
<mq32>
what is the difference between WASI and Wasm?
<Cadey>
mq32: the difference between the linux syscall ABI and an amd64 CPU
traviss has joined #zig
<Cadey>
how do i pass an arbitrary linker argument?
<bgiannan>
What signature should have a custome `panic` function. https://ziglang.org/documentation/master/#panic talks about a std/special/panic.zig file but it does not seem to exist anymore
<mq32>
Cadey: ah, so WASI is an interface to the outer world designed for wasm
<Cadey>
mq32: yeah
<Cadey>
it's an IO monad basically
<bgiannan>
daurnimator, Cadey, thx
<mq32>
Cadey: i've never understood the term "monad", it's explanations were always waay too theoretically for me
<Cadey>
mq32: monads basically just order compuations so that things happen in a predictable order, this makes a lot more sense in the context of unordered environments like haskell
<daurnimator>
mq32: imagine a functional language where everything is a pure function. input => output
<Cadey>
without an IO monad the haskell compiler might do something odd like make a file write happen before its open
<daurnimator>
mq32: now imagine how useless a language like that would be. how could you ever make a syscall when function input lead to function output and no side effects
<daurnimator>
mq32: so you introduce the monad as an extra input and output. `NEWWORLDSTATE, y = foo(OLDWORLDSTATE, x)`
<fengb>
Eh wasm has imports/exports defined in the spec. WASI just standardizes a bunch
<Cadey>
^
<Cadey>
my stuff would use wasi but my stuff predates wasi lol
<fengb>
It’s vaguely posix so it’s somewhat familiar
<Cadey>
i don't like how wasi programs can't open network sockets personally
<fengb>
But it’s also not very stable and nobody supports it very well
<Cadey>
it's probably great for supporting the past though
<Cadey>
my stuff uses URIs as file paths
<Cadey>
this lets you do crazy things like HTTP with "filesystem" calls
<fengb>
That sounds pretty cool. I’ve wondered how far “everything is a file” could be taken
<Cadey>
that's one of the core parts of my experiments :D
<mq32>
fengb: Look at Plan-9 to see that answer
<Cadey>
making it as easy to access remote files as if they were local
<Cadey>
you might wanna set the download=foo.txt attribute too
<mq32>
Cadey: if that pull request is your code: if (bits.STDIN_FILENO == undefined) <= this has no semantics
<Cadey>
mq32: yeah i fixed it locally
<Cadey>
updated the comment
traviss has quit [Remote host closed the connection]
<Cadey>
i really do like how zig structs don't have private members
<fengb>
`char sa_data[0];` is this a 0 dimension C array?
<mq32>
fengb: It's a weird thing in C :D
<mq32>
it is a common use of reading out-of-bounds
<daurnimator>
its invalid C :)
<fengb>
Oh yeah I do that in Zig too
<daurnimator>
has to be at least [1] to be valid
Ichorio has joined #zig
Ichorio has quit [Ping timeout: 250 seconds]
msiism has joined #zig
Ichorio has joined #zig
<msiism>
What, in rather general terms, is the development status of Zig? Is it good to go for a random “hobbyist” who'd like to go with a “better C”? Are there bindings for any GUI libraries yet?
belgin has joined #zig
<mq32>
> What, in rather general terms, is the development status of Zig?
<mq32>
it's quite usable. i've run into some problems with my projects, but i'm doing "special" stuff (embedded or low level)
<mq32>
> Is it good to go for a random “hobbyist” who'd like to go with a “better C”?
<mq32>
it's definitly worth a look, i really enjoy programming with zig and haven't started a hobby project that is not zig since i made my first project with it :D
<mq32>
> Are there bindings for any GUI libraries yet?
<mq32>
i'm not aware of that, but you can always use C headers that aren't macro-heavy directly from the langauge
<msiism>
Thanks. That sounds quite good. I don't depend on GUI bindings at the moment and I guess they will pop up eventually.
<mq32>
if you want to do game stuff, there's a pretty unfinished SDL2 binding to a more zig-style API by me :D
<mq32>
</advertising>
<msiism>
:) I'm not into gaming, sorry. The project I want to start next is creating a browser-independent bookmark manager.
<pixelherodev>
Huh - that's an interesting idea
<msiism>
For that purpose, it would be interesting to know if Zig has any libraries for processing structured data, like, e.g., JSON or TOML. But I'm not even sure that's really needed.
<mq32>
there's a json parser in the stdlib
<msiism>
Nice.
<companion_cube>
next stop: CBOR
<companion_cube>
the json for system programming :p
<gonz_>
Is ityonemo/dnautics on IRC with another name? He wrote this neat layer for creating BEAM NIFs in zig.
<msiism>
companion_cube: I see. Well, I think I like TOML more than JSON because it's more like INI on steroids. And I certainly like INI.
<companion_cube>
I came to dislike TOML, I find it very unintuitive. Best human readable format, imho, is S-expressions
adamkowalski has quit [Read error: Connection reset by peer]
adamkowalski has joined #zig
<msiism>
Hm... interesting. I'll have a look at that.
<belgin>
((((((s))))e))))x))))p)))s))))))
<companion_cube>
belgin: same goes for json
<msiism>
By the way, the webdesign of ziglang.org is really neat.
<companion_cube>
{{[{'{]]}}}}
<mq32>
companion_cube: i think you confused "human" and "computer" :D
<gonz_>
S-expressions are much more readable than JSON
<gonz_>
(or really any alternative)
<gonz_>
Also trivially parsable
<companion_cube>
mq32: I'm serious, it's simply more readable and editable than json
<companion_cube>
you can have comments, you don't need quotes in random places
Ichorio has quit [Ping timeout: 245 seconds]
<mq32>
i don't know. i hate pretty much dislike everything where i have to keep track of counters to know where i am located
<msiism>
Well, in the end, a bookmark is basically just a URL with a human-readable name attached to it (and 2 or 3 other things). So, you could also just simply throw them all in a single text file with a blank line delimiting each bookmark block. Presenting them in a tree strcuture, for example, is an entirely different thing, so that file wouldn't need to refelct any of that.
<mq32>
both json and sexprs have this counting thing
<mq32>
xml isn't that bad because you can visually scan for end-tags
<companion_cube>
indentation is enough
<companion_cube>
but then, doesn't Zig also have tons of counting?
<scientes>
you can just have a reader that properly formats it
<scientes>
companion_cube, yes it does, that is why you use indentation
<companion_cube>
same goes for S-exprs, really
<companion_cube>
and it's easy since the format is so easy to parse
* scientes
has read lisp and it is nutso
dddddd has joined #zig
<belgin>
if you need something more complicated than key/value pairs in a text file, you should probably go with s-exps
<scientes>
or JSON
<scientes>
JSON isn't that bad
<mq32>
companion_cube: that's why i try to reduce my scope depth, but i fail more often to do so in zig
<scientes>
well, are numbers in JSON limited to 64-bit floats?
<gonz_>
I think you'd have to come up with a better qualification than "has read Lisp" for your non-argument to make sense.
<scientes>
if you look at real lisp code it is pretty nutsy
<scientes>
gonz_, hell, whatever works
<companion_cube>
json is full of quotes and doesn't have comments
<companion_cube>
that's terrible for config
<scientes>
most parsers allow comments
<companion_cube>
but then it's not json ;)
<companion_cube>
(the parsers I know don't allow comments; or for what it's worth, having several objects in one file)
<gonz_>
I've written real Lisp code for years in several Lisps, saying it is "pretty nutsy" holds zero weight.
<companion_cube>
S-expressions for config doesn't mean it's going to be as deep and complex as lisp
<scientes>
why not just write a DSL
<scientes>
they are not hard
<companion_cube>
it's like comparing a bit of json to a big js codebase
<scientes>
the problem is that languages are not very good at writing parsers
<mq32>
why not just plain, simple key-value pairs with "key: value"? ^^
<mq32>
it's even possible to sed such files
<scientes>
mq32, that goes a long ways
<companion_cube>
mq32: what if you need more?
<tgschultz>
If you need something mroe complicated than k/v pairs in a text file you may be suffering from second-system effect.
<belgin>
yeah, that too
<tgschultz>
In a few python things I've written, I've just gone ahead and used python as the config file too.
<companion_cube>
that sounds much worse
<mq32>
Lua is also a quite nice config file language :D
<mq32>
<companion_cube> mq32: what if you need more?
<mq32>
use more files!
<companion_cube>
so parsing sexprs is overkill, but using lua/python is not? wow :D
<belgin>
you can even have tree structure in a list of k/v pairs
<mq32>
companion_cube: lua has actually started as a config file language
<belgin>
root/node1/node2: value
<belgin>
you'd have to type a lot, but whatever
<mq32>
belgin: yep
<belgin>
get a better keyboard :D
<belgin>
(if you don't like typing)
<companion_cube>
belgin: that's what toml does, and I hate it
<companion_cube>
anyway, I'll keep my tiny S-expr parser, thank you very much :p
<mq32>
btw, i'm writign a config file and i now have the best config entry ever:
<mq32>
hide-hidden: true
<belgin>
does andrew want to make an alternative to llvm for zig?
<belgin>
and by alternative i mean, no intermediate language?
<mq32>
belgin: the long term plan is to remove llvm as a dependency
<belgin>
cool
<pixelherodev>
There's already a Zig IR, correct?
<pixelherodev>
How hard would it be to add a `-emit zig-ir` option to the compiler?
<belgin>
there is?
<companion_cube>
(so in OCaml, we've gone from a ton of build systems using ocaml itself as a config language, to one build system with well restricted S-exprs for describing tasks, and it's amazing)
<belgin>
an intermediate-intermediate language?
* pixelherodev
shrugs
<pixelherodev>
Well, there's ` --verbose-ir enable compiler debug output for Zig IR` so probably
<belgin>
companion_cube, cool
<belgin>
it's always nice to configure your build instructions in the same language as the rest of your program
<companion_cube>
(it allows the build system to be portable, instead of people using shell all the time, and to have better parallelism \o/)
<companion_cube>
nah it's the opposite there
<companion_cube>
and tbh I like it
<pixelherodev>
Shell is portable!
<belgin>
ocaml isn't a lisp?
<pixelherodev>
Most people are just bad at writing portable shell code
<companion_cube>
no, it's a ML
<belgin>
oh right
<companion_cube>
pixelherodev: how does shell work on a normal windows?
<tgschultz>
If the program is already in python, and the configuration is complicated enough to need program-like capabilities, then I may as well also do the config in python.
<tgschultz>
That's my reasoning.
<pixelherodev>
Back in the dreadful age in which I ran Windows, usually from C:\bin\sh
<companion_cube>
sure, but then your config becomes a mess
<companion_cube>
last thing I used that did that was, I think, pelican
<tgschultz>
Only if you insist on writing messy code
<companion_cube>
some day my blog broke
belgin has quit [Remote host closed the connection]
<companion_cube>
(the thing is, then your whole API can be part of the config, not a big fan of that)
<tgschultz>
Eh. It's better than second system effect in my opinion.
<companion_cube>
having a well delineated config language that is easy to write or read isn't "second system effect" imho
<fengb>
pixelherodev: Zig IR is meant to be internal details and not relied upon
<tgschultz>
well, my opinion differs.
<companion_cube>
🤷
<pixelherodev>
fengb, ah
<pixelherodev>
Yeah, that figures
<fengb>
I'd guess this wouldn't be stable until after stage 2
<gonz_>
Ah, config/build systems. The tabs/spaces of tools.
<mq32>
let's just enforce indentation in the json config file by "\t \t"
<companion_cube>
if the first entry is `"strict": true` then it's "\t \r\t" instead
<andrewrk>
pixelherodev, there's --emit llvm-ir
<mq32>
companion_cube: the key must be separated from the value with a vertical tab
<fengb>
The only white space allowed should be zero width spaces
<mq32>
(obviously)
<mq32>
Boolean("false")
<mq32>
i love js :D
<companion_cube>
the separator is \0
<companion_cube>
key\0value
<mq32>
and value is delimited by another \0?
<SyrupThinker>
A leading comma is allowed, but not a trailing one
<companion_cube>
mq32: no, by \n\r
<fengb>
“\t\r\n” == false
<mq32>
are we going to create malboge.cfg?
<mq32>
companion_cube: sounds reasonable, that sequence is unlikely
<companion_cube>
✔
<andrewrk>
IMO the most important requirement of a build system is that it works on everybody's system
<companion_cube>
(yeah, that was the point there: avoid invoking unix commands as much as possible)
shakesoda has quit []
shakesoda has joined #zig
traviss has joined #zig
adamkowalski has quit [Quit: Lost terminal]
adamkowalski has joined #zig
dddddd has quit [Ping timeout: 240 seconds]
deesix has quit [Ping timeout: 252 seconds]
deesix has joined #zig
lunamn has joined #zig
<SyrupThinker>
I'm currently doing #3864, "does invalid float literal. Add a `0` before the decimal point" sound good, or should I just use the invalid char error?
dddddd has joined #zig
<adamkowalski>
I prefer the first, if we can make the errors more explicit it might be more helpful
<adamkowalski>
Is there any way to have a tool which acts as a file watcher. Then whenever a file is changed, you figure out what tests would be impacted by those changes, and auto run them?
<Cadey>
andrewrk: i tried making a patch for the "bring your own OS package" feature to customize the entrypoint, it seems that lld _insists_ on the entrypoint being _start for some reason. I added if (@hasDecl(root, "os") and @hasDecl(root.os, "entrypoint")) @export(root.os.entrypoint, wasm_freestanding_start, .Strong); to the is_wasm branch of zig/lib/std/special/start.zig around line 44, it seems that the
<Cadey>
entrypoint constant i exported in my OS module (cwa_main) is being completely ignored by lld _unless_ i build the file as a shared library
wootehfoot has joined #zig
<andrewrk>
Cadey, do you need to change the entry point from _start? I thought the point was just to run code before main() ?
<Cadey>
andrewrk: i guess i can adapt my other code to compensate for the entrypoint being _start
<Cadey>
i think i may have had a very fundamental misinterpretation of how processes work in C space
<Cadey>
andrewrk: in C space, _start doesn't have a return value, does it?
<andrewrk>
correct, it makes a syscall to exit
<Cadey>
well
<Cadey>
i need to add an exit syscall then lol
<andrewrk>
otherwise the CPU will continue executing instructions after _start, which is probably going to trigger SIGILL
<Cadey>
thanks again andrewrk
<andrewrk>
"here, CPU try executing this random memory, you're gonna have a great time!"
<andrewrk>
:)
<Cadey>
andrewrk: where is getStdInHandle defined? I can't find it with grepping
<andrewrk>
Cadey, Vexu is suggesting to add that function
<andrewrk>
as an alternative to emscripten, we could make the freestanding libc support os overrides as well. so you could provide e.g. printf as console.log
<andrewrk>
fengb, I don't understand, is our O_CREAT value incorrect for wasi?
<fengb>
They define 2 of them, O_CREAT is the publicly exported one and __WASI_OFLAGS_CREAT, which matches the value that's currently in O_CREAT
adamkowalski has quit [Quit: Lost terminal]
<fengb>
I don't know why there's a private version since its only usage is setting O_CREAT and a few redundant asserts
<fengb>
Oh that's the value that gets sent to the syscall
ky0ko has joined #zig
darithorn has joined #zig
<fengb>
So maybe I should rename the existing ones to OFLAGS_CREAT and redefine O_CREAT to match these headers? `OFLAGS_CREAT = 1; O_CREAT = OFLAGS_CREAT << 12;`
mahmudov has joined #zig
<andrewrk>
I think __WASI_OFLAGS_CREAT should go into os/wasi.zig and O_CREAT in os/bits/wasi.zig should change to be the libc value
<andrewrk>
os/bits/* tries to match the libc/posix layer
<fengb>
Ah okay
<andrewrk>
os/wasi.zig is wasi-specific stuff
<fengb>
That works, thanks
<fengb>
Sure, there aren't any constants in there currently so I wasn't sure
<andrewrk>
what are you working on? sounds like you're doing something exciting
<fengb>
Getting all the tests to compile in wasi
<fengb>
So we can enable them in CI
<andrewrk>
cool
<andrewrk>
if you want to try to make incremental progress, feel free to disable a bunch of the tests for wasi (ideally with links to github issues), and that way we can have some coverage, and then work toward enabling more tests incrementally
<fengb>
It's surprisingly not too bad. Although I might have spin out the last 10%
<fengb>
Mostly using this as an excuse to learn more about wasi and syscalls :P
<andrewrk>
out of curiosity, do you have a way to use a debugger when running wasi programs?
<andrewrk>
with the ability to step, and inspect values and stuff
<andrewrk>
I bet there's a way to do it with the browser's tools
<fengb>
I've been using good old print debugging :P
<Cadey>
AFAIK there's not really a good debugger for webassembly at all
<Cadey>
i've been using printf debugging and ramdiving with xxd personally
<andrewrk>
I bet it will happen soon though. which actually could be a pretty amazing way to debug logic
<andrewrk>
even if your target isn't wasi, you could cross compile a unit test and use the browser's GUI for debugging
<andrewrk>
that's gonna be a thing soon, I predict
<fengb>
Browser debug isn't that great for wasm
<Cadey>
a friend of mine in the go slack was working on some absolute insanity that involved writing every wasm instruction and its side effects to a postgres database
<fengb>
I suppose it works with poking at raw memory, but it's really low level
<andrewrk>
if people start using wasm more, browser debugging for wasm is going to be top tier
<andrewrk>
it's inevitable
<fengb>
I don't think there's real sourcemaps yet
* Cadey
sunglasses
<Cadey>
yes mister kelly
<Cadey>
that worked better in my head
<andrewrk>
lol
<andrewrk>
but we need the ability to run wasm with file:/// !! I can't believe the people in charge fucked that up so hard
<fengb>
Stacktraces aren't working for wasi yet so hunting down errors isn't really fun
<fengb>
I should actually figure that piece out
<andrewrk>
idk how debug info for wasm/wasi works
<Cadey>
so a big part of the problem there fengb is that there's not a good story in wasm for getting the debuginfo from the binary
<Cadey>
the webassembly environment i play with _does_ have stacktraces, but in the form of webassembly function numbers
<Cadey>
which can drive you a bit mad
<Cadey>
i should really add wasi support to olin >.>
<Snektron>
I realized a while ago that theres a 32-bit version of web assembly
<Cadey>
Snektron: that's the default one atm
<Cadey>
however, it does have native 64 bit pointers
mforney has quit [Quit: quit]
<andrewrk>
wasi barely has enough syscalls to do anything useful
<Cadey>
er
mforney has joined #zig
<Cadey>
64 bit integers/floats
<Cadey>
andrewrk: lol ikr
<Snektron>
What is the point of having a language intended for sandboxing have a 32 and 64 bit version?
<andrewrk>
Snektron, there's no 64 bit wasm yet
<Snektron>
Oh
<Snektron>
inb4 webapps larger than 4 GB
<Cadey>
Snektron: i don't think that it's going to be a practical issue for a while
<fengb>
We don't want to address 4 GB in the browser yet
<Snektron>
Cadey, thats what they said about memory in the 90s
<andrewrk>
it is kinda dumb that we need a compiler_rt function for 64 bit multiplication in wasm though
<Cadey>
Snektron: yes, i'm aware of the irony
<Snektron>
640 kb is enough for everyone
<Cadey>
actually
<Cadey>
with zig and webassembly
<Cadey>
640k of ram (~10 pages) is probably enough for a lot of significant uses
<Snektron>
andrewrk, can
<Snektron>
can't a multiplication be emitted as a series of instructions instead of a call?
<andrewrk>
shipping an extra ~50K of wasm just to implement 64 bit int multiplication, when the host CPU supports it natively
<Snektron>
how is 64 bit multiply 50K
<andrewrk>
Snektron, it can, but the compiler chooses to make some things calls, to avoid bloat
<andrewrk>
idk I was just making that number up. I can measure it
<Snektron>
i would expect such a multiply function to only be like 2 or 3 instructions at best
<Cadey>
webassembly can be a cruel mistress
<fengb>
Isn't it just applying FOIL?
<fengb>
Remembering my long lost algebra 2
<andrewrk>
what's the binary called to get wasm text from wasm binary?
<andrewrk>
wasm equivalent of objdump -d
<Cadey>
wasm2wat
<andrewrk>
thx
<Cadey>
np
<fengb>
Squint a bit and pretend you're working in Lisp :P
<andrewrk>
oh, wasm32 supports 64 bit multiplication
<andrewrk>
OK
<Cadey>
i64.mul i think
<andrewrk>
I guess the only difference is the pointer size
<andrewrk>
Snektron, ^
<companion_cube>
so it's x32, really
<andrewrk>
ah yeah nice analogy
<shakesoda>
"webapps larger than 4gb" is a horrifying thing to read as soon as i get to the computer
<Snektron>
ah yes, i just read it in the isa spec
<Cadey>
lol i just realized
<andrewrk>
ok but let's see how big 128 bit mul is then
<Cadey>
the go limitation of array sizes being `int` is going to bite me if i try to use more than 2 GB of ram in my stuff
<Cadey>
crap
<companion_cube>
makes sense if all your apps are in the browser
<companion_cube>
photoshop as a service, woo
<shakesoda>
do not want
<Snektron>
Cadey, i have an assignment on distributed sorting where i'm supposed to use MPI
<fengb>
I think it'll have to exist if we want to compile LLVM in the browser
<Cadey>
Snektron: MPI?
<Snektron>
MPI can be used to send buffers between compute nodes
<andrewrk>
not bad: https://clbin.com/7ZtPf yeah that looks like FOIL or something simple like that
<Snektron>
except the size is an int of course
<Cadey>
lol
<Snektron>
A real pain
<andrewrk>
a browser is just another OS layer, that evolved instead of being designed. one could imagine the future of browsers being a more intentionally designed second OS layer
<Cadey>
actually, i don't think i will run into that issue
<andrewrk>
better permission model that is more secure for users while allowing applications to do more powerful things
<Cadey>
int is machine word in go
<Snektron>
oh
<Snektron>
I forgot how datatypes worked in go, its been a while
<Cadey>
andrewrk: so basically we need the capability to guide the market to capabilities?
<andrewrk>
IMO today's web should be a *third* OS layer, on top of this other one that I'm describing
<companion_cube>
one could argue Windows also evolved, under the pressures of retrocompat
<andrewrk>
sorry bgiannan. for (list.toSlice()) |item| {}
<shakesoda>
Snektron: i'm slightly surprised to see that i128 output is shorter on arm64 than x86_64
wootehfoot has quit [Read error: Connection reset by peer]
<fengb>
In theory, we could add manual memory paging to wasm32 to break the 4GB barrier! 🙃
wootehfoot has joined #zig
<Cadey>
fengb: hopefully we won't need to
<Cadey>
interesting
<Cadey>
it doesn't look like webassembly has unsigned integer support
<Cadey>
i wonder if you can allocate past 2 GB of ram
<fengb>
"Integers are not inherently signed or unsigned, their interpretation is determined by individual operations."
<Cadey>
ah okay
wootehfoot has quit [Client Quit]
wootehfoot has joined #zig
<Snektron>
shakesoda, arm has a special instruction for stuff like this
<Snektron>
also, the destination of mul can be any register instead of just rax which also cleans up some things
FireFox317 has joined #zig
<FireFox317>
andrewrk: I see you are working on the self-hosted-compiler again. Are you trying to get it to compile stuff again?
dimenus has joined #zig
<andrewrk>
FireFox317, soon. I think I need to invest a little bit in std async io first
<andrewrk>
I have an interesting change coming up soon
FireFox317 has quit [Ping timeout: 265 seconds]
<bgiannan>
andrewrk, right, but i won't be able to search/replace since i use hashmaps iterators as well, so might take a while :)
dimenus has quit [Remote host closed the connection]
muffindrake has quit [Quit: muffindrake]
muffindrake has joined #zig
FireFox317 has joined #zig
ltriant has joined #zig
<frmdstryr>
Does defer'ed code run when main is interrupted (SIGINT)?
<frmdstryr>
I don't get why the streamserver seems to randomly error with address in use
<andrewrk>
frmdstryr, no
<mq32>
frmdstryr: no ,SIGINT is executed "out of band"
<andrewrk>
address in use is a linux thing. it hangs on to addresses for something like 60 seconds by default
<andrewrk>
I think if you clean up properly you can avoid this timeout being required
<andrewrk>
there is also SOREUSEADDR which has its own problems
<frmdstryr>
Can i set up a signal handler to call server.deinit() there?
<andrewrk>
I mean, you *can*. I don't think that's how I would recommend solving it
<andrewrk>
you'll also have this problem if your software crashes
<frmdstryr>
well that i understand :)
<andrewrk>
I think SO_REUSEADDR is probably appropriate while developing
<frmdstryr>
but i'd like to be able to shutdown with sigint
<andrewrk>
if you do this, probably the best way would be to have the sig int handler do something very minimal, such as set an atomic flag that your application will later check
<mq32>
yeah, the atomic flag is probably the cleanest way
<Cadey>
frmdstryr: in all likelyhood, assume your program will crash
<fengb>
Or worse, the slow drip of memory corruption
<Snektron>
maybe it will just rm -rf --no-preserve-root /
<Snektron>
while my friend was working with clang for his bachelors thesis, he made an "evil ub" mode
<Snektron>
it would do stuff like that
<fengb>
In my OS class, I'm pretty sure we had OOB access. It slowly corrupted the FAT12 system we worked on
<fengb>
We convinced the TA to let us refresh the fs after every test case since we passed all the checks from a fresh start :P
<Cadey>
is there a "noreturn" flag for zig functions?
<Cadey>
ah, return type noreturn
lunamn_ has quit [Ping timeout: 252 seconds]
lunamn has joined #zig
msiism has joined #zig
<msiism>
I'm reading Zig's docs and there's something I really can't wrap my head around (which happens quite often, actually): How can/Why do instructions like `break`, `continue`, `return` have a type?
<andrewrk>
Cadey, thanks for the patch, merged :)
<Cadey>
andrewrk: no problem, working on another one for overriding the exit() behavior