Exemple #1
0
        internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, bool usesGlobalEnv)
        {
            ScriptLoadingContext lcontext = CreateLoadingContext(script, source);

            try
            {
                FunctionDefinitionExpression fnx;

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
                    fnx = new FunctionDefinitionExpression(lcontext, usesGlobalEnv);

                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 function {0}", source.Name));
                        beginIp = fnx.CompileBody(bytecode, source.Name);
                        bytecode.Emit_Nop(string.Format("End function {0}", source.Name));
                    }

                //Debug_DumpByteCode(bytecode, source.SourceID);

                return(beginIp);
            }
            catch (SyntaxErrorException ex)
            {
                ex.DecorateMessage(script);
                ex.Rethrow();
                throw;
            }
        }
Exemple #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;
            }
        }
Exemple #3
0
        internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, bool usesGlobalEnv)
        {
            var lcontext = CreateLoadingContext(script, source);

            try
            {
                FunctionDefinitionExpression fnx;

                fnx = new FunctionDefinitionExpression(lcontext, usesGlobalEnv);

                int beginIp;

                using (bytecode.EnterSource(null))
                {
                    bytecode.Emit_Nop($"Begin function {source.Name}");
                    beginIp = fnx.CompileBody(bytecode, source.Name);
                    bytecode.Emit_Nop($"End function {source.Name}");
                }

                return(beginIp);
            }
            catch (SyntaxErrorException ex)
            {
                ex.DecorateMessage(script);
                ex.Rethrow();
                throw;
            }
        }
Exemple #4
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;
            }
        }
        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;
            }
        }
        internal static int LoadFunction(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.singlefunc(), listener);

                ScriptLoadingContext         lcontext = CreateLoadingContext(script, source);
                FunctionDefinitionExpression fndef;

                using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
                    fndef = new FunctionDefinitionExpression(parser.anonfunctiondef(), lcontext, false, 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 function {0}", source.Name));
                        beginIp = fndef.CompileBody(bytecode, source.Name);
                        bytecode.Emit_Nop(string.Format("End function {0}", source.Name));

                        Debug_DumpByteCode(bytecode, source.SourceID);
                    }

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