Skip to main content.

Tuesday, October 16, 2007

Two weeks. I wasted two weeks in doing the code for FTD (falcon template document). In the beginning, thinking the way PHP files are organized, I thought of doing a cute meta compiler, or upper level compiler, that would have then selected the proper compiler (falcon source or ftd file) and extracted a module from that. The ftd compiler itself would have created small pieces of codes (the things in escapes) and fed them to a properly configured source compiler, which would have integrated the source tree being formed with the code parsed in the way. Of course, this wouldn't have allowed leaving instructions half-way through, (i.e. doing part of a function in an escape, returning to document and re-escaping to continue the function), but that was ok to me.

Of course, that was quite clumsy and inefficient, but that was ok to me too, as the point was to have a fam module ready and use that instead, rather than compiling each time the source.

The real problem arose when I tried to create some block statement which could use unescaped sections, (the thing done with blocks in php). As falcon compiler is context sensible, that meant redesign the compiler so that "end" was considered a statement on its own, being able to close autonomously the currently open context. That worked for the simpler cases, but doing something decent with context sensible code, (i.e. class and object declarations) was nearly madness.

While thinking at something completely different (for the chronicle: I was composing a tune) I zenned it. I had been thinking the wrong way; I didn't have to virtualize the compiler, but to extend its working principles. I thought top-bottom, but here the solution was bottom-top.

In fact, modules created from ftd files are just normal modules where the unescaped blocks are automatically echoed to the VM through the ">" (fast print operator). All that I had to do was to provide the LEXER with an extra "mode", where it would have returned a fast-print related token for unescaped blocks, entering the normal mode after an escape, and then returning to "outer" mode when the escape was closed.

This took two hours coding, less than 200 new lines around, and worked like charm enabling ftd documents to seamlessly merge escaped and unescaped code. Even more than what I was dreaming for in the beginning...

Alas, the experiment with de-contextualized "end" statement wasn't fruitless: in the effort of doing it right I redesigned the lambda functions, separating lambda expressions from nameless functions. That's a change worth to be taken in the main branch, as it simplifies and makes much more natural one of the still controversial grammar issues.

In my defense, I have to admit that I had been ill last two-three weeks, having contracted a strange flu which was quite widespread in Italy and that didn't bear the usual symptoms, but caused muscular pain and loss of concentration.

Comments

No comments yet

Add Comment

This item is closed, it's not possible to add new comments to it or to vote on it