Arc Forumnew | comments | leaders | submitlogin
Jasper: compile to js lisp inspired by arc (github.com)
5 points by ema 3652 days ago | 13 comments


3 points by malisper 3648 days ago | link

I was going through some of the old arc posts and found an arc to javascript compiler that you might want to look into for ideas for jasper.

Post: http://www.arclanguage.org/item?id=14795

GitHub: https://github.com/arclanguage/arcnu/blob/c9642f4be0aad88398...

-----

4 points by rocketnia 3648 days ago | link

I think your second link's missing a hyphen: https://github.com/arclanguage/arc-nu/blob/c9642f4be0aad8839...

I think that's a very old version of Arc2js. There was at least one more version Pauan made after that, from scratch. Nowadays, Pauan's lisp-that-runs-on-JavaScript efforts seem to be focused on Nulan[1], which... seems to use the escodegen library[2] for JS generation.

And here I spent the weekend optimizing my own lisp-to-JS compiler, when I could've used escodegen. :-p Ah well, it'll probably be worth it because I'm very picky about stack overflows and such.

Well, that old version of Arc2js seems to be trapped in an orphaned set of commits that GitHub might garbage-collect at any time. I tried making a local mirror of the whole repo, but those commits don't come with it. Pauan probably wouldn't consider it to be code that's worth rescuing, but now's the time to figure out how to rescue it. :)

[1] https://github.com/Pauan/nulan

[2] https://github.com/Constellation/escodegen

-----

2 points by akkartik 3648 days ago | link

Crap. It's a real problem that branches aren't version controlled.

-----

2 points by akkartik 3648 days ago | link

I'm curious how you found that link, malisper.

-----

3 points by malisper 3648 days ago | link

I was just looking at some of the older posts here and came across the discussion of arc2js[0]. When that link didn't work I used Google and came across another post[1] where he mentioned an updated page and that one had a link that worked. I must have accidentally copied the broken link instead of the one to the actual page.

[0] http://arclanguage.org/item?id=14795

[1] http://arclanguage.org/item?id=15086

-----

2 points by ema 3648 days ago | link

I think escodegen is interesting when one wants to have source maps.

-----

4 points by ema 3650 days ago | link

I've made a web repl, http://ema-fox.github.io/jasper/ now you can try out jasper without leaving your browser.

-----

3 points by malisper 3651 days ago | link

Could you give us a brief explanation?

-----

5 points by ema 3650 days ago | link

I'll try.

Motivation: I want to have a lisp which, runs in the browser, interops easily with existing javaScript libraries, and is reasonably fast. clojureScript sort of is this, but its macros are kind of a kludge (clojureScript macros are written in clojure and have to be in a seperate file from the rest of the code, also hygienic only), interop isn't seamless, and I don't want to start a jvm every time I want to compile some code. A straight arc to javaScript compiler would have to be really smart to produce fast code, and interop wouldn't be seamless either. So I decided to try writing my own language.

Implementation: Since macros can call functions which were defined in the same file, the functions needed to be evaluated right after being compiled. So I couldn't just do a simple "jasper code in, javaScript code out" compiler in haskell. So there is a self hosted[1] compiler/repl.

Current status: It is already sort of usable, but I wouldn't recommend anyone else to use it for anything beyond throw away tinkering, because I still might decide to make big changes to the semantics.

Not sure if that are the things you wanted explained.

[1] Self hosted compilers are a pain in the behind, one has to mentally switch between the language version the compiler is written in and the language version the compiler is compiling and when you break you compiler you can't use it to compile the fixed version.

-----

3 points by rocketnia 3650 days ago | link

"A straight arc to javaScript compiler would have to be really smart to produce fast code, and interop wouldn't be seamless either. So I decided to try writing my own language."

"Current status: It is already sort of usable, but I wouldn't recommend anyone else to use it for anything beyond throw away tinkering, because I still might decide to make big changes to the semantics."

You could be telling the story of my recent language projects too. :-p

---

"Self hosted compilers are a pain in the behind, one has to mentally switch between the language version the compiler is written in and the language version the compiler is compiling and when you break you compiler you can't use it to compile the fixed version."

That's a really good warning to hear, because I was headed toward having a self-hosted compiler myself.

Nevertheless, I think I'm still headed in that direction. Once you or I have a self-hosted compiler, if it can compile to a platform, it can also run on that platform. That's a way to escape from the original platform you built it on: Write a compiler backend, and then just move to that platform for developing in the future. This could be a pretty nice superpower when we have the silos of C#-based Unity, Java-based Android, etc.

-----

4 points by ema 3649 days ago | link

"Once you or I have a self-hosted compiler, if it can compile to a platform, it can also run on that platform."

In theory yes, but it wouldn't be a good idea for jasper because it is a relatively thin layer on top of javaScript. So a backend for a different platform would have to emulate a lot of JS quirks, which would be complicated and produce slow code.

So if you want to make a cross platform language, it should be a thicker layer on the first platform from the beginning.

"Nevertheless, I think I'm still headed in that direction."

Always make backups of your compiler binaries or don't overwrite old compiler binaries so in case of a bug you don't end up with only one, broken, compiler binary.

-----

2 points by akkartik 3650 days ago | link

Thanks for the answer, especially the thoughts on self-hosted compilers. I'd always found myself vaguely unsatisfied with them as an outsider trying to understand them, so it's very useful to hear similar sentiments from someone who actually has experience building them.

BTW, I followed the instructions to run it and was pleasantly surprised by how painless it was.

One question I had: why does the generated js (http://ema-fox.github.io/jasper/compile.jpr.js) have long strings containing javascript code?

-----

2 points by ema 3650 days ago | link

I actually worried that it wasn't painless enough, and that I should have waited for the web repl to be done before submitting.

These long strings contain the compiled macros. They are only there for debugging. They belong in comments instead of strings, but I didn't think of it at that time.

-----