示例#1
0
        /// <summary>
        /// Visit the anyof expression.
        /// </summary>
        /// <param name="expr">AnyOf expression.</param>
        /// <returns></returns>
        public object VisitAnyOf(AnyOfExpr expr)
        {
            var result     = false;
            var leftExpr   = expr.CompareExpr;
            var leftResult = leftExpr.Evaluate(this) as LObject;

            if (expr.ParamListExpressions == null || expr.ParamListExpressions.Count == 0)
            {
                return(new LBool(result));
            }

            // Resolve the parameters.
            ParamHelper.ResolveNonNamedParameters(expr.ParamListExpressions, expr.ParamList, this);

            foreach (var rvalue in expr.ParamList)
            {
                var rightResult   = rvalue as LObject;
                var compareResult = EvalHelper.Compare(expr, Operator.EqualEqual, leftResult, rightResult) as LObject;
                if (compareResult != null && compareResult.Type == LTypes.Bool && ((LBool)compareResult).Value == true)
                {
                    result = true;
                    break;
                }
            }
            return(new LBool(result));
        }
示例#2
0
        /// <summary>
        /// Creates new instance of the type.
        /// </summary>
        /// <returns></returns>
        public object VisitNew(NewExpr expr)
        {
            object[] constructorArgs = null;
            var      paramListExprs  = expr.ParamListExpressions;

            if (paramListExprs != null && paramListExprs.Count > 0)
            {
                expr.ParamList = new List <object>();
                ParamHelper.ResolveNonNamedParameters(paramListExprs, expr.ParamList, this);
                constructorArgs = expr.ParamList.ToArray();
            }

            // CASE 1: Built in basic system types ( string, date, time, etc )
            if (LTypesLookup.IsBasicTypeShortName(expr.TypeName))
            {
                // TODO: Move this check to Semacts later
                var langType  = LTypesLookup.GetLType(expr.TypeName);
                var methods   = this.Ctx.Methods.Get(langType);
                var canCreate = methods.CanCreateFromArgs(constructorArgs);
                if (!canCreate)
                {
                    throw ExceptionHelper.BuildRunTimeException(expr, "Can not create " + expr.TypeName + " from parameters");
                }

                // Allow built in type methods to create it.
                var result = methods.CreateFromArgs(constructorArgs);
                return(result);
            }
            // CASE 2: Custom types e.g. custom classes.
            var hostLangArgs = LangTypeHelper.ConvertToArrayOfHostLangValues(constructorArgs);
            var instance     = this.Ctx.Types.Create(expr.TypeName, hostLangArgs);
            var obj          = LangTypeHelper.ConvertToLangClass(instance);

            return(obj);
        }
示例#3
0
        /// <summary>
        /// Creates new instance of the type.
        /// </summary>
        /// <returns></returns>
        public override object DoEvaluate()
        {
            object[] constructorArgs = null;
            if (ParamListExpressions != null && ParamListExpressions.Count > 0)
            {
                ParamList = new List <object>();
                ParamHelper.ResolveNonNamedParameters(ParamListExpressions, ParamList);
                constructorArgs = ParamList.ToArray();
            }

            // CASE 1: Built in basic system types ( string, date, time, etc )
            if (LTypesLookup.IsBasicTypeShortName(this.TypeName))
            {
                // TODO: Move this check to Semacts later
                var langType  = LTypesLookup.GetLType(this.TypeName);
                var methods   = this.Ctx.Methods.Get(langType);
                var canCreate = methods.CanCreateFromArgs(constructorArgs);
                if (!canCreate)
                {
                    throw BuildRunTimeException("Can not create " + this.TypeName + " from parameters");
                }

                // Allow built in type methods to create it.
                var result = methods.CreateFromArgs(constructorArgs);
                return(result);
            }
            // CASE 2: Custom types e.g. custom classes.
            var hostLangArgs = LangTypeHelper.ConvertToArrayOfHostLangValues(constructorArgs);
            var instance     = Ctx.Types.Create(this.TypeName, hostLangArgs);

            return(new LClass(instance));
        }
示例#4
0
        /// <summary>
        /// Creates new instance of the type.
        /// </summary>
        /// <returns></returns>
        public override object DoEvaluate(IAstVisitor visitor)
        {
            var settings = Ctx.Plugins.GetSettings <LogSettings>("comlib.log");

            if (settings == null)
            {
                settings = new LogSettings();
                Ctx.Plugins.SetSettings("comlib.log", settings);
            }

            // 1. Resolve the parameters.
            ParamHelper.ResolveNonNamedParameters(ParamListExpressions, ParamList, visitor);

            if (Mode == "log")
            {
                Log(settings);
                return(LObjects.EmptyString);
            }
            else if (Mode == "level")
            {
                return(new LString(settings.LogLevelName));
            }
            else if (Mode == "level_check")
            {
                var level = this.LogLevel;
                if (level == "debug")
                {
                    return(settings.LogLevelValue == LogPluginConstants.Debug);
                }
                if (level == "info")
                {
                    return(settings.LogLevelValue == LogPluginConstants.Info);
                }
                if (level == "warn")
                {
                    return(settings.LogLevelValue == LogPluginConstants.Warn);
                }
                if (level == "error")
                {
                    return(settings.LogLevelValue == LogPluginConstants.Error);
                }
                if (level == "fatal")
                {
                    return(settings.LogLevelValue == LogPluginConstants.Fatal);
                }
                return(false);
            }
            else if (Mode == "configure")
            {
                Configure(settings);
                return(LObjects.EmptyString);
            }
            return(LObjects.EmptyString);
        }