Пример #1
0
        internal void EmitValueChangedCallback(EmitContext ec, string name, TypeSpec type, Location loc)
        {
            if (listener_id == null)
            {
                listener_id = ListenerProxy.Register(ModificationListener);
            }

            if (listener_proxy_value == null)
            {
                listener_proxy_value = typeof(ListenerProxy).GetMethod("ValueChanged");
            }

#if STATIC
            throw new NotSupportedException();
#else
            // object value, int row, int col, string name, int listenerId
            if (type.IsStructOrEnum)
            {
                ec.Emit(OpCodes.Box, type);
            }

            ec.EmitInt(loc.Row);
            ec.EmitInt(loc.Column);
            ec.Emit(OpCodes.Ldstr, name);
            ec.EmitInt(listener_id.Value);
            ec.Emit(OpCodes.Call, listener_proxy_value);
#endif
        }
Пример #2
0
        /// <summary>
        ///   Evaluates and expression or statement and returns any result values.
        /// </summary>
        /// <remarks>
        ///   Evaluates the input string as a C# expression or
        ///   statement.  If the input string is an expression
        ///   the result will be stored in the result variable
        ///   and the result_set variable will be set to true.
        ///
        ///   It is necessary to use the result/result_set
        ///   pair to identify when a result was set (for
        ///   example, execution of user-provided input can be
        ///   an expression, a statement or others, and
        ///   result_set would only be set if the input was an
        ///   expression.
        ///
        ///   If the return value of this function is null,
        ///   this indicates that the parsing was complete.
        ///   If the return value is a string, it indicates
        ///   that the input is partial and that the user
        ///   should provide an updated string.
        /// </remarks>
        public string Evaluate(string input, out object result, out bool result_set)
        {
            CompiledMethod compiled;

            result_set = false;
            result     = null;

            input = Compile(input, out compiled);
            if (input != null)
            {
                return(input);
            }

            if (compiled == null)
            {
                return(null);
            }

            //
            // The code execution does not need to keep the compiler lock
            //
            object retval = typeof(QuitValue);

            try {
                invoke_thread = System.Threading.Thread.CurrentThread;
                invoking      = true;
                compiled(ref retval);
#if MONO_FEATURE_THREAD_ABORT
            } catch (ThreadAbortException e) {
                Thread.ResetAbort();
                Console.WriteLine("Interrupted!\n{0}", e);
#else
            } catch (ThreadInterruptedException e) {
                Console.WriteLine("Interrupted!\n{0}", e);
#endif
            } finally {
                invoking = false;

                if (listener_id != null)
                {
                    ListenerProxy.Unregister(listener_id.Value);
                    listener_id = null;
                }
            }

            //
            // We use a reference to a compiler type, in this case
            // Driver as a flag to indicate that this was a statement
            //
            if (!ReferenceEquals(retval, typeof(QuitValue)))
            {
                result_set = true;
                result     = retval;
            }

            return(null);
        }