News for hackers. Stuff that matters.
Re:Show HN: A self-hosted js compiler in 1k loc by peterkelly on Friday February 10, 2017 @01:22PM (#13617598)
I think the appropriate term for this is a pretty-printer. It isn't really a compiler, because the target language is the same as the source.

For a JavaScript compiler (or VM) to be genuinely described as self-hosting, it would need to be able to run using itself, without depending on an existing implementation such as V8, ChakraCore etc. The hard part is not outputting code that can be evaluated by JS itself, but implementing the semantics of JS in terms of a lower-level of abstraction, ideally native code.

Re:Show HN: A self-hosted js compiler in 1k loc by munificent on Friday February 10, 2017 @03:04PM (#13618417)
> It isn't really a compiler, because the target language is the same as the source.

I think it could still be deemed a "compiler" even if it output the same language if it was doing some significant transformation or modification of it.

But, yes, in this case I think you're right and a "pretty-printer" is a better description of it.

Re:Show HN: A self-hosted js compiler in 1k loc by EpicEng on Friday February 10, 2017 @08:54PM (#13620485)
Compiler:

a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer

Since they add features, I guess this would qualify as it outputs a "lower level form", but man it's really pushing the definition.

Re:Show HN: A self-hosted js compiler in 1k loc by bbcbasic on Friday February 10, 2017 @08:51PM (#13620473)
I'd say transpiler, or at least preprocessor. It does add a language feature, after all.
Re:Show HN: A self-hosted js compiler in 1k loc by Schampu on Sunday February 12, 2017 @08:24AM (#13628210)
I just added a second feature called "inout", which lets you pass variables by reference
Re:Show HN: A self-hosted js compiler in 1k loc by pvg on Friday February 10, 2017 @04:07PM (#13618918)
'Pretty-printer' is not quite right either. Nobody bootstraps pretty-printers by repeatedly running them through themselves and extending them which I think was kind of the point of the exercise here.
Re:Show HN: A self-hosted js compiler in 1k loc by whitten on Friday February 10, 2017 @05:39PM (#13619545)
What is the best way known to implement the semantics of a language? Generating an abstract syntax tree is nice, but what is the state of the art in abstract semantics ?
Re:Show HN: A self-hosted js compiler in 1k loc by rntz on Friday February 10, 2017 @11:01AM (#13616258)
The immediate question I had was: "compiles JS to what"?

Apparently the answer is: to Javascript. It's what some call a transpiler: it compiles Javascript plus some extra features down to a more "vanilla" Javascript (es5?). I tend to dislike the term transpiler (transpilers are just compilers that target high-level languages), but I guess in this case the term would have helped me understand what was meant!

Re:Show HN: A self-hosted js compiler in 1k loc by ThisIs_MyName on Friday February 10, 2017 @01:58PM (#13617899)
I prefer "source-to-source compiler": https://en.wikipedia.org/wiki/Source-to-source_compiler
Re:Show HN: A self-hosted js compiler in 1k loc by hasperdi on Friday February 10, 2017 @03:43PM (#13618727)
Yeah, it was the same question I had in mind. The README.md does not do a good job of explaining it.
Re:Show HN: A self-hosted js compiler in 1k loc by coolspot on Friday February 10, 2017 @01:54PM (#13617865)
I can make Chrome V8 in one LOC.

find ./chrome-v8-src | xargs sed -i ':a;N;$!ba;s/\n//g'

Boom!

Re:Show HN: A self-hosted js compiler in 1k loc by aaron-lebo on Friday February 10, 2017 @02:05PM (#13617945)
I really like Douglas Crockford's Pratt parser which is similar. It doesn't compile down to JS but it's trivial to go from the AST to JS either manually or using something like escodegen.

Very elegant and easily extensible.

http://javascript.crockford.com/tdop/index.html

Re:Show HN: A self-hosted js compiler in 1k loc by ckluis on Friday February 10, 2017 @12:59PM (#13617406)
would this allow something like - https://ckluis.com/js-template-concept-e6de6912fd35 - to be feasible?