Beispiel #1
0
        public override void Execute(ICpu cpu)
        {
            string suffixName = cpu.PopStack().ToString().ToUpper();
            object popValue = cpu.PopValueEncapsulated();

            var specialValue = popValue as ISuffixed;

            if (specialValue == null)
            {
                throw new Exception(string.Format("Values of type {0} cannot have suffixes", popValue.GetType()));
            }

            ISuffixResult result = specialValue.GetSuffix(suffixName);

            // If the result is a suffix that is still in need of being invoked and hasn't resolved to a value yet:
            if (result != null && !IsMethodCallAttempt && !result.HasValue)
            {
                // This is what happens when someone tries to call a suffix method as if
                // it wasn't a method (i.e. leaving the parentheses off the call).  The
                // member returned is a delegate that needs to be called to get its actual
                // value.  Borrowing the same routine that OpcodeCall uses for its method calls:

                cpu.PushStack(result);
                cpu.PushStack(new KOSArgMarkerType());
                OpcodeCall.StaticExecute(cpu, false, "", false); // this will push the return value on the stack for us.
            }
            else
            {
                if (result.HasValue)
                {
                    // Push the already calculated value.

                    cpu.PushStack(result.Value);
                }
                else
                {
                    // Push the indirect suffix delegate, but don't execute it yet
                    // because we need to put the upcoming arg list above it on the stack.
                    // Eventually an <indirect> OpcodeCall will occur further down the program which
                    // will actually execute this.

                    cpu.PushStack(result);
                }
            }
        }
Beispiel #2
0
 public override void Execute(ICpu cpu)
 {
     cpu.PushStack(cpu.PopValueEncapsulated());
 }