Archive for January, 2008

Creating Variable in DLR (DLR Language - Part 2)

Tuesday, January 29th, 2008

DLR Variable Assignment(Src & Binary)

Creating a variable is not an easy task in DLR. There are different types of variables and different issues (like binding, etc.). Let’s consider the easiest way of using variable.

The variable may be created inside CodeBlock. CodeBlock captures a block of code that should correspond to a .NET method body:

variable.JPG

Open Screenshot

They we will create an Ast which writes value 3 to the variable (consider second red rectangle on the image).

The output of code above should be the following AST and result:
//
// AST
//
.codeblock Object Script ()() {
.var Int32 hello (Global,InParameterArray)
{
(.bound hello) = 3;
.return (.bound hello);
}
}
Result:3

Simple DLR language

Thursday, January 17th, 2008

As Script.NET project had evolved, I was more oftenly being asked to employ DLR for its engine.

DLR stands for Dynamic Language Runtime - a Microsoft’s library which provides services for building dynamic (script) languages such as IronPython and IronRuby. It is employing DynamicMethod technology to produce IL code. The benefit of DynamicMethod is that it may be garbagge collected.

After my first glance at DLR library I have been scared a little bit about it’s design. But, now I came to it again with a strong wish to get deeper.

After some unsuccessfull attempts a I have finaly got it to work. The language is simply arithmetic expressions which then being compiled and evaluated. The source codes and binaries may be downloaded: DLR Calculator.

I am planning to write more detailed article describing this solution soon.

For now consider a list of classes in the order in which they had been implemented.

  • 1. MyConsoleHost
  • 2. MyLanguageProvider
  • 3. MyLEngine
  • 4. MyLOptionsParser
  • 5. MyLConsoleOptions
  • 6. MyLEngineOptions
  • 7. MyLLanguageContext
  • 8. MyLEngine.PrintIteractiveCodeResult
  • 9. Classes in Compiler directory

The solution has the following structure:

  • Compiler - a custom classes with parser, lexer, etc. which will generate DLR Ast for compilation
  • Hosting - a set of classes for hosting a new language, interaction with console, options, etc
  • Runtime - a set of classes using during code execution, such as language context

For testing try following expressions: 1+2, 3+3*2, 1+(2+3*(1+1))+1