[IronPython] Parser is not accessible anymore in IP2A6
David.Lawler at franke.com
David.Lawler at franke.com
Wed Nov 28 22:45:31 CET 2007
> Yes, Parser being internal definitely causes the error. It is a good
> question whether it is a permanent change because there are pros and
> cons going both ways. Let me open a bug on this since it is
> something we need to make decision on. In the meantime, as a
> temporary workaround (emphasizing the temporary workaround) you can
> use -X:PrivateBinding flag with IronPython to get access to the
> internal/private classes.
>
> The bug I opened is here:
>
> http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=14105
>
> Feel free to vote/comment on it and also keep an eye on it for the
> ultimate resolution.
>
> Thanks for the feedback!
> Martin
>
Well - that SHOULD work - but does not. If you take the following example
program:
import clr
clr.AddReference('IronPython')
clr.AddReference('Microsoft.Scripting')
from System.Text import Encoding
import IronPython
import Microsoft.Scripting
path = "PythonParserTest.py"
pe = IronPython.Hosting.PythonEngine.CurrentEngine
enc = Encoding.Default
s = Microsoft.Scripting.Hosting.SourceUnit.CreateFileUnit(pe, path, enc)
c = Microsoft.Scripting.CompilerContext(s)
p = IronPython.Compiler.Parser.CreateParser(c,
IronPython.PythonEngineOptions())
ast = p.ParseFile(True)
print "all done"
save it as PythonParserTest.py and run it you get this:
ipy -X:PrivateBinding -X:ExceptionDetail PythonParserTest.py
Value cannot be null.
Parameter name: expression
at Microsoft.Scripting.Ast.Ast.ConvertHelper(Expression expression,
Type type
)
at
Microsoft.Scripting.Generation.MethodTarget.MakeExpression(ActionBinder bi
nder, StandardRule rule, Expression[] parameters)
at
Microsoft.Scripting.Generation.MethodTarget.MakeExpression(ActionBinder bi
nder, StandardRule rule, Expression[] parameters, Type[] knownTypes)
at
Microsoft.Scripting.Actions.CallBinderHelper`2.MakeMethodBaseRule(MethodBa
se[] targets)
at Microsoft.Scripting.Actions.CallBinderHelper`2.MakeRule()
at IronPython.Runtime.Types.BuiltinFunction.MakeCallRule[T](CallAction
action
, CodeContext context, Object[] args)
at
IronPython.Runtime.Types.BuiltinFunction.Microsoft.Scripting.IDynamicObjec
t.GetRule[T](DynamicAction action, CodeContext context, Object[] args)
at
Microsoft.Scripting.Actions.ActionBinder.UpdateSiteAndExecute[T](CodeConte
xt callerContext, DynamicAction action, Object[] args, Object site, T&
target, R
uleSet`1& rules)
at
Microsoft.Scripting.Actions.FastDynamicSite`4.UpdateBindingAndInvoke(T0 ar
g0, T1 arg1, T2 arg2)
at
Microsoft.Scripting.Actions.DynamicSiteHelpers.UninitializedTargetHelper`7
.FastInvoke3(FastDynamicSite`4 site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Actions.FastDynamicSite`4.Invoke(T0 arg0, T1
arg1, T2
arg2)
at __main__$mod_1.Initialize(CodeContext ) in PythonParserTest.py:line
16
at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean
tryEva
luate)
at Microsoft.Scripting.ScriptModule.Execute()
at IronPython.Hosting.PythonCommandLine.RunFileWorker(String fileName)
at IronPython.Hosting.PythonCommandLine.RunFile(String filename)
if you make your own version of IronPython 2A6 with Parser set to public
rather
than internal, then the above example works. The problem appears to be in
MethodTarget.cs
around line 150 or so:
// Private binding, invoke via reflection
if (mi != null) {
Expression instance = mi.IsStatic ? null :
_instanceBuilder.ToExpression(context, parameters);
call = Ast.Call(
Ast.RuntimeConstant(mi),
typeof(MethodInfo).GetMethod("Invoke", new Type[]
{ typeof(object), typeof(object[]) }),
Ast.ConvertHelper(instance, typeof(object)),
Ast.NewArrayHelper(typeof(object[]), args)
);
} else {
call = Ast.Call(
Ast.RuntimeConstant((ConstructorInfo)Method),
typeof(ConstructorInfo).GetMethod("Invoke", new
Type[] { typeof(object[]) }),
Ast.NewArrayHelper(typeof(object[]), args)
);
}
where it seems that the 'invoke via reflection for private bindings' has
issues in
Ast.ConvertHelper. However, as I tried to understand the problem further
I developed
an enormous brain cramp. I am so happy that I mostly write business
software and not compilers!
This is not of huge importance to me but I would think that you would want
to solve this
for the poor souls out there who are (or will be) trying to produce
editors/IDEs or other
tools for IronPython (think Intellisense and/or code completion).
Regards,
David
More information about the Ironpython-users
mailing list