Пример #1
0
        /// <summary>
        /// Constructor used to create a FunctionCode for code that's been serialized to disk.  
        /// 
        /// Code constructed this way cannot be interpreted or debugged using sys.settrace/sys.setprofile.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// </summary>
        internal FunctionCode(TotemContext context, Delegate code, CompilableStmt totemCode, int localCount)
        {
            _normalDelegate = code;
            _lambda = totemCode;
            _argCount = CalculateArgumentCount();

            // need to take this lock to ensure sys.settrace/sys.setprofile is not actively changing
            lock (_CodeCreateAndUpdateDelegateLock)
            {
                SetTarget(AddRecursionCheck(context, code));
            }

            RegisterFunctionCode(context);
        }
Пример #2
0
        /// <summary>
        /// Constructor to create a FunctionCode at runtime.
        /// 
        /// Code constructed this way supports both being interpreted and debugged.  When necessary the code will
        /// be re-compiled or re-interpreted for that specific purpose.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// 
        /// the initial delegate provided here should NOT be the actual code.  It should always be a delegate which updates our Target lazily.
        /// </summary>
        internal FunctionCode(TotemContext context, Delegate initialDelegate, CompilableStmt code, bool? tracing, bool register)
        {
            _lambda = code;
            Target = LightThrowTarget = initialDelegate;
            _localCount = code._scopeVars == null ? 0 : code._scopeVars.Count;
            _argCount = CalculateArgumentCount();
            if (tracing.HasValue)
            {
                if (tracing.Value)
                {
                    _tracingDelegate = initialDelegate;
                }
                else
                {
                    _normalDelegate = initialDelegate;
                }
            }

            if (register)
            {
                RegisterFunctionCode(context);
            }
        }