Beispiel #1
0
        internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode)
        {
            var lcontext = CreateLoadingContext(script, source);

            try
            {
                Statement stat = new ChunkStatement(lcontext);

                int beginIp;

                using (bytecode.EnterSource(null))
                {
                    bytecode.Emit_Nop($"Begin chunk {source.Name}");
                    beginIp = bytecode.GetJumpPointForLastInstruction();
                    stat.Compile(bytecode);
                    bytecode.Emit_Nop($"End chunk {source.Name}");
                }

                return(beginIp);
            }
            catch (SyntaxErrorException ex)
            {
                ex.DecorateMessage(script);
                ex.Rethrow();
                throw;
            }
        }
Beispiel #2
0
        internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode)
        {
            ScriptLoadingContext lcontext = CreateLoadingContext(script, source);

            try
            {
                Statement stat;

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
                    stat = new ChunkStatement(lcontext);

                int beginIp = -1;

                //var srcref = new SourceRef(source.SourceID);

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
                    using (bytecode.EnterSource(null))
                    {
                        bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name));
                        beginIp = bytecode.GetJumpPointForLastInstruction();
                        stat.Compile(bytecode);
                        bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name));
                    }

                //Debug_DumpByteCode(bytecode, source.SourceID);

                return(beginIp);
            }
            catch (SyntaxErrorException ex)
            {
                ex.DecorateMessage(script);
                ex.Rethrow();
                throw;
            }
        }
Beispiel #3
0
        internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
        {
            AntlrErrorListener listener = new AntlrErrorListener(source);

            try
            {
                LuaParser parser = CreateParser(script, new AntlrInputStream(source.Code), source.SourceID, p => p.chunk(), listener);

                ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
                ChunkStatement       stat;

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
                    stat = new ChunkStatement(parser.chunk(), lcontext, globalContext);

                int beginIp = -1;

                //var srcref = new SourceRef(source.SourceID);

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
                    using (bytecode.EnterSource(null))
                    {
                        bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name));
                        beginIp = bytecode.GetJumpPointForLastInstruction();
                        stat.Compile(bytecode);
                        bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name));
                    }

                Debug_DumpByteCode(bytecode, source.SourceID);

                return(beginIp);
            }
            catch (ParseCanceledException ex)
            {
                HandleParserError(ex, listener);
                throw;
            }
        }