/// <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(PythonContext context, Delegate code, Compiler.Ast.ScopeStatement scope, string documentation, int localCount) { _normalDelegate = code; _lambda = scope; _argCount = CalculateArgumentCount(); // need to take this lock to ensure sys.settrace/sys.setprofile is not actively changing lock (_CodeCreateAndUpdateDelegateLock) { Target = AddRecursionCheck(context, code); } RegisterFunctionCode(context); }
/// <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(PythonContext context, Delegate initialDelegate, Compiler.Ast.ScopeStatement scope, string documentation, bool? tracing, bool register) { _lambda = scope; Target = LightThrowTarget = initialDelegate; _initialDoc = documentation; _localCount = scope.Variables == null ? 0 : scope.Variables.Count; _argCount = CalculateArgumentCount(); if (tracing.HasValue) { if (tracing.Value) { _tracingDelegate = initialDelegate; } else { _normalDelegate = initialDelegate; } } if (register) { RegisterFunctionCode(context); } }
/// <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(PythonContext context, Delegate initialDelegate, Compiler.Ast.ScopeStatement scope, string documentation) { _lambda = scope; Target = initialDelegate; _initialDoc = documentation; _localCount = scope.Variables == null ? 0 : scope.Variables.Count; _argCount = CalculateArgumentCount(); RegisterFunctionCode(context); }