Building Ast Expression Trees, on Mono

Sep 20, 2010 at 9:27 PM

I have been unable to find the items to build Ast Expression trees under Mono. But it isn't clear to me if I am just not including the correct libraries, if they just haven't been written yet, or if I am not using the correct version of Mono.

For example, I'm attempting to do the following code snippet, in IronPython, under Mono, but I can't find Expression.Assign:

statements.Add(
Expression.Assign(
r,
Expression.Multiply(
r,
Expression.Subtract(
n,
Expression.Constant(1)
)
)
)
);

I'm currently using Mono 2.6.7, and DLR version 0.9. I've included references to "System.Core", but System.Linq.Expressions seems to be very sensitive to the version of Mono.

Anyone here have insight into what is the best way one can generate Ast Expression Trees under Mono?

Thanks for any insight,

-Doug

Coordinator
Sep 20, 2010 at 9:34 PM

I think Mono 2.8 will have the v2 Expression Trees built-in using the same code that’s in the MS .NET Framework. Until then you’ll probably need to use Microsoft.Scripting.Core which has the ETs in the Microsoft.Scripting.Ast namespace (or if there’s a beta version of 2.8 you could use that, or obviously build from source). In IronPython/IronRuby we usually use conditional compilation to support either one by doing:

#if !CLR2

using MSAst = System.Linq.Expressions;

#else

using MSAst = Microsoft.Scripting.Ast;

#endif

And then qualify everything w/ MSAst and define CLR2 when building for pre-.NET 4 platforms.

From: dsblank [mailto:notifications@codeplex.com]
Sent: Monday, September 20, 2010 2:27 PM
To: Dino Viehland
Subject: Building Ast Expression Trees, on Mono [dlr:227912]

From: dsblank

I have been unable to find the items to build Ast Expression trees under Mono. But it isn't clear to me if I am just not including the correct libraries, if they just haven't been written yet, or if I am not using the correct version of Mono.

For example, I'm attempting to do the following code snippet, in IronPython, under Mono, but I can't find Expression.Assign:

statements.Add(
Expression.Assign(
r,
Expression.Multiply(
r,
Expression.Subtract(
n,
Expression.Constant(1)
)
)
)
);

I'm currently using Mono 2.6.7, and DLR version 0.9. I've included references to "System.Core", but System.Linq.Expressions seems to be very sensitive to the version of Mono.

Anyone here have insight into what is the best way one can generate Ast Expression Trees under Mono?

Thanks for any insight,

-Doug

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Sep 21, 2010 at 12:08 AM

Thanks, that is useful info. It looks like I am definitely missing them, yes? Or am I misunderstanding how I get access?

$ mono --version 
Mono JIT compiler version 2.6.7 (Debian 2.6.7-3ubuntu1) 
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
 	TLS:           __thread
 	GC:            Included Boehm (with typed GC and Parallel Mark)
 	SIGSEGV:       altstack 
	Notifications: epoll 
	Architecture:  x86 
	Disabled:      none 
