public NovaPartialFunction(NovaFunction function, List <FunctionArgument> args, NovaScope scope)
     : base(function.Name, new List <FunctionArgument>(), null, null)
 {
     WrappedFunction  = function;
     PartialArguments = args;
     WrappedScope     = scope;
 }
Exemplo n.º 2
0
        public static void AddMethod(IDictionary <string, NovaMethodTable> dict, NovaFunction func)
        {
            if (func.Name == "<__doNotExport>")
            {
                return;
            }
            if (!dict.ContainsKey(func.Name))
            {
                dict[func.Name] = new NovaMethodTable(func.Name);
            }


            dict[func.Name].AddFunction(func);
        }
Exemplo n.º 3
0
        internal static dynamic Define(object rawName, object rawArguments, object rawBody, object rawScope)
        {
            var scope = (NovaScope)rawScope;

            var name = (string)rawName;

            var args = (List <FunctionArgument>)rawArguments;

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

            scope[name] = function;

            return(function);
        }
Exemplo n.º 4
0
        public void AddFunction(NovaFunction function)
        {
            NovaFunction funcToRemove = null;

            _functions.ForEach(func =>
            {
                if (func.Name.Equals(function.Name) && func.Arguments.Count == function.Arguments.Count && !(function is NovaNativeFunction))
                {
                    funcToRemove = func;
                }
            });
            if (funcToRemove != null)
            {
                _functions.Remove(funcToRemove);
            }
            _functions.Add(function);
        }
Exemplo n.º 5
0
        private bool CheckForNameMatch(NovaFunction function, List <FunctionArgument> args)
        {
            var match = false;

            for (var i = 0; i < args.Count; i++)
            {
                if (args[i].Name != null)
                {
                    var nameMatch = function.Arguments.Where(arg => arg.Name == args[i].Name);
                    if (!nameMatch.Any())
                    {
                        return(false);
                    }
                    match = true;
                }
            }
            return(match);
        }
Exemplo n.º 6
0
        private bool CheckForMatch(NovaFunction 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);
            }
            var myCount    = args.Count;
            var theirCount = function.Arguments.Count;

            function.Arguments.ForEach(arg => {
                if (arg.HasDefault)
                {
                    theirCount--;
                }
            });
            var 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);
        }
Exemplo n.º 7
0
        internal static dynamic SingletonDefine(Expression rawSingleton, object rawName, object rawArguments,
                                                object rawBody, object rawScope)
        {
            var scope = (NovaScope)rawScope;

            var name = (string)rawName;

            var args = (List <FunctionArgument>)rawArguments;

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

            object singleton = CompilerServices.CompileExpression(rawSingleton, scope);

            if ((singleton is NovaClass))
            {
                var @class = (NovaClass)singleton;
                if (_inClassDefine)
                {
                    if (@class.Name == _className)
                    {
                        function.IsSingleton = true;
                        return(function);
                    }
                    NovaClass.AddMethod(@class.InstanceMethods, function);
                    if (@class.RemovedMethods.Contains(name))
                    {
                        @class.RemovedMethods.Remove(name);
                    }
                    if (@class.UndefinedMethods.Contains(name))
                    {
                        @class.UndefinedMethods.Remove(name);
                    }
                }
                else
                {
                    NovaClass.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 NovaInstance)
            {
                var @object = (NovaInstance)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);
        }