en en en pt es en en en en cv en en en en en en en ca es en es ne en en en en en en en en fr en en en en en en en en en en en en en en en en fr fr zh nl en en en en en en en en en en en en en en it en en en en en en en pt en en en en en en en en en
I just finished implementing exceptions in the Higgs interpreter, complete with support for the finally block and optional catch clauses. The fact that Higgs is an interpreter and tracing JIT instead of a method-based compiler definitely made this process somewhat simpler. The interpreter uses a calling convention where all arguments are pushed on the stack and each stack frame has a fixed size, making stack unwinding very easy. The tracing JIT won’t have to do any special treatment of exceptions: it will simply fall back to the interpreter.
Unsurprisingly, one of the trickiest aspects of exception support is the finally block. This was difficult to implement because the semantics of JavaScript (and Java) say that every form of control flow leaving a try or catch block must execute the corresponding finally blocks (and there might be more than one). This means the throw, break, continue and return statements can each trigger the execution of finally blocks. You can hijack a return statement using a finally block and return a different value. Worse yet: exceptions crossing interprocedural boundaries can trigger the execution of finally blocks while unwinding the stack.
Since my interpreter uses an intermediate representation built on basic blocks and sequences of instructions, I had to compile finally blocks in-line at every point where they would be run, which meant handling a multitude of corner cases. I believe this complexity reveals that finally blocks are a fundamentally “unnatural” language feature. I say unnatural because the control flow involved is convoluted and unintuitive to programmers. Preventing a return statement from executing seems like the kind of black magic that simply shouldn’t be possible.
I’m quite happy to have exception support as I believe it will make debugging the Higgs runtime and standard libraries (both written in extended JS) much easier. Now that this is done, I will be moving towards one of the biggest pieces of the puzzle: implementing a garbage collector for Higgs. Since the focus of my research isn’t garbage collection, I will implement a simple and minimalist stop-the-world copying GC. Having previously implemented a similar GC for Tachyon, I anticipate that I should be able to complete this task within approximately two weeks. The task will be sped up by the automatic generation of code to visit heap-allocated objects.
In case anyone reading this blog is interested, I could use some help on various fronts, one of which is the completion of the math library. I’m missing functions such as Math.ceil, Math.log, Math.exp and full floating-point support in Math.pow. I’m also in need of code to parse and format floating-point values as strings. All of this code would be written in JavaScript. Lastly, I’m looking for a simple JavaScript FFT (fourier transform) benchmark.
From → Compilers, Higgs, JavaScript
Is finally really that bad? It is exactly the right semantics for cleanup code. In the case of hijacking “return”, the return statement itself is more of a problem because it is essentially a goto. This works well in languages like Ruby where you don’t need return statements (though you can use them).
It sounds like you have other reasons for disliking finally. I’m curious what they are.
(I feel for you on the complexity of the implementation, though.)
The complexity of the implementation and the unintuitive spaghetti control flow. Seems to me it’s just not all that useful, and I prefer a simpler, more minimalist language.
Leave a Reply Cancel reply
Enter your comment here...
Fill in your details below or click an icon to log in:
Email (required) (Address never made public)
You are commenting using your WordPress.com account. ( Log Out /  Change )
You are commenting using your Twitter account. ( Log Out /  Change )
You are commenting using your Facebook account. ( Log Out /  Change )
Notify me of new comments via email.
Notify me of new posts via email.
Typed vs Untyped Virtual Machines
Minimalism in Programming Language Design
Democracy, Dictatorships and Access to Information
Code that Doesn’t Rot
The Internet Changed My Life
What’s Could You Use Tesla Bot For?
NoiseCraft: a Browser-Based Visual Programming Language for Sound & Music
Art Artificial Intelligence Artificial Life Assembly Biology Compilers Creativity D Language Electronics Future Game Development Genetic Algorithms Grad studies Graphics Higgs JavaScript Microcontrollers Microprocessors Music Programming Programming Languages Psychology Rant Robotics Tachyon Technology Uncategorized work x86 Zeta
Archives Select Month June 2022  (1) May 2022  (1) March 2022  (1) February 2022  (2) January 2022  (2) December 2021  (1) June 2021  (1) February 2021  (2) December 2020  (1) September 2020  (1) January 2020  (1) November 2019  (2) October 2019  (2) June 2019  (1) January 2019  (1) December 2018  (1) May 2018  (2) February 2018  (1) January 2018  (1) December 2017  (1) October 2017  (1) June 2017  (1) April 2017  (1) January 2017  (1) December 2016  (1) November 2016  (2) September 2016  (2) May 2016  (1) March 2016  (1) February 2016  (2) January 2016  (1) November 2015  (4) October 2015  (1) September 2015  (3) August 2015  (2) July 2015  (3) June 2015  (1) May 2015  (3) April 2015  (2) March 2015  (1) February 2015  (1) December 2014  (1) November 2014  (2) October 2014  (2) September 2014  (3) July 2014  (3) May 2014  (1) April 2014  (1) March 2014  (1) February 2014  (1) January 2014  (3) December 2013  (3) October 2013  (2) September 2013  (1) August 2013  (2) July 2013  (3) June 2013  (2) May 2013  (3) March 2013  (2) February 2013  (1) January 2013  (3) December 2012  (4) November 2012  (1) October 2012  (1) September 2012  (3) July 2012  (4) June 2012  (2) May 2012  (2) April 2012  (4) March 2012  (2) February 2012  (3) January 2012  (6) December 2011  (2) November 2011  (3) October 2011  (8) September 2011  (4) August 2011  (3)