Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Understanding void.h

Name: Anonymous 2016-01-25 19:02

So i've checked FV github to see it was empty.
Apparently FV is too stupid to use git and keeps void.h in gists.
From https://gist.github.com/FrozenVoid/87e6ad6212ac9ce496e0

1.The thing you notice first is everything depends on _VFUNC which actually does nothing but concatenate with ##
Its in varmacro.h and the system is based on http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments bruteforce approach that creates a macro for every number of arguments. Its cute but limited to 63 arguments and requires writing 63 macros each time: he used this approach in early commits in the gist file.
What FV has done is to replace the 63 macros per macro with apply: same 63 macros but they carry a function macro as first argument and switch to next apply(N-1) with remaining arguments. There are several of these apply functions, most of them i couldn't understand, before writing some test code.
apply.h and apply2.h are the largest files in there along with argmacro.h.

2. _Generic abuse. If you preprocess the files which use p() macro the horrible mess of nested _Generics comes to front, hidden in type selection macro: the type selection...is just macro applied to the type list, another _Generic macro that has all the types.

3.tuple.h this one is quite interesting: using macro argument lists kept in parens as compile-time objects. The next trick is converting the "tuple" back into argument list:
Its not in tuple.h but counter-intuitevely in varmacro.h

#define wrap(...) __VA_ARGS__
#define detuple(...) wrap __VA_ARGS__
Basically when a "tuple" like (1,2,3) is passed to detuple it strips the parens off it, because wrap assumes the parens are its arguments and returns them back.
4.There are actually car and cdr in there: in the argmacro.h there is curious "rest" macro that strips off the first N arguments from its arguments and frontrest macro which return back first N arguments.
They apparently work by passing the argument list N times so it either cut N front arguments or preserves the N first arguments. Neat.

5.The key of array.h - the foreach macro: i was first curious how it find out the size of array, the trick he used is in mem.h elems() macro that uses size() a dirty macro hack that either returns sizeof or msize(): a call to check heap object length in bytes if its sizeof() equal to size of pointer. Here it is:
#define size1(arg1) ({u8 lensize=sizeof(arg1);\
once;\
if((lensize!=sizeof(vp)))break;\
if(isarray(arg1)|isbasic(arg1)){;break;};\
lensize=msize((vp)(u8)arg1);endonce;\
;lensize;})
void.h isn't that cryptic as it seemed at first glance.

Name: Anonymous 2016-01-25 20:14

FrozenAnus

Name: Anonymous 2016-01-25 23:40

>>1-2
Thanks for looking after yourself.

Name: Anonymous 2016-01-26 5:46

>>1
Obviously stolen from BoostPP

Name: Anonymous 2016-01-26 6:02

JACKSON 5 GET

Name: Anonymous 2016-01-26 6:06

>>4
What??? BoostPP is ancient shit it doesn't use macro overloading: its a modern technique.

Name: Anonymous 2016-01-26 6:10

>>1
You could ask it on my forum instead of trial and error.

Name: Anonymous 2016-01-27 16:58

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

Name: Anonymous 2016-01-28 7:26

It's beautiful.

Name: Anonymous 2016-01-28 8:18

Isn't msize non-portable?

Name: Anonymous 2016-01-28 9:06

check em

Name: Anonymous 2016-01-28 12:07

How the fuck is this an "lispeval":
#define tapplyfunc0(func) func
#define tapplyfunc1(func,args...) func(args)
#define tapplyfunc(args...) _VFUNC(tapplyfunc,reduce1arg(nargs(args)))(args)

#define tapplyf(t) tapplyfunc(sdt(t))
#define lispeval(tuples...) sm opapply(;,tapplyf,tuples) em

Name: Anonymous 2016-01-28 12:13

>>12
It's not. IMO, void.h is pretty retarded piece of code.

Name: Anonymous 2016-01-28 13:13

