Exemple #1
0
        /// <summary>
        /// Executes the <paramref name="sourceCode"/> in the <paramref name="newContext"/>.
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="sourceCode">The code to execute</param>
        /// <param name="newContext">The context name to switch to before executeing the code</param>
        /// <returns>The executed source code's result</returns>
        private static AType ExecuteWithContextSwitch(Aplus environment, string sourceCode, string newContext)
        {
            AType result;

            string oldContext = environment.CurrentContext;

            environment.CurrentContext = newContext;

            DLR.Expression <Func <Aplus, AType> > lambda =
                Function.Monadic.NonScalar.Other.ExecuteFunction.BuildExecuteMethod(sourceCode, environment);

            Func <Aplus, AType> method = lambda.Compile();

            result = method(environment);

            environment.CurrentContext = oldContext;
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Executes the <paramref name="sourceCode"/> in the current context and catches errors (like monadic-do)
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="sourcecode">The code to execute</param>
        /// <returns>
        ///  1) An AInteger if there is an error, this integer is the number of the error
        ///  2) The executed source code's result enclosed in an ABox
        /// </returns>
        private static AType ProtectedExecute(Aplus environment, string sourcecode)
        {
            AType result;

            try
            {
                DLR.Expression <Func <Aplus, AType> > lambda =
                    Function.Monadic.NonScalar.Other.ExecuteFunction.BuildExecuteMethod(sourcecode, environment);
                Func <Aplus, AType> method = lambda.Compile();

                // Enclose the result
                result = ABox.Create(method(environment));
            }
            catch (Error error)
            {
                result = AInteger.Create((int)error.ErrorType);
            }

            return(result);
        }
Exemple #3
0
        public override AType Execute(AType argument, Aplus environment)
        {
            // Environment is required!
            Assert.NotNull(environment);

            if (argument.Type != ATypes.AChar)
            {
                throw new Error.Type(this.TypeErrorText);
            }

            if (argument.Rank > 1)
            {
                throw new Error.Rank(this.RankErrorText);
            }

            DLR.Expression <Func <Aplus, AType> > lambda = BuildExecuteMethod(argument.ToString(), environment);
            Func <Aplus, AType> method = lambda.Compile();

            AType result = method(environment);

            return(result);
        }
Exemple #4
0
        static AipcConnection()
        {
            DLR.ParameterExpression functionParameter = DLR.Expression.Parameter(typeof(AType), "_FUNCTION_");

            DLR.ParameterExpression environmentParameter = DLR.Expression.Parameter(typeof(Aplus), "_ENVIRONMENT_");
            DLR.ParameterExpression handleParameter      = DLR.Expression.Parameter(typeof(AType), "_HANDLE_NUMBER_");
            DLR.ParameterExpression eventTypeParameter   = DLR.Expression.Parameter(typeof(AType), "_EVENT_TYPE_");
            DLR.ParameterExpression callDataParameter    = DLR.Expression.Parameter(typeof(AType), "_CALL_DATA_");

            /**
             * Build the following lambda method:
             *  (function, env, handleNumber, eventType, callData) => function(env, callData, eventType, handleNumber);
             */
            DLR.Expression <Func <AType, Aplus, AType, AType, AType, AType> > method =
                DLR.Expression.Lambda <Func <AType, Aplus, AType, AType, AType, AType> >(
                    DLR.Expression.Convert(
                        DLR.Expression.Dynamic(
                            new Binder.InvokeBinder(new DYN.CallInfo(4)),
                            typeof(object),
                            functionParameter,
                            environmentParameter,
                            callDataParameter,
                            eventTypeParameter,
                            handleParameter
                            ),
                        typeof(AType)
                        ),
                    true,
                    functionParameter,
                    environmentParameter,
                    handleParameter,
                    eventTypeParameter,
                    callDataParameter
                    );

            CallbackFunction = method.Compile();
        }