Exemplo 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>();
 }
Exemplo 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();
            }
        }
Exemplo n.º 3
0
 public static void Pop() => Current = Current?.Caller;
Exemplo n.º 4
0
 public static void Push(CallFrame other)
 {
     other.Caller = Current;
     Current      = other;
 }
Exemplo n.º 5
0
 public static CallFrame Push(CallSite callSite,
                              iObject instance,
                              ArgumentBundle arguments = null)
 => Current = new CallFrame(callSite, instance, arguments);