public static Dictionary<string, object> FromPythonDict(IronPython.Runtime.Dict pythonDict)
        {
            Dictionary<string, object> dict = new Dictionary<string,object>();

            foreach ( object key in pythonDict.Keys)
            {
                string propName = key as string;
                if (propName == null)
                {
                    throw new System.ArgumentException("Property name is not a string");
                }
                object propVal = pythonDict[key];
                if (propVal is IronPython.Runtime.Dict)
                {
                    dict.Add(propName, FromPythonDict(propVal as IronPython.Runtime.Dict));
                }
                else if (propVal is IronPython.Runtime.List)
                {
                    dict.Add(propName, FromPythonList(propVal as IronPython.Runtime.List));
                }
                else if (propVal is IronMath.BigInteger)
                {
                    IronMath.BigInteger val = propVal as IronMath.BigInteger;
                    dict.Add(propName, val.ToInt64());
                }
                else
                {
                    dict.Add(propName, propVal);
                }
            }

            return dict;
        }
예제 #2
1
파일: array.cs 프로젝트: wdxa/ILNumerics
 /// <summary>
 /// Convert IronPython List into ILBaseArray
 /// </summary>
 /// <param name="list">IronPython List (must be filled with Python ints or floats)</param>
 /// <returns>ILBaseArray</returns>
 public static ILBaseArray array(IronPython.Runtime.List list)
 {
     List<int> size = new List<int>();
     Type type = typeof(double);
     PythonListHelper.GetListDimensionsAndType(ref size, list, ref type);
     if (!PythonListHelper.CheckList(ref size, list, 0, ref type))
     {
         throw new ArgumentException("List is not rectangular or not of constant type!");
     }
     if (type == typeof(Double))
     {
         return new ILArray<Double>(list);
     }
     else if (type == typeof(Int32))
     {
         return new ILArray<Int32>(list);
     }
     else throw new ArgumentException("List type is not int or float");
 }
예제 #3
0
 internal CodeSpan(IronPython.Compiler.Location start, IronPython.Compiler.Location end)
 {
     this.startLine = start.Line;
     this.startColumn = start.Column;
     this.endLine = end.Line;
     this.endColumn = end.Column;
 }
 public static DomainEntityCollection<Relationship> MakeGroup(IronPython.Runtime.List lst)
 {
     DomainEntityCollection<Relationship> retval = new DomainEntityCollection<Relationship>();
     foreach (var c in lst)
     {
         retval.Add(new Relationship(null) { Code = (string)c });
     }
     return retval;
 }
예제 #5
0
        public static void PerformModuleReload(
            IronPython.Runtime.PythonContext context, 
            IronPython.Runtime.PythonDictionary dict)
        {
            context.DomainManager.LoadAssembly(typeof(System.Xml.Linq.XDocument).Assembly);

            dict["FOO"] = "bar";
            System.Console.WriteLine("Module Load");
        }
예제 #6
0
        public static object get_state(IronPython.Runtime.CodeContext context, object value)
        {
            object prev_value = null;

            if (context.LanguageContext.HasModuleState(_stateKey))
            {
                prev_value = context.LanguageContext.GetModuleState(_stateKey);
            }

            context.LanguageContext.SetModuleState(_stateKey, value);

            return prev_value;
        }
예제 #7
0
파일: mgrid.cs 프로젝트: wdxa/ILNumerics
 public IronPython.Runtime.List this[IronPython.Runtime.Slice xslice, IronPython.Runtime.Slice yslice]
 {
     get
     {
         if ((xslice.start == null) || (xslice.stop == null) || (yslice.start == null) || (yslice.stop == null))
         {
             throw new ILArgumentException("mgrid: start and stop of slices must be provided");
         }
         double xStep = 1, yStep = 1, xStart = 0, yStart = 0, xStop = 1, yStop = 1;
         //
         if (xslice.start is int) xStart = (double)(int)(xslice.start);
         if (xslice.start is double) xStart = (double)(xslice.start);
         if (xslice.stop is int) xStop = (double)(int)(xslice.stop);
         if (xslice.stop is double) xStop = (double)(xslice.stop);
         //
         if (yslice.start is int) yStart = (double)(int)(yslice.start);
         if (yslice.start is double) yStart = (double)(yslice.start);
         if (yslice.stop is int) yStop = (double)(int)(yslice.stop);
         if (yslice.stop is double) yStop = (double)(yslice.stop);
         // 
         if (xslice.step == null)
         {
             if (xStop >= xStart) xStep = 1;
             else xStep = -1;
         }
         else
         {
             if (xslice.step is int) xStep = (double)(int)(xslice.step);
             if (xslice.step is double) xStep = (double)(xslice.step);
         }
         if (yslice.step == null)
         {
             if (yStop >= yStart) yStep = 1;
             else yStep = -1;
         }
         else
         {
             if (yslice.step is int) yStep = (double)(int)(yslice.step);
             if (yslice.step is double) yStep = (double)(yslice.step);
         }
         //
         IronPython.Runtime.List list = new IronPython.Runtime.List();
         int nx = (int)Math.Floor((xStop - xStart) / xStep) + 1;
         int ny = (int)Math.Floor((yStop - yStart) / yStep) + 1;
         ILArray<double> x = ILMath.counter(xStart, xStep, nx);
         ILArray<double> y = ILMath.counter(yStart, yStep, ny);
         List<ILArray<double>> meshgrid = ILMath.meshgrid(x, y);
         list.Add(meshgrid[0]); list.Add(meshgrid[1]);
         return list;
     }
 }
