Newbie question about AST and IL generation

Feb 26, 2009 at 12:41 AM
Hi, I just one to know something, is possible to get the IL code from the AST and store it in the disk, to use later like an executable, I know DLR is for dynamic languages, but this can be an interesting option:

Now I get something that I think is the structure of the AST:

//
// AST: ReturnStatement
//

.return (MyLHelpers.Print)(
    .site (Object) Do Add( // DoOperation Add
        .context
        1
        1
    ),
);



but is possible using the ast get the IL and store on disk for their use later as executable (not related to above code):

//Add.il

//Add Two Numbers


.assembly extern mscorlib {}

.assembly Add
{
    .ver 1:0:1:0
}
.module add.exe

.method static void main() cil managed
{
    .maxstack 2
    .entrypoint
    
    ldc.i4.s 50
    ldc.i4 30    
    add
    call void [mscorlib]System.Console::Write (int32)
    ret
}



Thanks in advance for any suggestion or correction.

Feb 26, 2009 at 1:19 AM

> but is possible using the ast get the IL and store on disk for their use later as executable (not related to above code):

Yup, you can save the code to into an assembly that can be loaded later. See ScriptCode.SaveToAssembly. If you then wanted to see the IL, you could disassemble it.

Depending on how your language implementation works, you may need to do some additional work to ensure that the code can be saved. For example, the tree needs to be free of pointers to live objects.

- John