public DekiScriptExpression Visit(DekiScriptAccess expr, DekiScriptExpressionEvaluationState state)
        {
            DekiScriptExpression prefix = expr.Prefix.VisitWith(this, state);
            DekiScriptExpression index  = expr.Index.VisitWith(this, state);
            DekiScriptAccess     access = (DekiScriptAccess)DekiScriptExpression.Access(expr.Location, prefix, index);

            if ((prefix is DekiScriptLiteral) && (index is DekiScriptLiteral))
            {
                DekiScriptLiteral result = DekiScriptExpressionEvaluation.Instance.Evaluate(access, state, false);

                // check if result is a property
                if (DekiScriptRuntime.IsProperty(result))
                {
                    // retrieve property information
                    var descriptor = state.Runtime.ResolveRegisteredFunctionUri(((DekiScriptUri)result).Value);
                    if ((descriptor != null) && descriptor.IsIdempotent)
                    {
                        // evaluate property, since it never changes
                        return(state.Runtime.EvaluateProperty(expr.Location, result, state.Env));
                    }
                    return(DekiScriptExpression.Call(expr.Location, result, new DekiScriptList()));
                }
                return(result);
            }
            return(access);
        }
Beispiel #2
0
 private static object Eval(object value, DekiScriptRuntime runtime)
 {
     if (value is XUri)
     {
         DekiScriptLiteral uri = DekiScriptExpression.Constant((XUri)value);
         if (DekiScriptRuntime.IsProperty(uri))
         {
             value = runtime.EvaluateProperty(Location.None, uri, runtime.CreateEnv()).NativeValue;
         }
     }
     return(value);
 }
        public DekiScriptExpression Visit(DekiScriptAccess expr, DekiScriptOptimizerState state)
        {
            DekiScriptExpression prefix = expr.Prefix.VisitWith(this, state);
            DekiScriptExpression index  = expr.Index.VisitWith(this, state);
            DekiScriptAccess     access = new DekiScriptAccess(expr.Line, expr.Column, prefix, index);

            if ((prefix is DekiScriptLiteral) && (index is DekiScriptLiteral))
            {
                // BUGBUGBUG (steveb): don't eval properties!
                DekiScriptLiteral result = DekiScriptExpressionEvaluation.Instance.Evaluate(access, state.Env, false);

                // check if result is a property
                if (DekiScriptRuntime.IsProperty(result))
                {
                    // retrieve property information
                    DekiScriptFunction function;
                    if (DekiScriptLibrary.Functions.TryGetValue(((DekiScriptUri)result).Value, out function))
                    {
                        if (function is DekiScriptFunctionNative)
                        {
                            DekiScriptFunctionNative native = (DekiScriptFunctionNative)function;

                            // check if function is idempotent; if so, execute it
                            if (native.IsIdempotent)
                            {
                                // evaluate property, since it never changes
                                return(DekiScriptRuntime.EvaluateProperty(result, state.Env));
                            }
                        }
                    }
                    return(new DekiScriptCall(expr.Line, expr.Column, result, new DekiScriptList(), false));
                }
                return(result);
            }
            return(access);
        }