/// <summary>
        /// Resolves all the labels and updates the information in the given 
        /// IParseItem tree.
        /// </summary>
        /// <param name="target">The IParseItem tree to traverse.</param>
        /// <exception cref="System.ArgumentNullException">If target is null.</exception>
        public void Resolve(IParseItem target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            tree = new GetInfoTree();
            target.Accept(this);
            tree.Resolve();

            var info = tree.EndFunc();
            GlobalCaptures = info.CapturedLocals;
            GlobalNested = info.HasNested;
        }
示例#2
0
        /// <summary>
        /// Resolves all the labels and updates the information in the given IParseItem tree.
        /// </summary>
        /// <param name="target">The IParseItem tree to traverse.</param>
        /// <exception cref="System.ArgumentNullException">If target is null.</exception>
        public void Resolve(IParseItem target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _tree = new GetInfoTree();
            target.Accept(this);
            _tree.Resolve();

            var info = _tree.EndFunc();

            _globalCaptures = info.CapturedLocals;
            _globalNested   = info.HasNested;
        }
示例#3
0
        /// <summary>
        /// Compiles an IParseItem tree indo an IModule object so that it can
        /// be executed.
        /// </summary>
        /// <param name="name">The name to given the module, can be null to
        /// auto-generate.</param>
        /// <param name="E">The current environment.</param>
        /// <param name="item">The item to compile.</param>
        /// <returns>A compiled version of the object.</returns>
        /// <exception cref="System.ArgumentNullException">If E or item is null.</exception>
        /// <exception cref="ModMaker.Lua.Parser.SyntaxException">If there is
        /// syntax errors in the item tree.</exception>
        public ILuaValue Compile(ILuaEnvironment E, IParseItem item, string name)
        {
            if (E == null)
            {
                throw new ArgumentNullException(nameof(E));
            }
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            // get the name
            name = name ?? "<>_func_" + (_tid++);
            if (_types.Contains(name))
            {
                int i = 0;
                while (_types.Contains(name + i))
                {
                    i++;
                }
                name += i;
            }

            // resolve labels
            GetInfoVisitor lVisitor = new GetInfoVisitor();

            lVisitor.Resolve(item);

            // create the type
            TypeBuilder tb = _mb.DefineType(name, TypeAttributes.Public | TypeAttributes.BeforeFieldInit | TypeAttributes.Sealed,
                                            typeof(LuaValueBase), Type.EmptyTypes);
            ChunkBuilder cb = new ChunkBuilder(tb, lVisitor.GlobalCaptures, lVisitor.GlobalNested);

            // compile the code
            CompilerVisitor cVisitor = new CompilerVisitor(cb);

            item.Accept(cVisitor);
            var ret = cb.CreateChunk(E);

            return(ret);
        }
示例#4
0
        /// <summary>
        /// Compiles an IParseItem tree indo an IModule object so that it can 
        /// be executed.
        /// </summary>
        /// <param name="name">The name to given the module, can be null to 
        /// auto-generate.</param>
        /// <param name="E">The current environment.</param>
        /// <param name="item">The item to compile.</param>
        /// <returns>A compiled version of the object.</returns>
        /// <exception cref="System.ArgumentNullException">If E or item is null.</exception>
        /// <exception cref="ModMaker.Lua.Parser.SyntaxException">If there is
        /// syntax errors in the item tree.</exception>
        public ILuaValue Compile(ILuaEnvironment E, IParseItem item, string name)
        {
            if (E == null)
                throw new ArgumentNullException("E");
            if (item == null)
                throw new ArgumentNullException("item");

            // get the name
            name = name ?? "<>_func_" + (_tid++);
            if (_types.Contains(name))
            {
                int i = 0;
                while (_types.Contains(name + i))
                    i++;
                name += i;
            }

            // resolve labels
            GetInfoVisitor lVisitor = new GetInfoVisitor();
            lVisitor.Resolve(item);

            // create the type
            TypeBuilder tb = _mb.DefineType(name, TypeAttributes.Public | TypeAttributes.BeforeFieldInit | TypeAttributes.Sealed,
                typeof(LuaValueBase), Type.EmptyTypes);
            ChunkBuilder cb = new ChunkBuilder(tb, lVisitor.GlobalCaptures, lVisitor.GlobalNested);

            // compile the code
            CompilerVisitor cVisitor = new CompilerVisitor(cb);
            item.Accept(cVisitor);
            var ret = cb.CreateChunk(E);
            return ret;
        }