5 ms·
If you find it unbelievable that code like this is written by hand, read this short explanation about “a very unusual style of C” [1]. Fastai has a guide how t
by warpech 7y ago
If you find it unbelievable that code like this is written by hand, read this short explanation about “a very unusual style of C” [1].
Fastai has a guide how to write Whitney-style code in Python [2].
Thre is a relevant thread in HN [3].
[1] https://github.com/kevinlawler/kona/wiki/Coding-Guidelines#this-is-a-very-unusual-style-of-c https://github.com/kevinlawler/kona/wiki/Coding-Guidelines#t...
[2] https://docs.fast.ai/dev/style.html https://docs.fast.ai/dev/style.html
[3] https://news.ycombinator.com/item?id=19481505 https://news.ycombinator.com/item?id=19481505
- saagarjha 7y agoThis isn't even unusual "I want to write K in C" style, it's specifically being annoying: https://bitbucket.org/ngn/k/src/master/m.c https://bitbucket.org/ngn/k/src/master/m.c. I mean, for goodness' sake, it's pivoting the stack in x86_64 assembly to implement _start!
- ngnk 7y agoany ideas for a more compact and efficient way to get argc and argv on both linux and freebsd without bringing in libc?
- saagarjha 7y agoPortably? No.
- duskwuff 7y agoGiven that the interpreter makes system calls directly using inline assembly [1], I suspect that any hope of portability went out the window long ago. [1]: https://bitbucket.org/ngn/k/src/b54eb5cfea5eb821fe1de68d2a8ad4b97f88e765/k.h#lines-63 https://bitbucket.org/ngn/k/src/b54eb5cfea5eb821fe1de68d2a8a...
- ngnk 7y agoacross 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 https://github.com/ktye/i/tree/master/_/ngn though i personally never use windows
- kick 7y agoThanks for writing/freeing this! I've had a lot of fun with it since a friend first pointed out that it had been released under a libre license.
- pja 7y agoNope :) But http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html http://dbp-consulting.com/tutorials/debugging/linuxProgramSt... does suggest zeroing the top-most frame (%ebp) and making sure the stack is 16-byte aligned might also be worth doing. (Possibly it’s already 16-byte aligned already because you jmp to main instead of calling it though?)
- ngnk 7y agothat'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.
- saagarjha 7y ago> afaik zeroing %rbp here plays no role other than to assist debuggers. Yep, it marks function frame boundaries. If you don't particularly care, you may want to consider compiling with -fomit-frame-pointer and the compiler will return this register back to the set of general purpose ones for it to use. > i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing. It will if you end up emitting any SSE instructions, because they will cause loads and stores that need to be aligned.
- 3xblah 7y agoI use _getenv in k3 a=arg1 b=arg2 k c.k
- userbinator 7y agoFor those who want to try understanding APL-styled C, I recommend starting off with this: https://code.jsoftware.com/wiki/Essays/Incunabulum https://code.jsoftware.com/wiki/Essays/Incunabulum I think a lot of the reason people have difficulty is that you need to read the macros first; jumping into the middle won't make any sense. The macros are very mnemonic and there's only 5 of them. For example, I found the DO macro to be particularly elegant because it expresses "repeat something n times", and one of the features of array languages which makes them terse and powerful is this implicit repetition.
- mark_l_watson 7y agoThanks, especially for the fastai style link. I am currently finishing a book [1] that uses the Hy language (hylang) which is a Lisp wrapper on Python. I am going to revisit my code examples, informed by Jeremy’s ideas. Hy is really just a simple mapping of Python to Lisp (syntax very much like Clojure) so most of his style ideas carry over. [1] https://leanpub.com/hy-lisp-python https://leanpub.com/hy-lisp-python
- msla 7y agoI wish they'd release the source of the obfuscator they used.