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;
            }
        }