public PhpCallback(RoutineDelegate functionDelegate, ScriptContext context) { // create a new DRoutineDesc based on the passed delegate routineDesc = new PhpRoutineDesc(PhpMemberAttributes.Static | PhpMemberAttributes.NamespacePrivate, functionDelegate, false); this.context = context; this.state = State.Bound; }
/// <summary> /// Constructor of PHP closure. /// </summary> /// <param name="context">Current <see cref="ScriptContext"/></param> /// <param name="lambda">Delegate to lambda function itself.</param> /// <param name="parameter"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there are no parameters.</param> /// <param name="static"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there is no <c>use</c> of scope variables.</param> public Closure(ScriptContext/*!*/context, RoutineDelegate/*!*/lambda, PhpArray parameter, PhpArray @static) :this(context, true) { Debug.Assert(context != null); Debug.Assert(lambda != null); this.lambda = lambda; this.parameter = parameter; this.@static = @static; }
/// <summary> /// Used by compiler through subclasses (<paramref name="arglessStub"/> is <B>null</B> then). /// Called by a declaring helper at run-time. /// </summary> /// <param name="declaringType">The declaring type. Can be null.</param> /// <param name="memberAttributes">Attributes of the function.</param> /// <param name="arglessStub">The stub to be called. Cannot be null.</param> /// <param name="needsIndex">True to allocate <see cref="Index"/>. Usable for preserved descs, for global functions that can be reused.</param> internal DRoutineDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate arglessStub, bool needsIndex) : base(declaringType, memberAttributes) { Debug.Assert(declaringType != null); this._arglessStub = arglessStub; // allocate an index, only for preserved descs if (needsIndex) // assign an index only if needed (save indexes, since they cause prealocation of larger BitArray) this.Index = System.Threading.Interlocked.Increment(ref LastIndex); }
/// <summary> /// Constructor of PHP closure. /// </summary> /// <param name="context">Current <see cref="ScriptContext"/></param> /// <param name="lambda">Delegate to lambda function itself.</param> /// <param name="parameter"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there are no parameters.</param> /// <param name="static"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there is no <c>use</c> of scope variables.</param> public Closure(ScriptContext /*!*/ context, RoutineDelegate /*!*/ lambda, PhpArray parameter, PhpArray @static) : this(context, true) { Debug.Assert(context != null); Debug.Assert(lambda != null); this.lambda = lambda; this.parameter = parameter; this.@static = @static; }
public void DeclareFunction(RoutineDelegate /*!*/ arglessStub, string /*!*/ fullName, PhpMemberAttributes memberAttributes, MethodInfo argfull) { var desc = new PhpRoutineDesc(memberAttributes, arglessStub, true); if (argfull != null) // only if we have the argfull { new PurePhpFunction(desc, fullName, argfull); // writes desc.Member } functions[fullName] = desc; }
/// <summary> /// Used by compiler through subclasses (<paramref name="arglessStub"/> is <B>null</B> then). /// Called by a declaring helper at run-time. /// </summary> /// <param name="declaringType">The declaring type. Can be null.</param> /// <param name="memberAttributes">Attributes of the function.</param> /// <param name="arglessStub">The stub to be called. Cannot be null.</param> /// <param name="needsIndex">True to allocate <see cref="Index"/>. Usable for preserved descs, for global functions that can be reused.</param> internal DRoutineDesc(DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate arglessStub, bool needsIndex) : base(declaringType, memberAttributes) { Debug.Assert(declaringType != null); this._arglessStub = arglessStub; // allocate an index, only for preserved descs if (needsIndex) // assign an index only if needed (save indexes, since they cause prealocation of larger BitArray) { this.Index = System.Threading.Interlocked.Increment(ref LastIndex); } }
/// <summary> /// Used by both fast and full reflectors. /// </summary> internal PhpLibraryFunctionDesc(PhpLibraryModule/*!*/ declaringModule, RoutineDelegate/*!*/ arglessStub) : base(declaringModule.GlobalType.TypeDesc, PhpMemberAttributes.Public | PhpMemberAttributes.Static, arglessStub, true) { Debug.Assert(declaringModule != null && arglessStub != null); }
/// <summary> /// Creates a descriptor for specified PHP function at run-time if argless stub delegate is available. /// Called by declaring helpers emitted on script or when a callback is created. /// </summary> public PhpRoutineDesc(PhpMemberAttributes memberAttributes, RoutineDelegate/*!*/ arglessStub, bool needsIndex) : base(UnknownModule.RuntimeModule.GlobalType.TypeDesc, memberAttributes, arglessStub, needsIndex) { Debug.Assert(arglessStub != null); }
/// <summary> /// Creates a descriptor for specified PHP method at run-time if argless stub delegate is available. /// Called by declaring helper emitted on PHP types. /// </summary> internal PhpRoutineDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate/*!*/ arglessStub) : base(declaringType, memberAttributes, arglessStub, false) { Debug.Assert(arglessStub != null); }
/// <summary> /// Declare function <paramref name="name"/> into the PHP <paramref name="context"/>. /// </summary> private static void DeclareFunction(ScriptContext/*!*/context, string name, RoutineDelegate func) { context.DeclaredFunctions.Add(name, new PHP.Core.Reflection.PhpRoutineDesc(PHP.Core.Reflection.PhpMemberAttributes.Public | PHP.Core.Reflection.PhpMemberAttributes.Static, func, false)); }
/// <summary> /// Declare function <paramref name="name"/> into the PHP <paramref name="context"/>. /// </summary> private static void DeclareFunction(ScriptContext /*!*/ context, string name, RoutineDelegate func) { context.DeclaredFunctions.Add(name, new PHP.Core.Reflection.PhpRoutineDesc(PHP.Core.Reflection.PhpMemberAttributes.Public | PHP.Core.Reflection.PhpMemberAttributes.Static, func, false)); }
/// <summary> /// Used by both fast and full reflectors. /// </summary> internal PhpLibraryFunctionDesc(PhpLibraryModule /*!*/ declaringModule, RoutineDelegate /*!*/ arglessStub) : base(declaringModule.GlobalType.TypeDesc, PhpMemberAttributes.Public | PhpMemberAttributes.Static, arglessStub, true) { Debug.Assert(declaringModule != null && arglessStub != null); }
/// <summary> /// Creates a descriptor for specified PHP function at run-time if argless stub delegate is available. /// Called by declaring helpers emitted on script or when a callback is created. /// </summary> public PhpRoutineDesc(PhpMemberAttributes memberAttributes, RoutineDelegate /*!*/ arglessStub, bool needsIndex) : base(UnknownModule.RuntimeModule.GlobalType.TypeDesc, memberAttributes, arglessStub, needsIndex) { Debug.Assert(arglessStub != null); }
/// <summary> /// Creates a descriptor for specified PHP method at run-time if argless stub delegate is available. /// Called by declaring helper emitted on PHP types. /// </summary> internal PhpRoutineDesc(DTypeDesc /*!*/ declaringType, PhpMemberAttributes memberAttributes, RoutineDelegate /*!*/ arglessStub) : base(declaringType, memberAttributes, arglessStub, false) { Debug.Assert(arglessStub != null); }