Hacker News new | past | comments | ask | show | jobs | submit login
How Kal Compiles Itself (rzimmerman.me)
87 points by rzimmerman on Aug 18, 2013 | hide | past | favorite | 19 comments



As CoffeeScript also went through this same process, bootstrapping itself away from an original Ruby-based compiler (at this moment: https://github.com/jashkenas/coffee-script/commit/6446e0004c...), Kal is now in some sense "two self-hosted steps" away from a "normal" language. That's pretty neat.

GorillaScript (here: https://github.com/ckknight/gorillascript/tree/master/src), Coco (here: https://github.com/gkz/LiveScript/tree/master/src) et al, are also implemented in themselves. I hope that this trend of compile-to-JS languages tending to self-host continues.


Why isn't anyone doing languages that compile to a trampolined form of JS? It would kill two birds with one stone: you get to write recursive code without wasting memory, and you can easily implement a lightweight thread scheduler. It seems like people are just picking the low hanging fruit, i.e. "JS syntax is ugly, let's implement a desugarer". I haven't seen many people try to change the semantics of JS much. maybe Whalesong or something, but nobody is using that.


One reason is that performance would be miserable. Most current JS runtimes aren't very good at optimizing that kind of code, and it actually uses quite a bit of extra memory.


This is definitely one of the coolest "Show HN"-style projects I've seen in a while. Great work!


A word of warning: the name 'Kal' will be funny to russian-speaking devs. In case you care.


Sure, it would be a poor name for a new soda you plan to market in Russian-speaking countries; but probably not really worth mentioning here. I'm sure you realize, but lots of Russian words/phrases sound funny (or obscene) in English too - this is true of every language and vice versa. Naming things is hard enough already without trying to cover what it might sound like in every major language.


Kal means feces in Russian.

>Naming things is hard enough already without trying to cover what it might sound like in every major language.

IMO, when you give a name to internationally used thing, this should be taken care of. I.e. name shouldn't sound funny obscene in any of the major languages.


I think most Russian-speaking programmers are intelligent enough to understand it's a foreign name, especially since it's written as "kal" and not "кал".

> I.e. name shouldn't sound funny obscene in any of the major languages.

My point is that this is probably more difficult than you realize.

It's also pointless; if you're the maker of a consumer product (like a soda) and you expect to market it in Russian-speaking countries, then of course you need to watch out for such things. Something like this which is only incidentally used by a small portion of technically literate Russian speakers - it's not really worth bothering with.


Yeah, that's kind of a shame. I'm not planning on changing it though. I figure most russian devs will have a sense of humor about it. I guess with a word that short, most languages are bound to have a meaning for it.

I chose it because in Hebrew it means simple/easy/BASIC.


I'm wondering what Kal's license is? I'm especially wondering if source written in the language itself qualifies as open source under the terms of any/some/most/all of the Free and Open Source licenses, or if the source of every version ever used to compile another version must be made available?


All self-hosted GPL compilers have this 'problem'...

The output of the compiler under the GPL can be licensed however you like.


"wait for" and "for parallel" seem useful. Are they inspired by constructs in other languages, or do they have analogs in other languages?


"wait for" turns out to be somewhat analogous to the upcoming "yield" statement in ECMAScript 6 as well as .NET patterns for async code. "for parallel" must exist somewhere (it almost looks like functional programming). I actually added it as an afterthought when I decided "wait for" ought to work inside of loops. It uses the same mechanism as async.js's "map".


Fortress and Scala have similar concepts

  (0 to 10).par.foreach(expensiveOp)


C# has

  range.AsParallel().Select(expensiveOp);
Which is hilariously verbose, and map is called select. But it's nice to have...


So in essense it dosen't, not more than any other language atleast.

It originaly compiles from coffescript.

It's a point of view thing.


It does. Coffeescript is not involved at any point in the current compilation process.

It did not originally however.


While it may be cool that Kal compiles itself, unless there is a source tree for the Kal binaries themselves, there is a indubitably huge issue of trust with distributing binaries.

Relevant: http://cm.bell-labs.com/who/ken/trust.html


The article links to that very page:

> anarbi posted a great [link] about how compilers can contain a memory of things that are no longer in the code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: