Пример #1
0
        public static void lua_upvaluejoin(lua_State L, int fidx1, int n1,
                                           int fidx2, int n2)
        {
            LClosure f1    = null;
            LClosure null_ = null;    //FIXME:added
            UpValRef up1   = getupvalref(L, fidx1, n1, ref f1);
            UpValRef up2   = getupvalref(L, fidx2, n2, ref null_);

            up1.set(up2.get());
            luaC_objbarrier(L, f1, up2.get());
        }
Пример #2
0
        public static void lua_upvaluejoin(lua_State L, int fidx1, int n1,
                                           int fidx2, int n2)
        {
            Closure f1 = null;

            Closure[] f1Ref = new Closure[] { f1 };     //FIXME:added
            UpValRef  up1   = getupvalref(L, fidx1, n1, f1Ref);

            f1 = f1Ref[0];       //FIXME:added
            UpValRef up2 = getupvalref(L, fidx2, n2, null);

            up1.set(up2.get());
            luaC_objbarrier(L, f1, up2.get());
        }
Пример #3
0
        public void Visit(UpValRef e)
        {
            // The block where the upval was declared needs to be closed.
            for (BlockBuilder outer = block; outer != null; outer = outer.Parent)
            {
                if (outer.Block == e.Variable.Block)
                {
                    outer.SetNeedsClose();
                    break;
                }
            }

            // Get upval.
            function.InstructionABC(e.SourceSpan, Opcode.GetUpVal, target, function.UpVal(e.Variable), 0);
        }
Пример #4
0
        public static void lua_upvaluejoin(lua_State L, int fidx1, int n1,
                                           int fidx2, int n2)
        {
            LClosure f1    = null;
            LClosure null_ = null;    //FIXME:added
            UpValRef up1   = getupvalref(L, fidx1, n1, ref f1);
            UpValRef up2   = getupvalref(L, fidx2, n2, ref null_);

            luaC_upvdeccount(L, up1.get());
            up1.set(up2.get());
            up1.get().refcount++;
            if (upisopen(up1.get()))
            {
                up1.get().u.open.touched = 1;
            }
            luaC_upvalbarrier(L, up1.get());
        }
Пример #5
0
        // Statement visitors.

        public void Visit(Assign s)
        {
            if (s.Target is GlobalRef)
            {
                // Assign to global.
                GlobalRef  global   = (GlobalRef)s.Target;
                int        constant = function.Constant(global.Name);
                Allocation value    = R(s.Value);
                function.InstructionABx(s.SourceSpan, Opcode.SetGlobal, value, constant);
                value.Release();
            }
            else if (s.Target is Index)
            {
                // Assign to table index.
                Index      index = (Index)s.Target;
                Allocation table = R(index.Table);
                Allocation key   = RK(index.Key);
                Allocation value = RK(s.Value);
                function.InstructionABC(s.SourceSpan, Opcode.SetTable, table, key, value);
                value.Release();
                key.Release();
                table.Release();
            }
            else if (s.Target is LocalRef)
            {
                // Assign to local.
                LocalRef   local  = (LocalRef)s.Target;
                Allocation target = function.Local(local.Variable);
                Move(target, s.Value);
                target.Release();
            }
            else if (s.Target is UpValRef)
            {
                // Assign to upval.
                UpValRef   upval = (UpValRef)s.Target;
                int        index = function.UpVal(upval.Variable);
                Allocation value = R(s.Value);
                function.InstructionABC(s.SourceSpan, Opcode.SetUpVal, value, index, 0);
                value.Release();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Пример #6
0
 public void Visit(UpValRef e)
 {
     o.Write(e.Variable.Name);
 }
Пример #7
0
 public virtual void Visit(UpValRef e)
 {
     result = e;
 }
Пример #8
0
        public void Visit(AssignList s)
        {
            // Evaluate subexpressions for index targets.
            Allocation allocTargets = function.Top();

            Expression[] targets = new Expression[s.Targets.Count];
            for (int target = 0; target < s.Targets.Count; ++target)
            {
                Expression e     = s.Targets[target];
                Index      index = e as Index;
                if (index != null)
                {
                    Allocation table = R(index.Table);
                    Allocation key   = RK(index.Key);

                    targets[target] = new IndexRef(index.SourceSpan, table, key);

                    key.Release();
                    table.Release();
                    allocTargets.Allocate(2);
                }
                else
                {
                    targets[target] = e;
                }
            }

            // Evaluate all values.
            Allocation allocValues = function.Top();

            for (int value = 0; value < s.Values.Count; ++value)
            {
                Allocation allocValue = Push(s.Values[value]);
                allocValue.Release();
                allocValues.Allocate();
            }
            if (s.ValueList != null)
            {
                if (s.Targets.Count <= s.Values.Count)
                {
                    throw new ArgumentException();
                }

                Allocation allocValueList = PushList(s.ValueList, s.Targets.Count - s.Values.Count);
                allocValueList.Release();
                allocValues.Allocate(s.Targets.Count - s.Values.Count);
            }

            // Assign each value.
            for (int target = 0; target < targets.Length; ++target)
            {
                if (targets[target] is GlobalRef)
                {
                    GlobalRef global = (GlobalRef)targets[target];
                    function.InstructionABx(s.SourceSpan, Opcode.SetGlobal,
                                            allocValues + target, function.Constant(global.Name));
                }
                else if (targets[target] is IndexRef)
                {
                    IndexRef index = (IndexRef)targets[target];
                    function.InstructionABC(s.SourceSpan, Opcode.SetTable,
                                            index.Table, index.Key, allocValues + target);
                }
                else if (targets[target] is LocalRef)
                {
                    LocalRef local = (LocalRef)targets[target];
                    function.InstructionABC(s.SourceSpan, Opcode.Move,
                                            function.Local(local.Variable), allocValues + target, 0);
                }
                else if (targets[target] is UpValRef)
                {
                    UpValRef upval = (UpValRef)targets[target];
                    function.InstructionABC(s.SourceSpan, Opcode.SetUpVal,
                                            allocValues + target, function.UpVal(upval.Variable), 0);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            // Release.
            allocValues.Release();
            allocTargets.Release();
        }