public SilverPartialFunction(SilverFunction function, List<FunctionArgument> args, SilverScope scope)
     : base(function.Name, new List<FunctionArgument>(), null, null)
 {
     WrappedFunction = function;
     PartialArguments = args;
     WrappedScope = scope;
 }
 public void AddFunction(SilverFunction function)
 {
     SilverFunction funcToRemove = null;
     _functions.ForEach(func =>
     {
         if (func.Name.Equals(function.Name) && func.Arguments.Count == function.Arguments.Count && !(function is SilverNativeFunction))
         {
             funcToRemove = func;
         }
     });
     if (funcToRemove != null)
         _functions.Remove(funcToRemove);
     _functions.Add(function);
 }
Esempio n. 3
0
 public static FunctionConstraint Function(SilverFunction expected)
 {
     return new FunctionConstraint(expected);
 }
Esempio n. 4
0
 public static FunctionConstraint Function(this ConstraintExpression expr, SilverFunction expected)
 {
     return Is.Function(expected);
 }
        internal static dynamic SingletonDefine(Expression rawSingleton, object rawName, object rawArguments,
            object rawBody, object rawScope)
        {
            var scope = (SilverScope) rawScope;

            var name = (string) rawName;

            var args = (List<FunctionArgument>) rawArguments;

            var body = (BlockExpression) rawBody;
            var function = new SilverFunction(name, args, body, scope);

            object singleton = CompilerServices.CompileExpression(rawSingleton, scope);
            if ((singleton is SilverClass)) {
                var @class = (SilverClass) singleton;
                if (_inClassDefine) {
                    if (@class.Name == _className) {
                        function.IsSingleton = true;
                        return function;
                    }
                    SilverClass.AddMethod(@class.InstanceMethods, function);
                    if (@class.RemovedMethods.Contains(name))
                    {
                        @class.RemovedMethods.Remove(name);
                    }
                    if (@class.UndefinedMethods.Contains(name))
                    {
                        @class.UndefinedMethods.Remove(name);
                    }
                }
                else {
                    SilverClass.AddMethod(@class.InstanceMethods, function);
                    if (@class.RemovedMethods.Contains(name))
                    {
                        @class.RemovedMethods.Remove(name);
                    }
                    if (@class.UndefinedMethods.Contains(name))
                    {
                        @class.UndefinedMethods.Remove(name);
                    }
                }
            }
            else if (singleton is SilverInstance) {
                var @object = (SilverInstance) singleton;
                @object.SingletonMethods[name] = function;
                if (@object.RemovedMethods.Contains(name))
                {
                    @object.RemovedMethods.Remove(name);
                }
                if (@object.UndefinedMethods.Contains(name))
                {
                    @object.UndefinedMethods.Remove(name);
                }
            }

            return function;
        }
        internal static dynamic Define(object rawName, object rawArguments, object rawBody, object rawScope)
        {
            var scope = (SilverScope) rawScope;

            var name = (string) rawName;

            var args = (List<FunctionArgument>) rawArguments;

            var body = (BlockExpression) rawBody;
            var function = new SilverFunction(name, args, body, scope);

            scope[name] = function;

            return function;
        }
Esempio n. 7
0
        public static void AddMethod(IDictionary<string, SilverMethodTable> dict, SilverFunction func)
        {
            if (func.Name == "<__doNotExport>") {
                return;
            }
            if (!dict.ContainsKey(func.Name)) {
                dict[func.Name] = new SilverMethodTable(func.Name);
            }

            dict[func.Name].AddFunction(func);
        }
 private bool CheckForNameMatch(SilverFunction function, List<FunctionArgument> args)
 {
     bool match = false;
     for (int i = 0; i < args.Count; i++) {
         if (args[i].Name != null) {
             IEnumerable<FunctionArgument> nameMatch = function.Arguments.Where(arg => arg.Name == args[i].Name);
             if (!nameMatch.Any()) {
                 return false;
             }
             match = true;
         }
     }
     return match;
 }
 private bool CheckForMatch(SilverFunction function, List<FunctionArgument> args)
 {
     if (args.Count == function.Arguments.Count) {
         return true;
     }
     if (args.Count > function.Arguments.Count) {
         if (function.Arguments.Any() && function.Arguments.Last().IsVarArg) {
             return true;
         }
         return false;
     }
     int myCount = args.Count;
     int theirCount = function.Arguments.Count;
     function.Arguments.ForEach(arg => {
         if (arg.HasDefault) {
             theirCount--;
         }
     });
     int vo = 0;
     if (function.Arguments.Any() && function.Arguments.Last().IsVarArg) {
         vo = 1;
     }
     if (myCount == theirCount) {
         return true;
     }
     if (myCount + vo == theirCount) {
         return true;
     }
     return false;
 }
 internal FunctionConstraint(SilverFunction expected)
 {
     Expected = expected;
 }