Example #1
0
 public void AddOperation(Runtime runtime, string key,
                          IP5Any value)
 {
     switch (key)
     {
     case "+":
         AddOperation(runtime, OverloadOperation.ADD, value);
         break;
     case "+=":
         AddOperation(runtime, OverloadOperation.ADD_ASSIGN, value);
         break;
     case "-":
         AddOperation(runtime, OverloadOperation.SUBTRACT, value);
         break;
     case "-=":
         AddOperation(runtime, OverloadOperation.SUBTRACT_ASSIGN, value);
         break;
     case "*":
         AddOperation(runtime, OverloadOperation.MULTIPLY, value);
         break;
     case "*=":
         AddOperation(runtime, OverloadOperation.MULTIPLY_ASSIGN, value);
         break;
     case "/":
         AddOperation(runtime, OverloadOperation.DIVIDE, value);
         break;
     case "/=":
         AddOperation(runtime, OverloadOperation.DIVIDE_ASSIGN, value);
         break;
     case "<<":
         AddOperation(runtime, OverloadOperation.SHIFT_LEFT, value);
         break;
     case "<<=":
         AddOperation(runtime, OverloadOperation.SHIFT_LEFT_ASSIGN, value);
         break;
     case ">>":
         AddOperation(runtime, OverloadOperation.SHIFT_RIGHT, value);
         break;
     case ">>=":
         AddOperation(runtime, OverloadOperation.SHIFT_RIGHT_ASSIGN, value);
         break;
     }
 }
Example #2
0
        public void AddOperation(Runtime runtime, OverloadOperation op,
                                 IP5Any value)
        {
            P5Scalar s = value as P5Scalar;
            int idx = (int)op;

            if (s != null && s.IsReference(runtime))
            {
                var code = s.Dereference(runtime) as P5Code;

                if (code != null)
                {
                    subroutines[idx] = code;
                    methods[idx] = null;
                    return;
                }
            }

            subroutines[idx] = null;
            methods[idx] = value.AsString(runtime);
        }
Example #3
0
        public P5Scalar CallOperation(Runtime runtime, OverloadOperation op,
                                      P5Scalar left, IP5Any right,
                                      bool inverted)
        {
            var args = new P5Array(runtime,
                                   inverted ? right : left,
                                   inverted ? left : right,
                                   new P5Scalar(runtime, inverted));

            if (subroutines[(int)op] != null)
            {
                return subroutines[(int)op].Call(runtime,
                                                 Opcode.ContextValues.SCALAR,
                                                 args) as P5Scalar;
            }
            else
            {
                return args.CallMethod(runtime, Opcode.ContextValues.SCALAR,
                                       methods[(int)op]) as P5Scalar;
            }
        }