Author of Void.h AMA:
the concept of 'executable tuples' is a remote relative of lisp eval - its useful in some cases when macro-constructed macros/tuples/functions need to be encapsulated in blocks(it doesn't care if the arg is function/macro or tuple-expression like (func(),func2(),4) (which returns 4).
lispeval goes likes this:
1.sm em({;start_macro end_macro;}) is a GCC extension called statement expression macro(statement block), the last value-expression of which is returned by lispeval.
https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Statement-Exprs.html

2.opapply is executed inside the #1 expr, it invokes tapplyf and separates invocations by semicolons, creating:
({; tapplyf(arg1);tapplyf(arg2);tapplyf(arg3);...;tapplyf(Lastarg1);})
The last tapplyf is going to be the value-expression returned.

3. tapplyf( tuple apply func):
passes its arguments to tapplyfunc, expanding tuples into arglist if the argument is a tuple(sdt== safe detuple)
tapplyf((apply,query,data...))
becomes tapplyfunc(apply,query,data...)

4.tapplyfunc checks how much arguments it gets:if one, the argument is inserted into expr as is, e.g. it could be a second level tuple like ((anything,a,(4.4),(3,4))) or some direct expression literal(anything is only detupled once: to nest eval you need to explicitly include eval as the tuples first arg ).
If there are more than one arguments, the first argument is treated as function and rest as arguments:
tapplyfunc(apply,query,data...)
becomes apply(query,data...)
which expands to query(dataarg1),query(dataarg2),...

Name: Anonymous 2016-01-28 14:17

Author of Void.h AMA:
Why the hell did you create this kind of sad crap?

Name: Anonymous 2016-01-28 14:56

>>15
because unlike Lisp its useful.

Name: Anonymous 2016-01-28 15:21

>>16
Lisp is far more useful than some crappy C headers.

Name: Anonymous 2016-01-28 15:47

>>17
Lisp has a large CPU/Ram overhead thats inherent due its design.
99% of useful things it does is reducing amount of code written: Lisp macros to generate Real code that will run(at runtime) and Lisp code will do the same thing C code does 99% of time.
void.h macros remove most of the "abstraction cruft" which Lisp also remove at cost of performance.
Since the preprocessor is (besides compile-time) a zero-cost abstraction the generated code doesn't suffer any performance penalty for using it.
Lisp generates crappy Lisp code or converts Lisp to crappy C ocde that is inferior to code made with C macros.
Process:
Lisp->code.lisp-(slow)>lisp.c(Lisp-to-C translated)->GCC(optimize)->code.asm
Void.h(zero-cost C macros)->code.c(real C)->GCC(optimize)->code.asm
Some Lisp compilers don't rely on GCC: they produce even worse code. And interpreters..worse than python/ruby.
Lisp compilers would actually be useful if they were generating C code from macros like void.h without any Lisp concepts in result(i.e. text generator that produces C code from macro-blocks). Since C macros already proven to be as versatile as Lisp, the case of using Lisp is quite weak anyway and considering the syntax())( probably useless.

Name: Anonymous 2016-01-28 22:21

>>18
I have no idea how Lisp works, please ignore.
Okay, thanks for sharing.

Name: Anonymous 2016-01-28 22:56

>>19
Who are you quoting?

Name: Anonymous 2016-01-29 0:16

>>19
He never said that though.

Name: Anonymous 2016-01-29 0:41

>>21
Oh, he certainly did.

Name: Anonymous 2016-01-29 1:46

>>20
being an anus

Name: Anonymous 2016-01-29 2:40

>>23
Who are you quoting? It certainly isn't Milkribs.

Name: Anonymous 2016-01-29 5:41

>>19
Lisp is essentially a simplified XML parser which modifies the XML node tree at runtime(like DOM modification in HTML pages via JavaScript,except the code is encoded in XML), which at end is converted to C code blocks to compile(via GCC) or assembler fragments to combine into object executable file.

Name: Anonymous 2016-01-29 6:11

>>25
The key insight as to why simple C macros are more powerful than Lisp is this:
Lisp operates on the Level of DOM node manipulation - C macros are innerHTML manipulators that bypass Node boundaries and modify the raw text, instead of obeying XML rules. While on the surface C macros seem primitive they operate on a lower level where they have less restrictions and safety checks.
I predict that extending C preprocessor would benefit the software industry much more then inventing another crippled XML processor.

Name: Anonymous 2016-01-29 9:37

>>25
since lisp came first, you mean that xml is a lisp with angle brackets, but without parser, compiler, or interpreter built-in?

Name: Anonymous 2016-01-29 9:50

>>18
chez scheme and stalin produce worse code than hand-written C

Name: Anonymous 2016-01-29 10:02

>>27
XML follows independent evolution from Lithp.
XML(1997 Michael Sperberg-McQueen) <- SGML(late 1970's http://www.sgmlsource.com/history/roots.htm ISO 8879: Standard GML ) <- GML (1969 Charles Goldfarb, Edward Mosher, and Raymond Lorie) <-(1968 IBM SCRIPT https://en.wikipedia.org/wiki/SCRIPT_%28markup%29 ) <-1967 from IBM https://en.wikipedia.org/wiki/CP/CMS
https://en.wikipedia.org/wiki/History_of_CP/CMS#Historical_notes (The only place where Lithp intersects with XML is this:

Role of John McCarthy (of LISP fame) in timesharing: "At about this time [April 1961] John McCarthy… gave a special evening lecture [stressing the future importance of time-sharing that] ended on the speculative note that computation might eventually 'be organized as a public utility, just as the telephone system is a public utility.' This insightful prediction can be seen to anticipate the role of the Internet. Similar sentiments were later expressed forcefully by Alan Kay and others. IBM leadership had a very different view of computation.[15]

Name: Anonymous 2016-01-29 10:10

>>28
They produce only Lisp-to-C code: a restricted subset of C which is then compiled.
C macros allow you to create unlimited, unrestricted C code with the same abstraction level. C macros allow anything:Lisp code allows using a subset-of-C which is overburdened with Lisp overhead and runtime cost.
Stalin Scheme is an exception rather than a rule: it produces better C code(yet more restricted than hand coded C) than most Lisp compilers, but has some restrictions that make it less popular than other Lisps.

Name: Anonymous 2016-01-29 10:52

>>28
Whom are you quoting?

Name: Anonymous 2016-01-29 11:05

>>32
Its an abstract quasi-quotation isomorphism, you wouldn't understand.

Name: Anonymous 2016-01-29 11:21

>>30
How is compile-time C not overhead, while compile-time Lisp supposedly is? You, sir, are confused and ill-informed.

Name: Anonymous 2016-01-29 11:30

>>33
Compile time C produces C code.
compile-time Lisp transform Lisp into a form that resembles C code but is actually something like Lisp Virtual Machine, a runtime that abstracts Lisp into a restricted subset of C.
Then this "Lisp Virtual Code" is transformed into a mess of C code blocks that GCC has to optimize.
The overhead is in the produced code, not the compilation time.

Name: Anonymous 2016-01-29 17:34

>>34
are you high

Name: Anonymous 2016-01-30 3:32

>>34
On one hand, it is sort of amusing seeing how consistent and adamant you are about this.

On the other hand, you're making a complete ass of yourself in proudly showcasing your complete ignorance and need to kill yourself.

Name: Anonymous 2016-01-30 7:13

>>36
Another blubbering Lisptard being an ignorant and deluded clown.
https://raw.githubusercontent.com/holdenk/stalin-hax/master/stalin-IA32.c (Stalin Scheme)

Name: Anonymous 2016-01-30 8:47

>>37
Another blubbering actual retard who knows very little about 1 shitty language dialect, and thinks he's hot shit. You know nothing, Jon Snow. Stop trying to talk about it.

Name: Anonymous 2016-01-30 8:53

Lisp is bloated shit though. I can say that without even reading the thread. If half as much time was spent optimizing the interpreter\compiler as was spent merely telling people to write macros to produce optimized executables, LISP would be fast enough to complete an infinite loop in less than an hour. It's a shame that such great, expressive, powerful languages as the Lisp family suffer from the equivalent of a C compiler maker telling people that if they don't like the shit outputs, to just write their own toolchain but to keep the at-fault component until the bitter end.

Name: Anonymous 2016-01-30 9:04

>>38
1 shitty language dialect
This is Stalin Scheme the fastest Lisp/Scheme language on the planet with most sophisticated flow/IPO optimizations found in the language family. It produces near-C speed code and often outperforms naive C. The file Stalin generates for its compiler >>37 is a bit bloated, but is trivial for GCC to optimize into real tight assembler.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List