$ mono bin/ipy.exe 
IronPython 2.6 Beta 2 (0.0.0.0) on .NET 2.0.50727.1433 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import clr 
>>> clr.AddReference("Microsoft.Scripting") 
>>> clr.AddReference("Microsoft.Scripting.Core") 
>>> import Microsoft.Scripting 
>>> dir(Microsoft.Scripting.Ast) 
['FinallyFlowControlExpression', 'GeneratorExpression', 'IfStatementBuilder', 'IfStatementTest', 'LambdaBuilder', 'SkipInterpretExpression', 'TryStatementBuilder', 'Utils', 'YieldExpression'] 
>>> dir(Microsoft.Scripting.Ast.Utils) 
['AddDebugInfo', 'Coalesce', 'CoalesceFalse', 'CoalesceTrue', 'ComplexCallHelper', 'Constant', 'Convert', 'DebugMark', 'DebugMarker', 'Default', 'Empty', 'Equals', 'Finalize', 'FinallyFlowControl', 'Generator', 'GeneratorLambda', 'GetHashCode', 'GetType', 'If', 'IfCondition', 'IfThen', 'IfThenElse', 'Infinite', 'Lambda', 'Loop', 'MakeYield', 'MemberwiseClone', 'NewArrayHelper', 'ReferenceEquals', 'SimpleCallHelper', 'SimpleNewHelper', 'SkipInterpret', 'ToString', 'Try', 'Unless', 'VariableDictionary', 'Void', 'WeakConstant', 'While', 'YieldBreak', 'YieldReturn', '__all__', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Coordinator
Sep 21, 2010 at 1:11 AM

It looks like you’re using IronPython 2.6 Beta 2. I’m not sure what the state of things was then but it’s possible that this is in a different namespace in the beta. For 2.6.1 this works for me:

>>> import clr

>>> clr.AddReference('Microsoft.Scripting.Core')

>>> import Microsoft.Scripting

>>> dir(Microsoft.Scripting.Ast)

['BinaryExpression', 'BlockExpression', 'CatchBlock', 'ConditionalExpression', '

ConstantExpression', 'DebugInfoExpression', 'DefaultExpression', 'DynamicExpress

ion', 'ElementInit', 'Expression', 'ExpressionType', 'ExpressionVisitor', 'GotoE

xpression', 'GotoExpressionKind', 'IndexExpression', 'InvocationExpression', 'La

belExpression', 'LabelTarget', 'LambdaExpression', 'ListInitExpression', 'LoopEx

pression', 'MemberAssignment', 'MemberBinding', 'MemberBindingType', 'MemberExpr

ession', 'MemberInitExpression', 'MemberListBinding', 'MemberMemberBinding', 'Me

thodCallExpression', 'NewArrayExpression', 'NewExpression', 'ParameterExpression

', 'RuntimeVariablesExpression', 'SwitchCase', 'SwitchExpression', 'SymbolDocume

ntInfo', 'TryExpression', 'TypeBinaryExpression', 'UnaryExpression']

(this was on MS’s CLR but it should work the same on Mono)

From: dsblank [mailto:notifications@codeplex.com]
Sent: Monday, September 20, 2010 5:09 PM
To: Dino Viehland
Subject: Re: Building Ast Expression Trees, on Mono [dlr:227912]

From: dsblank

Thanks, that is useful info. It looks like I am definitely missing them, yes? Or am I misunderstanding how I get access?

$ mono --version 
Mono JIT compiler version 2.6.7 (Debian 2.6.7-3ubuntu1) 
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
       TLS:           __thread
       GC:            Included Boehm (with typed GC and Parallel Mark)
       SIGSEGV:       altstack 
       Notifications: epoll 
       Architecture:  x86 
       Disabled:      none 
$ mono bin/ipy.exe 
IronPython 2.6 Beta 2 (0.0.0.0) on .NET 2.0.50727.1433 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import clr 
>>> clr.AddReference("Microsoft.Scripting") 
>>> clr.AddReference("Microsoft.Scripting.Core") 
>>> import Microsoft.Scripting 
>>> dir(Microsoft.Scripting.Ast) 
['FinallyFlowControlExpression', 'GeneratorExpression', 'IfStatementBuilder', 'IfStatementTest', 'LambdaBuilder', 'SkipInterpretExpression', 'TryStatementBuilder', 'Utils', 'YieldExpression'] 
>>> dir(Microsoft.Scripting.Ast.Utils) 
['AddDebugInfo', 'Coalesce', 'CoalesceFalse', 'CoalesceTrue', 'ComplexCallHelper', 'Constant', 'Convert', 'DebugMark', 'DebugMarker', 'Default', 'Empty', 'Equals', 'Finalize', 'FinallyFlowControl', 'Generator', 'GeneratorLambda', 'GetHashCode', 'GetType', 'If', 'IfCondition', 'IfThen', 'IfThenElse', 'Infinite', 'Lambda', 'Loop', 'MakeYield', 'MemberwiseClone', 'NewArrayHelper', 'ReferenceEquals', 'SimpleCallHelper', 'SimpleNewHelper', 'SkipInterpret', 'ToString', 'Try', 'Unless', 'VariableDictionary', 'Void', 'WeakConstant', 'While', 'YieldBreak', 'YieldReturn', '__all__', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
 

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Sep 22, 2010 at 2:04 PM

Just following up with some results. I was not able to get the DLR version 0.9 to compile with Mono 2.6.7. However, I was able to build the DLR-1.0 with VS Express 2008, with the Express solution file that now comes with the DLR-1.0 download. These files built on Windows 7 work fine under Mono 2.6.7. I did have to include Microsoft.Dynamic  in one of my DLL compilations on Mono, but everything else seems to be working lovely.

Thanks to all!

-Doug