News for hackers. Stuff that matters.
Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by gravypod on Friday December 30, 2016 @09:29PM (#13289096)
I'm having a hard time understanding what your PhD is about. Could you clarify in layman's terms?
Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by pbiggar on Friday December 30, 2016 @09:56PM (#13289180)
Sure. Basically, a bunch of scripting languages (Ruby, PHP, Python, a few others) share the same properties, that make them hard to compile:

- they're not really specified anywhere

- they use `eval` and similar dynamic constructs

- they allow you to mutate your data in weird ways (in particular, you can change variables dynamically by knowing the name of the variable, aka "variable variables").

I looked at how to solve these problems in PHP by embedding the PHP interpreter into the compiler as well as into the compiled program. Then I looked at how to do alias analysis in PHP - alias analysis is a type of static analysis to figure out which names in the program point to the same value. This had been done before for a subset of PHP but not for the full generality of the language, in particular dealing with variable variables.

Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by sgrove on Saturday December 31, 2016 @12:15AM (#13289605)
There's actually a not-too-terrible talk going over some of the challenges of compiling PHP, and how initial promising gains turn out to be very difficult (as OP said) to maintain as you try to encompass the full language. Some great examples of disappointments and challenges!

https://www.youtube.com/watch?v=kKySEUrP7LA

Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by markonen on Saturday December 31, 2016 @01:52AM (#13289905)
Pretty sure pbiggar knows about the talk since he's the person giving it!
Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by pbiggar on Saturday December 31, 2016 @02:08AM (#13289942)
Totally forgot about it :)
Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by vjeux on Saturday December 31, 2016 @08:43AM (#13290965)
FYI, both PHP and JavaScript do have a specification.

PHP Specification: https://github.com/php/php-langspec/blob/master/spec/00-spec...

JavaScript Specification: http://www.ecma-international.org/publications/files/ECMA-ST...

Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by pbiggar on Sunday January 01, 2017 @06:00PM (#13297909)
JS does - I didnt focus on JS.

PHP has an unofficial spec now but didn't then. Here's what I wrote about it when it came out: https://circleci.com/blog/critiquing-facebooks-new-php-spec/

Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by gravypod on Saturday December 31, 2016 @08:53AM (#13291004)
Yea that's what confused me about the abstract of the thesis.
Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by gravypod on Saturday December 31, 2016 @09:20AM (#13291096)
> - they're not really specified anywhere

This doesn't make sense

> - they allow you to mutate your data in weird ways (in particular, you can change variables dynamically by knowing the name of the variable, aka "variable variables").

There are a few ways to naively do this. The first and easiest I'd say is just to make a jump table of all the variables in scope. Take a hash of the string and access that. The hardest way is to optimize out this access. Check to see where all of the callers are and inline the function to make the string hard-baked in. After that you can simply replace $some_string() with string_contents(); and get 0 overhead.

> - they use `eval` and similar dynamic constructs

This is harder but eval is largely discouraged and mostly unused (I hope). It can still be supported by linking in the compiler at runtime and calling the compiler on the string passed. It's slow but would allow it to work. Alternatively you could also do the inlining optimization trick.

Re:Nectar: A Native JavaScript Compiler Inspired by Crystal ... by pbiggar on Sunday January 01, 2017 @06:06PM (#13297939)
I'm not sure why you wrote this comment. Did you think that someone who did a PhD in this didn't consider this? The difference between writing this comment and actually trying it is why they give people PhDs.

Have a read of my thesis. I researched whether eval is used much (answer, yes). I looked at the challenge of inlining (you have to know what function is called - non-trivial). The naive jump-table thing you describe is basically impossible (or at least, it makes optimizing around it impossible). If you don't know the string value, all bets on all variables are off. You need to keep the value out of registers, you can't reorder operations, you're basically at square one.