Esempio n. 1
0
        protected override void _Exec(Frame frame)
        {
            var results = exp_list.GetResults(frame);

            for (int i = 0; i < var_list.Count; i++)
            {
                var    it  = var_list[i];
                object val = results.Count > i ? results[i] : null;
                if (it is TableAccess)
                {
                    // TableAccess
                    var access = it as TableAccess;
                    var table  = access.table.GetOneResult(frame);
                    var idx    = access.index.GetOneResult(frame);
                    if (idx == null)
                    {
                        throw frame.NewRunException(line, "table index can not be null");
                    }

                    ExtUtils.Set(table, idx, val);
                }
                else
                {
                    // Name
                    var ter = it as Terminator;
                    Debug.Assert(ter.token.Match(TokenType.NAME));
                    var name = ter.token.m_string;
                    frame.Write(name, val);
                }
            }
        }
Esempio n. 2
0
        protected override List <object> _GetResults(Frame frame)
        {
            var t   = table.GetOneResult(frame);
            var idx = index.GetOneResult(frame);

            if (idx == null)
            {
                throw frame.NewRunException(index.line, "table index can not be null");
            }
            var ret = ExtUtils.Get(t, idx);

            return(new List <object>()
            {
                ret
            });
        }
Esempio n. 3
0
        protected override void _Exec(Frame frame)
        {
            object table = null, idx = null, val;
            string name = null;

            // 读
            if (var is TableAccess)
            {
                var access = var as TableAccess;
                table = access.table.GetOneResult(frame);
                if (table == null)
                {
                    throw frame.NewRunException(access.table.line, "table can not be null when run TableAccess");
                }
                idx = access.index.GetOneResult(frame);
                if (idx == null)
                {
                    throw frame.NewRunException(access.index.line, "index can not be null when run TableAccess");
                }
                val = ExtUtils.Get(table, idx);
            }
            else
            {
                var ter = var as Terminator;
                Debug.Assert(ter.token.Match(TokenType.NAME));
                name = ter.token.m_string;
                val  = frame.Read(name);
            }

            // 运算
            if (op == TokenType.CONCAT_SELF)
            {
                // .=
                string str = exp.GetString(frame);
                val = Utils.ToString(val) + str;
            }
            else
            {
                double delta = 1;
                if (exp != null)
                {
                    delta = exp.GetValidNumber(frame);
                }
                if (op == TokenType.DEC_ONE || op == TokenType.DEC_SELF)
                {
                    delta *= -1;
                }
                // @om 要不要检查下NaN
                val = Utils.ToNumber(val) + delta;
            }

            // 写
            if (var is TableAccess)
            {
                ExtUtils.Set(table, idx, val);
            }
            else
            {
                frame.Write(name, val);
            }
        }