예제 #8
0
 internal static ComplexF[] List_to_ComplexArray(IronPython.Runtime.List list_object)
 {
     ComplexF[] _fft = new ComplexF[list_object.Count];
        for (int i = 0 ; i < _fft.Length ; i++)
        {
        try
        {
            if (list_object[i].GetType() == typeof(System.Numerics.Complex))
            {
                System.Numerics.Complex c = (System.Numerics.Complex)list_object[i];
                _fft[i] = new ComplexF((float)c.Real, (float)c.Imaginary);
            }
            else
            {
                _fft[i] = new ComplexF(float.Parse(list_object[i].ToString()), 0);
            }
        } catch (Exception)
        {
            throw;
        }
        }
        return _fft;
 }
예제 #9
0
        public void Analyze(IronPython.Compiler.Ast.FunctionDefinition function)
        {
            this.argument = 0;
            this.function = function;

            foreach (Expression param in function.Parameters) {
                param.Walk(this);
                argument++;
            }
        }
예제 #10
0
 private void PushScope(IronPython.Compiler.Ast.ClassDefinition cls)
 {
     PushScope(new ClassScope(module, current, cls));
 }
예제 #11
0
 public Compiler(IList<string> sourcesFiles, string OutputAssembly, IronPython.Hosting.CompilerSink compilerSink)
     : base(sourcesFiles, OutputAssembly, compilerSink)
 {
 }
예제 #12
0
 internal keyword(IronPython.Compiler.Ast.Arg arg)
     : this() {
     _arg = arg.Name;
     _value = Convert(arg.Expression);
 }
예제 #13
0
 public FunctionDefinitionInfo(IronPython.Compiler.Ast.FunctionDefinition function)
 {
     this.function = function;
 }
예제 #14
0
 public override bool Walk(IronPython.Compiler.Ast.FunctionDefinition node) {
     UpdateLoops(node);
     return base.Walk(node);
 }
예제 #15
0
 public override bool Walk(IronPython.Compiler.Ast.ClassDefinition node) {
     UpdateLoops(node);
     return false;
 }
 public void PostWalk(IronPython.Compiler.Ast.FunctionDefinition node)
 {
     AssertCurrent(node); current = current.Parent;
 }
예제 #17
0
 /// <summary>
 /// Recurively builds an stack-trace string from the IronPython traceback.
 /// </summary>
 /// <param name="traceback"></param>
 /// <returns></returns>
 private StringBuilder BuildTraceback(IronPython.Runtime.Exceptions.TraceBack traceback)
 {
     StringBuilder traceBuilder = new StringBuilder();
     if (traceback == null)
         return traceBuilder;
     if (traceback.tb_next != null)
     {
         traceBuilder.AppendFormat("{0}\r\n", BuildTraceback(traceback.tb_next));
     }
     if (traceback.tb_frame != null && traceback.tb_frame is IronPython.Runtime.Exceptions.TraceBackFrame)
     {
         IronPython.Runtime.Exceptions.TraceBackFrame frame = (IronPython.Runtime.Exceptions.TraceBackFrame)traceback.tb_frame;
         if (frame.f_code != null)
         {
             traceBuilder.AppendFormat("at {0} Line {1}",
                                       frame.f_code.co_filename,
                                       traceback.tb_lineno);
         }
     }
     return traceBuilder;
 }
        public static LinkedList<object> FromPythonList(IronPython.Runtime.List pythonList)
        {
            LinkedList<object> list = new LinkedList<object>();

            foreach (object obj in pythonList)
            {
                if (obj is IronPython.Runtime.Dict)
                {
                    list.AddLast(FromPythonDict(obj as IronPython.Runtime.Dict));
                }
                else if (obj is IronPython.Runtime.List)
                {
                    list.AddLast(FromPythonList(obj as IronPython.Runtime.List));
                }
                else if (obj is IronMath.BigInteger)
                {
                    IronMath.BigInteger val = obj as IronMath.BigInteger;
                    list.AddLast(val.ToInt64());
                }
                else
                {
                    list.AddLast(obj);
                }
            }

            return list;
        }
 public ClassDefinition(IronPython.Compiler.Ast.ClassDefinition @class)
 {
     this.@class = @class;
 }
 /// <summary>
 /// Log Errors/Warnings/Messages when the compiler reports them.
 /// </summary>
 /// <param name="path">Path to the file where the error was found (null/empty if N/A)</param>
 /// <param name="message">Text of the error/warning/message</param>
 /// <param name="startLine">First line of the block containing the error (0 if N/A)</param>
 /// <param name="startColumn">First column of the block containing the error (0 if N/A)</param>
 /// <param name="endLine">Last line of the block containing the error (0 if N/A)</param>
 /// <param name="endColumn">Last column of the block containing the error (0 if N/A)</param>
 /// <param name="errorCode">Code corresponding to the error</param>
 /// <param name="severity">Error/Warning/Message</param>
 public override void AddError(string path, string message, string lineText, IronPython.Hosting.CodeSpan location, int errorCode, IronPython.Hosting.Severity severity)
 {
     if (ProjectDirectory != null && !System.IO.Path.IsPathRooted(path))
         path = System.IO.Path.Combine(ProjectDirectory, path);
     // Based on the type of event (error/warning/message), report the corresponding type of problem to MSBuild
     switch(severity)
     {
         case IronPython.Hosting.Severity.Error:
             {
                 buildSucceeded = false;
                 taskLogger.LogError(String.Empty, "PY" + errorCode.ToString(), String.Empty, path, location.StartLine, location.StartColumn, location.EndLine, location.EndColumn, message);
                 break;
             }
         case IronPython.Hosting.Severity.Warning:
             {
                 taskLogger.LogWarning(String.Empty, "PY" + errorCode.ToString(), String.Empty, path, location.StartLine, location.StartColumn, location.EndLine, location.EndColumn, message);
                 break;
             }
         case IronPython.Hosting.Severity.Message:
             {
                 taskLogger.LogMessage(message);
                 break;
             }
     }
 }
