public void EvaluateSetVar() { Parser parser = new Parser(new StreamReader("setvar.py")); ICommand command = parser.CompileCommandList(); Machine machine = new Machine(); command.Execute(machine.Environment); Assert.AreEqual(1, machine.Environment.GetValue("a")); }
public void EvaluateImportFrom() { Parser parser = new Parser(new StreamReader("importfrom.py")); ICommand command = parser.CompileCommandList(); Machine machine = new Machine(); command.Execute(machine.Environment); Assert.AreEqual(1, machine.Environment.GetValue("one")); Assert.AreEqual(2, machine.Environment.GetValue("two")); }
private static bool ProcessFiles(string[] args, Machine machine) { bool hasfiles = false; foreach (var arg in args) { if (!arg.EndsWith(".py")) continue; hasfiles = true; Parser parser = new Parser(new StreamReader(arg)); ICommand command = parser.CompileCommandList(); command.Execute(machine.Environment); } return hasfiles; }
public void EvaluateImport() { Parser parser = new Parser(new StreamReader("import.py")); ICommand command = parser.CompileCommandList(); Machine machine = new Machine(); command.Execute(machine.Environment); object mod = machine.Environment.GetValue("setvar"); Assert.IsNotNull(mod); Assert.IsInstanceOfType(mod, typeof(IValues)); IValues modenv = (IValues)mod; Assert.AreEqual(1, modenv.GetValue("a")); }
public object Apply(IContext context, IList<object> arguments, IDictionary<string, object> namedArguments) { int nargs = arguments == null ? 0 : arguments.Count; if (nargs == 0) throw new TypeError("exec expected at least 1 arguments, got 0"); // TODO implement bytes or code object if (!(arguments[0] is string)) throw new TypeError("exec() arg 1 must be a string, bytes or code object"); Parser parser = new Parser((string)arguments[0]); ICommand command = parser.CompileCommandList(); if (command == null) return null; command.Execute(context); return null; }
public static Module LoadModule(string name, IContext context) { Module module = null; if (TypeUtilities.IsNamespace(name)) { var types = TypeUtilities.GetTypesByNamespace(name); module = new Module(context.GlobalContext); foreach (var type in types) module.SetValue(type.Name, type); } else { string filename = ModuleUtilities.ModuleFileName(name); if (filename == null) throw new ImportError(string.Format("No module named {0}", name)); if (modules.ContainsKey(filename) && modules[filename].GlobalContext == context.GlobalContext) return modules[filename]; Parser parser = new Parser(new StreamReader(filename)); ICommand command = parser.CompileCommandList(); module = new Module(context.GlobalContext); string doc = CommandUtilities.GetDocString(command); command.Execute(module); module.SetValue("__doc__", doc); modules[filename] = module; } return module; }
public void CompileEmptyCommandList() { Parser parser = new Parser(string.Empty); ICommand command = parser.CompileCommandList(); Assert.IsNull(command); }
public void CompileCompositeCommandUsingSemicolonAndSpaces() { Parser parser = new Parser("spam = \"bar\"; one = 1"); ICommand command = parser.CompileCommandList(); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(CompositeCommand)); }
public void CompileCompositeCommand() { Parser parser = new Parser("spam = \"bar\"\r\none = 1"); ICommand command = parser.CompileCommandList(); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(CompositeCommand)); }
public void CompileHttpServer() { Parser parser = new Parser(new StreamReader("httpserver.py")); ICommand command = parser.CompileCommandList(); }
public void CompileDefIf() { Parser parser = new Parser(new StreamReader("defif.py")); ICommand command = parser.CompileCommandList(); }
private void ExecuteFile(string filename) { Parser parser = new Parser(new StreamReader(filename)); ICommand command = parser.CompileCommandList(); command.Execute(this.machine.Environment); }
private void Execute(string text) { Parser parser = new Parser(text); ICommand command = parser.CompileCommandList(); command.Execute(this.machine.Environment); }