Пример #1
0
        public async Task <object> Load(IInterpreter interpreter, FrameContext context, PyModuleSpec spec)
        {
            var foundPath  = (string)spec.LoaderState;
            var inFile     = File.ReadAllText(foundPath);
            var moduleCode = ByteCodeCompiler.Compile(inFile, new Dictionary <string, object>());
            await interpreter.CallInto(context, moduleCode, new object[0]);

            if (context.EscapedDotNetException != null)
            {
                throw context.EscapedDotNetException;
            }

            var moduleFrame = context.callStack.Pop();
            var module      = PyModule.Create(spec.Name);

            for (int local_i = 0; local_i < moduleFrame.LocalNames.Count; ++local_i)
            {
                module.__setattr__(moduleFrame.LocalNames[local_i], moduleFrame.Locals[local_i]);
            }

            return(module);
        }
Пример #2
0
 public Task <object> Call(IInterpreter interpreter, FrameContext context, object[] args)
 {
     return(interpreter.CallInto(context, this, args));
 }