예제 #1
0
        private Arity CalculateArity()
        {
            var min = ArgumentKinds.Count(a => a == ArgumentKind.Simple);

            if (ArgumentKinds.Any(a => a == ArgumentKind.Key || a == ArgumentKind.KeyRest))
            {
                min++;
            }
            var max = ArgumentKinds.Any(a => a == ArgumentKind.Rest) ? int.MaxValue : min;

            return(new Arity(min, max));
        }
예제 #2
0
        public iObject Call(iObject instance, params iObject[] arguments)
        {
            if (arguments.Length != ArgumentKinds.Count)
            {
                throw new ArgumentException(
                          $"{MethodName}: Number of arguments ({arguments.Length}) doesn't match expected number ({ArgumentKinds.Count})."
                          );
            }

            var bundle = new ArgumentBundle(ArgumentKinds.Zip(arguments, (kind, arg) => (kind, arg)));

            CallFrame.Push(this, instance, bundle);

            try
            {
                try
                {
                    return(CallCache.Call());
                }
                catch (RecompilationRequiredException)
                {
                    // caught while a method was being undefined.
                    // give a second chance to recover (which will possibly call method_missing).
                    return(CallCache.Call());
                }
            }
            catch (Exception e)
            {
                if (!e.Data.Contains(RB_STACK_KEY))
                {
                    e.Data[RB_STACK_KEY] = CallFrame.Current;
                }

                throw;
            }
            catch (System.Exception e)
            {
                if (!e.Data.Contains(RB_STACK_KEY))
                {
                    e.Data[RB_STACK_KEY] = CallFrame.Current.CallSite.MethodName.Name;
                }

                throw;
            }
            finally
            {
                CallFrame.Pop();
            }
        }
예제 #3
0
        public override string ToString()
        {
            var argumentKinds = string.Join(", ", ArgumentKinds.Select(_ => _.Description));

            return($"CallSite<\"{MethodName}\"<{Arity}>({argumentKinds})>");
        }