Esempio n. 1
0
        public LOLMethod(FunctionRef info, LOLProgram prog)
        {
            this.info = info;
            this.args = new ArgumentRef[info.Arity + (info.IsVariadic ? 1 : 0)];
            this.program = prog;
            this.locals = new Scope(prog.globals);

            LocalRef it = new LocalRef("IT");
            locals.AddSymbol(it);
        }
Esempio n. 2
0
        public void Visit(LocalRef e)
        {
            Allocation local = function.Local(e.Variable);

            if ((int)target != (int)local)
            {
                function.InstructionABC(e.SourceSpan, Opcode.Move, target, local, 0);
            }
            local.Release();
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
0
        private VariableRef DeclareVariable(string name)
        {
            VariableRef ret;

            if (currentMethod == null)
            {
                /*ret = new GlobalRef(name);
                 * program.globals.AddSymbol(ret);*/
                ret = new LocalRef(name);
                main.locals.AddSymbol(ret);
            }
            else
            {
                ret = new LocalRef(name);
                currentMethod.locals.AddSymbol(ret);
            }

            return(ret);
        }
Esempio n. 5
0
        private void HandleException()
        {
            LocalRef exception = null;

            if (Env.TryCatchEcxeption(out exception))
            {
                string stackTrace = null;
                try
                {
                    stackTrace = new Throwable(exception).GetStackTrace();
                }
                finally
                {
                    exception.Dispose();
                }

                Env.ClearContext();
                throw new Exception(stackTrace);
            }
        }
Esempio n. 6
0
        private VariableRef DeclareVariable(string name)
        {
            VariableRef ret;
            if (currentMethod == null)
            {
                /*ret = new GlobalRef(name);
                program.globals.AddSymbol(ret);*/
                ret = new LocalRef(name);
                main.locals.AddSymbol(ret);
            }
            else
            {
                ret = new LocalRef(name);
                currentMethod.locals.AddSymbol(ret);
            }

            return ret;
        }
Esempio n. 7
0
 public void Visit(LocalRef e)
 {
     o.Write(e.Variable.Name);
 }
Esempio n. 8
0
 public void DefineLocal(ILGenerator gen, LocalRef l)
 {
     l.Local = gen.DeclareLocal(l.Type);
     if (program.compileropts.IncludeDebugInformation)
         l.Local.SetLocalSymInfo(l.Name);
 }
Esempio n. 9
0
 public virtual void Visit(LocalRef e)
 {
     result = e;
 }
Esempio n. 10
0
 public Class(LocalRef jObject)
 {
     this.jObject = jObject;
 }
Esempio n. 11
0
 public Throwable(LocalRef jObject)
 {
     this.jObject = jObject;
 }
Esempio n. 12
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();
        }
Esempio n. 13
0
 public StackTraceElement(LocalRef jObject)
 {
     this.jObject = jObject;
 }