예제 #21
0
            private void WalkLoopBody(IronPython.Compiler.Ast.Statement body, bool isFinally) {

                bool inLoop = _inLoop;
                bool inFinally = _inFinally;

                int loopId = ++_loopId;
                _inFinally = false;
                _inLoop = true;
                _loopIds.Add(loopId, isFinally);

                body.Walk(this);

                _inLoop = inLoop;
                _inFinally = inFinally;
                LoopOrFinallyIds.Remove(loopId);
            }
 // FunctionDefinition
 public bool Walk(IronPython.Compiler.Ast.FunctionDefinition node)
 {
     current = node; return Process(node);
 }
예제 #23
0
 public override void PostWalk(IronPython.Compiler.Ast.EmptyStatement node) {
     UpdateLoops(node);
     base.PostWalk(node);
 }
예제 #24
0
 public override void PostWalk(IronPython.Compiler.Ast.FunctionDefinition node)
 {
     PopScope();
 }
예제 #25
0
 public override bool Walk(IronPython.Compiler.Ast.WithStatement node) {
     UpdateLoops(node);
     return base.Walk(node);
 }
예제 #26
0
        // FunctionDefinition
        public override bool Walk(IronPython.Compiler.Ast.FunctionDefinition node)
        {
            // Name is defined in the enclosing scope
            Define(node.Name, new FunctionDefinition(node));

            // process the default arg values in the outer scope
            foreach (Expression e in node.Defaults) {
                e.Walk(this);
            }
            // process the decorators in the outer scope
            if (node.Decorators != null) {
                node.Decorators.Walk(this);
            }

            PushScope(node);

            argumentAnalyzer.Analyze(node);
            return true;
        }
 public InferredClass GetClass(IronPython.Compiler.Ast.ClassDefinition cls)
 {
     Debug.Assert(scopes.ContainsKey(cls));
     return new InferredClass(scopes[cls] as ClassScope);
 }
예제 #28
0
 private void PushScope(IronPython.Compiler.Ast.FunctionDefinition func)
 {
     PushScope(new FunctionScope(module, current, func));
 }
예제 #29
0
        // ClassDefinition
        public override bool Walk(IronPython.Compiler.Ast.ClassDefinition node)
        {
            Define(node.Name, new ClassDefinition(node));

            // Base references are in the outer scope
            foreach (Expression b in node.Bases) b.Walk(this);

            // And so is the __name__ reference
            Reference(SymbolTable.Name);

            PushScope(node);

            // define the __doc__
            SymbolId doc = SymbolTable.Doc;
            Define(doc, new DirectDefinition(typeof(string)));

            // Walk the body
            node.Body.Walk(this);
            return false;
        }
 public ExperimentalCompiler(IList<string> sourcesFiles, string outputAssembly, IronPython.Hosting.CompilerSink compilerSink)
 {
     this.sourceFiles = (List<string>)sourcesFiles;
     this.outputAssembly = outputAssembly;
     this.errorSink = compilerSink;
 }