/// <summary>
        /// Creates a lambda expression from a call signature and a statement body.
        /// Either 'body' or 'ambient' must additionally be specified.
        /// </summary>
        /// <param name="name">Name of the function if applicable</param>
        /// <param name="callSignature">Signature of the lambda</param>
        /// <param name="body">Body of the lambda; may be null, in which case 'ambient' must be non-null.</param>
        /// <param name="captures">Number of captured variables.</param>
        /// <param name="locals">Number of local variables.  This number *includes* the number of lambda's formal parameters.</param>
        /// <param name="fun">May be given in place of a body statement.  In case 'body' is null, this must be non-null.</param>
        /// <param name="location">Location of the definition.</param>
        /// <param name="statistic">Function invocation statistics</param>
        internal FunctionLikeExpression(
            SymbolAtom name,
            [NotNull] CallSignature callSignature,
            Statement body,
            int captures,
            int locals,
            InvokeAmbient fun,
            LineInfo location,
            FunctionStatistic statistic)
            : base(location)
        {
            Contract.Requires(callSignature != null);
            Contract.Requires(body != null || fun != null);
            Contract.Requires(body == null || fun == null);
            Contract.Requires(captures >= 0);
            Contract.Requires(locals >= 0);
            Contract.Requires(locals >= callSignature.Parameters.Count);

            Name          = name;
            CallSignature = callSignature;
            Body          = body;
            m_ambient     = fun;
            Captures      = captures;
            Locals        = locals;
            Statistic     = statistic;
            Params        = callSignature.Parameters.Count;
        }
        /// <summary>
        ///     Factory method that creates instance of the <see cref="ModuleBinding"/>.
        /// </summary>
        private ModuleBinding CreateFun(string name, InvokeAmbient body, CallSignature signature)
        {
            var atomName  = Symbol(name);
            var statistic = new FunctionStatistic(AmbientName, atomName, signature, StringTable);

            return(ModuleBinding.CreateFun(atomName, body, signature, statistic));
        }
Beispiel #3
0
        /// <summary>
        ///     Creates fun binding.
        /// </summary>
        /// <remarks>
        ///     Used by ambients only!
        /// </remarks>
        public static ModuleBinding CreateFun(SymbolAtom name, InvokeAmbient fun, CallSignature callSignature, StringTable stringTable)
        {
            Contract.Requires(name.IsValid);
            Contract.Requires(fun != null);
            Contract.Requires(callSignature != null);

            return(CreateFun(name, fun, callSignature, new FunctionStatistic(SymbolAtom.Invalid, name, callSignature, stringTable)));
        }
Beispiel #4
0
        /// <summary>
        ///     Creates fun binding.
        /// </summary>
        /// <remarks>
        ///     Used by ambients only!
        /// </remarks>
        public static ModuleBinding CreateFun(SymbolAtom name, InvokeAmbient fun, CallSignature callSignature, FunctionStatistic statistic)
        {
            Contract.Requires(name.IsValid);
            Contract.Requires(fun != null);
            Contract.Requires(callSignature != null);

            return(new ModuleBinding(
                       FunctionLikeExpression.CreateAmbient(name, callSignature, fun, statistic),
                       Declaration.DeclarationFlags.Export, default(LineInfo)));
        }
 /// <summary>
 /// Creates ambient function.
 /// </summary>
 public static FunctionLikeExpression CreateAmbient(SymbolAtom name, CallSignature signature, InvokeAmbient fun, [NotNull] FunctionStatistic statistics)
 {
     Contract.Requires(name.IsValid);
     return(new FunctionLikeExpression(name, signature, fun, default(LineInfo), statistics));
 }
 /// <summary>
 /// Creates a callable expression for the ambient function.
 /// </summary>
 /// <param name="name">Name of the function if applicable</param>
 /// <param name="callSignature">Signature of the lambda.</param>
 /// <param name="ambient">Delegate to serve as lambda's body.</param>
 /// <param name="location">Location of delegates definition.</param>
 /// <param name="statistic">Function invocation statistics.</param>
 private FunctionLikeExpression(SymbolAtom name, [NotNull] CallSignature callSignature, InvokeAmbient ambient, LineInfo location, [NotNull] FunctionStatistic statistic)
     : this(name, callSignature : callSignature, body : null, captures : 0, locals : callSignature.Parameters.Count, fun : ambient, location : location, statistic : statistic)
 {
     Contract.Requires(callSignature != null);
     Contract.Requires(ambient != null);
 }
 /// <summary>
 ///     Factory method that creates instance of the <see cref="NamespaceFunctionDefinition" />.
 /// </summary>
 protected NamespaceFunctionDefinition Function(string name, InvokeAmbient body, CallSignature signature)
 {
     return(new NamespaceFunctionDefinition(name, CreateFun(name, body, signature)));
 }