News
- 16 August 2009 - Stack unwinding for Language::P
I finally found a flexible way to represent scope information in the Language::P intermediate representation.
The newly added
scope_enterandscope_leavepseudo-instructions mark the start/end of a scope boundary; both instructions have a single 'scope' attribute that links to scope information stored in the IR code object. The advantage of this solution over storing scope start/end offsets directly in the scope information is that it works across IR code transformations and when scope entry/exit are on separate basic blocks; the disadvantage is that finding the start/end of a scope requires scanning all the IR representation of a subroutine.For example the following (dummy) Perl code
{ 1; }compiles to
# main L1: scope_enter scope=0 # implicit scope for the file jump to=L2 L2: scope_enter scope=1 # scope delimited by the braces constant_integer value=1 scope_leave scope=1 jump to=L4 L4: scope_leave scope=0 endScope information contains the outer scope (or
-1for a subroutine/main scope), flags to indicate the scope type (subroutine, eval, main) and the bytecode to be run when exiting the scope through an exception.In the DLR runtime, wrapping subroutines/evals with a try/catch block containing the scope exit code for inner scopes should be (almost) all is needed for stack unwinding.
The implementation for the Toy runtime (just pushed to GitHub) is straightforward: when an exception is thrown, search the scope list for the scope containing the current program counter and walk up the scope list, running scope exit bytecode, until an eval scope is found.
- 1 May 2009 - Playing with DLR
Setup
I used Mono 2.4 and MonoDevelop 2.0 (the binary download under Mac OS X, built from sources for Debian Lenny x86-64) and the DLR from Subversion (revision 23071).
For the DLR to build I had to make some changes to the project files:
find . -name '*.csproj' | xargs perl -i -pe 's/\Q;$(SignedSym)\E//' -- find . -name '*.csproj' | xargs perl -i -ne '/<TreatWarningsAsErrors>/ || print' --naturally the same changes can be performed from the project settings dialog inside MonoDevelop, but the above one-liners are way quicker.
The DLR compiles just fine from inside MonoDevelop, just open
Src/Codeplex-DLR.sln, expand "Runtme" and buildMicrosoft.Scripting.ExtensionAttribute,Microsoft.Scripting.CoreandMicrosoft.Scripting. I have not tried to build the rest of the projects (examples, IronPyton and IronRuby).Hello world
using System; using Microsoft.Linq.Expressions; namespace HelloWorld { class MainClass { public static void Main(string[] args) { // get the MethodInfo for the method System.Console.WriteLine(string) var write_line = typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }); // construct the expression tree for System.Console.WriteLine("Hello, world!") var exp = Expression.Lambda( Expression.Call(write_line, Expression.Constant("Hello, world!"))); // compile the expression and call the generated code exp.Compile().DynamicInvoke(); } } }While the program output is nothing impressive, I find the ability to dynamically compile expression trees pretty impressive. Even more impressive is that expression trees can work both for translating ASTs (they have blocks, conditional expressions, loops) and for compiling basic blocks (using goto).
- 5 April 2009 - It's more complicated than you think
Today, after two weeks, I looked at my wxPerl inbox and found a bug report (with patch!) to make Alien::wxWidgets work with wxWidgets 2.8.10; feeling guilty for not answering it in a timely manner, I proceeded to apply the patch.
After testing it on Mac, I had almost hit "Send" for the thanks-applied mail, when my conscience suddenly awoke and told me I should at least test the change under Windows. Foolishly, I decided to upgrade to the latest and greatest Module::Build and MakeMaker (it will only take 5 minutes!).
Bad Idea.
Module::Install failed halfway through Module::Build and Compress::Zlib installation, being unable to replace some files: one hour wasted in fixing the Perl installation.
Another hour wasted in tracking a build bug unrelated to the patch in question.
With some luck I will manage to commit the one-line patch today...