public ByteCodeGenerator(CompileManager manager, Method method)
        {
            Manager = manager;
            Method = method;

            byteCodeStream = new byte[64];
            length = 0;

            variableList = new Variable[256];
            if (method.Modifiers.HasFlag(Modifier.Static))
            {
                variableCount = 0;
                MaxVariables = 0;
            }
            else
            {
                variableCount = 1;
                MaxVariables = 1;

                variableList[0] = new Variable(0, "this", method.DeclaringType);
            }
            variableListStack = new Stack<Tuple<short, Variable[]>>();

            state = new State();
        }
Example #2
0
        /// <summary>
        /// Reads and compiles the specified grammars.
        /// </summary>
        /// <returns>true, if the compilation was successful; false, otherwise.</returns>
        public override bool Execute()
        {
            var inputs = this.InputFile;

            CompileManager.CompileFile(this.InputFile, this.OutputFile, this.LogError, new GraphQLGenerationOptions {
                Namespace = Namespace, LanguageVersion = LanguageVersion
            });

            return(!this.Log.HasLoggedErrors);
        }
Example #3
0
        public void MakePragmaPath_WhenGivenVariousOutputPaths_ReturnsTheExpectedPragmaPath(string input, string output, string pragmaPath)
        {
            var result = CompileManager.MakePragmaPath(input, output);

            Assert.That(result, Is.EqualTo(pragmaPath));
        }
Example #4
0
        public void CompileString_WhenGivenAValidGrammar_ReturnsCompileResultWithNoErrors(string subject, string fileName)
        {
            var result = CompileManager.CompileString(subject, fileName);

            Assert.That(result.Errors, Is.Empty);
        }
Example #5
0
        public void CompileString_WhenGivenANullOrEmptyString_ReturnsCompileResultWithErrors(string subject, string fileName)
        {
            var result = CompileManager.CompileString(subject, fileName);

            Assert.That(result.Errors.Single().ErrorNumber, Is.EqualTo("PEG0001"));
        }
Example #6
0
 public void CompileFile_WhenGivenANullLogErrorAction_ThrowsArgumentNullException(string outputFile)
 {
     Assert.That(() => CompileManager.CompileFile("OK.peg", outputFile, null), Throws.InstanceOf <ArgumentNullException>());
 }
Example #7
0
 public void CompileFile_WhenGivenANullInputFileName_ThrowsArgumentNullException(string outputFile)
 {
     Assert.That(() => CompileManager.CompileFile(null, outputFile, err => { }), Throws.InstanceOf <ArgumentNullException>());
 }