예제 #1
0
 public override bool LessThanOrEqual(
     StackContext sctx,
     PValue leftOperand,
     PValue rightOperand,
     out PValue result)
 {
     result =
         StringComparer.Ordinal.Compare(
             leftOperand.CallToString(sctx), rightOperand.CallToString(sctx)) <= 0;
     return true;
 }
예제 #2
0
 public override bool Addition(
     StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result)
 {
     var left = leftOperand.CallToString(sctx);
     var right = rightOperand.CallToString(sctx);
     result = System.String.Concat(left, right);
     return true;
 }
예제 #3
0
 public override bool GreaterThan(
     StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result)
 {
     result =
         StringComparer.Ordinal.Compare(
             leftOperand.CallToString(sctx), rightOperand.CallToString(sctx)) > 0;
     return true;
 }
예제 #4
0
        public static PValue RunStatically(StackContext sctx, PValue fpv, PValue[] iargs,
            bool useIndirectCallAsFallback)
        {
            IStackAware f;
            IMaybeStackAware m;
            CilClosure cilClosure;
            PFunction func = null;
            PVariable[] sharedVars = null;

            PValue result;
            ReturnMode returnMode;

            if ((cilClosure = fpv.Value as CilClosure) != null)
            {
                func = cilClosure.Function;
                sharedVars = cilClosure.SharedVariables;
            }

            if ((func = func ?? fpv.Value as PFunction) != null && func.HasCilImplementation)
            {
                func.CilImplementation.Invoke(
                    func, CilFunctionContext.New(sctx, func), iargs, sharedVars ?? new PVariable[0],
                    out result, out returnMode);
            }
            else if ((f = fpv.Value as IStackAware) != null)
            {
                //Create stack context, let the engine execute it
                var subCtx = f.CreateStackContext(sctx, iargs);
                sctx.ParentEngine.Process(subCtx);
                result = subCtx.ReturnValue;
                returnMode = subCtx.ReturnMode;
            }
            else if ((m = fpv.Value as IMaybeStackAware) != null)
            {
                StackContext subCtx;
                if (m.TryDefer(sctx, iargs, out subCtx, out result))
                {
                    sctx.ParentEngine.Process(subCtx);
                    result = subCtx.ReturnValue;
                    returnMode = subCtx.ReturnMode;
                }
                else if (useIndirectCallAsFallback)
                {
                    returnMode = ReturnMode.Exit;
                }
                else
                {
                    throw new PrexoniteException(
                        string.Format(
                            "Invocation of {0} did not produce a valid return mode. " +
                                "Only Prexonite functions have a return mode.",
                            fpv.CallToString(sctx)));
                }
            }
            else if (useIndirectCallAsFallback)
            {
                result = fpv.IndirectCall(sctx, iargs);
                returnMode = ReturnMode.Exit;
            }
            else
            {
                throw new PrexoniteException(
                    "call\\sub\\perform requires its argument to be stack aware.");
            }

            return new PValueKeyValuePair(sctx.CreateNativePValue(returnMode), result);
        }