Esempio n. 1
0
 public CallFrame(CallSite callSite,
                  iObject instance,
                  ArgumentBundle arguments = null,
                  CallFrame caller         = null)
 {
     CallSite  = callSite;
     Instance  = instance;
     Caller    = caller ?? Current;
     Arguments = arguments ?? new ArgumentBundle();
     Locals    = new LinkedDictionary <Symbol, LocalVariable>();
 }
Esempio n. 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();
            }
        }
Esempio n. 3
0
 public static void Pop() => Current = Current?.Caller;
Esempio n. 4
0
 public static void Push(CallFrame other)
 {
     other.Caller = Current;
     Current      = other;
 }
Esempio n. 5
0
 public static CallFrame Push(CallSite callSite,
                              iObject instance,
                              ArgumentBundle arguments = null)
 => Current = new CallFrame(callSite, instance, arguments);