public void DecompileGetArgument() { Block block = new Block(); block.CompileArgument("foo"); block.CompileGet("foo"); BlockDecompiler decompiler = new BlockDecompiler(block); var result = decompiler.Decompile(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.AreEqual("GetArgument foo", result[0]); }
public override void Visit(BlockExpression expression) { Block newblock = new Block(null, this.block); // TODO Review is the copy of argument and local names is needed foreach (var parname in this.block.ParameterNames) newblock.CompileArgument(parname); foreach (var locname in this.block.LocalNames) newblock.CompileLocal(locname); if (expression.ParameterNames != null) foreach (var parname in expression.ParameterNames) newblock.CompileArgument(parname); if (expression.LocalVariables != null) foreach (var locname in expression.LocalVariables) newblock.CompileLocal(locname); var compiler = new BytecodeCompiler(newblock); compiler.Visit(expression.Body); this.block.CompileGetBlock(newblock); }
public void CompileAndRun() { Machine machine = new Machine(); Block block; block = new Block(); block.CompileArgument("newX"); block.CompileGet("newX"); block.CompileSet("GlobalX"); block.Execute(machine, new object[] { 10 }); Assert.AreEqual(10, machine.GetGlobalObject("GlobalX")); }
public void CompileWithLocals() { Machine machine = new Machine(); IClass cls = machine.CreateClass("TestClass"); cls.DefineInstanceVariable("x"); Block block; block = new Block(); block.CompileArgument("newX"); block.CompileLocal("l"); block.CompileGet("newX"); block.CompileSet("l"); Assert.AreEqual(1, block.NoLocals); Assert.IsNotNull(block.ByteCodes); Assert.IsTrue(block.ByteCodes.Length > 0); }