HNHacker News
TopNewBestAskShowJobs

ngnk

28 karma · joined January 10, 2020

submissionscomments
ngnk··on J for C Programmers
https://i.imgur.com/sJJWBtq.png
ngnk··on ngn/k, an AGPL K interpreter
ktye says it compiles with msys2/mingw (msys2.org). i haven't tried it as i don't use windows at all.
ngnk··on ngn/k, an AGPL K interpreter
regarding windows - see https://news.ycombinator.com/item?id=22010059
ngnk··on ngn/k, an AGPL K interpreter
ianal. to the best of my knowledge the project is clean from a legal perspective. ofc, you don't have to be doing something wrong to become a target of copyright trolling.
ngnk··on ngn/k, an AGPL K interpreter
1:x uses mmap, so it would return instantly no matter how large a file you give it

0:x uses 1:x and then it splits the content into lines. unfortunately splitting requires copying, so you'd be limited by the amount of ram (let's ignore "swap").

i don't use mmap for writing/amendment yet. i'll be working on it.

the way modern hardware works is like this: every process run by the os has its own view of the (typically 48-bit) address space. a process can request from the os that a part of that address space be "backed" by a certain file. this means that every time the process touches (i.e. tries to read or write) a virgin memory page there (usually page=4k, always aligned), the os will be automatically notified and will make sure to fill it in with actual content from the file, before the process even knows. from that point on, the page will occupy physical ram. if the os is low on memory later, it may decide to free up the page and return it to its previous state.

in effect, data from disk (or any disk-like storage) can be "streamed" while your program uses ordinary array indexing. the word "streaming" though implies reading from start to end in order (which is additionally sped up by prefetch, but that's a different story..); memory mapping is more general - it allows random access.

ngnk··on ngn/k, an AGPL K interpreter
reading is done with mmap. it returns instantly and then loads memory pages from disk only when you use them.
ngnk··on ngn/k, an AGPL K interpreter

    0:"path"                  /read  lines
    "path"0:("line1";"line2") /write lines
    1:"path"                  /read  bytes
    "path"1:"content"         /write bytes
ngnk··on ngn/k, an AGPL K interpreter
i can confirm, geocar's understanding of the code is correct
ngnk··on ngn/k, an AGPL K interpreter
the agpl is not so much about making concise code pleasant for the masses, as it is about making its freedom viral
ngnk··on ngn/k, an AGPL K interpreter
that's a good read, thanks. afaik zeroing %rbp here plays no role other than to assist debuggers. i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing. i jmp to main() because i wrote it and i know it never returns. it exit()-s.
ngnk··on ngn/k, an AGPL K interpreter
i'd encourage people to compile from source. the binary in "downloads" was compiled without the "-march=native" flag, in order to support older cpus, so it's a bit slower. also, i don't intend to update it regularly - i'll probably remove it in a couple of days.
ngnk··on ngn/k, an AGPL K interpreter
i changed it to "telemetry". i'm not really sure what to call it. they are upfront about it in the clickwrap eula but the data is not anonymized (see section 1.5a - in k ".z.u" means username) and you are not allowed to obstruct connectivity. it's not quite spyware either, as it happens with your consent.
ngnk··on ngn/k, an AGPL K interpreter
across architectures: you're right, as of now it's x86_64 only

across operating systems: it works on linux and freebsd as-is (thanks bakul), and with a few changes on windows+libc (thanks ktye) - https://github.com/ktye/i/tree/master/_/ngn though i personally never use windows

ngnk··on ngn/k, an AGPL K interpreter
any ideas for a more compact and efficient way to get argc and argv on both linux and freebsd without bringing in libc?