Beispiel #1
0
 public override TResult Call <TResult>(ICallable <TResult> callable)
 {
     lock (Mutex)
     {
         return(callable.Call());
     }
 }
Beispiel #2
0
        public object VisitCallExpression(CallExpression expression)
        {
            object callee = Evaluate(expression.callee);

            List <object> arguments = new List <object>();

            foreach (IExpression argument in expression.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            // Incorrect call, the calle cannot be called (ie. "some string"() )
            if (callee is ICallable == false)
            {
                throw new RuntimeError(expression.paren, "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            // Not correct number of arguments
            if (arguments.Count != function.Arity())
            {
                // TODO: Might want to make it like JavaScript where it uses null when not enough, and discards when too many
                throw new RuntimeError(expression.paren, $"Expected {function.Arity()} arguments but got {arguments.Count}.");
            }

            return(function.Call(this, expression, arguments));
        }
Beispiel #3
0
        public object VisitCallExpr(Expr.Call expr)
        {
            object callee = Evaluate(expr.Callee);

            List <object> arguments = new List <object>();

            foreach (var argument in expr.Arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                throw new InterpretingException(expr.Paren,
                                                "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            if (arguments.Count != function.Arity)
            {
                throw new InterpretingException(expr.Paren,
                                                $"Expected {function.Arity} arguments but got {arguments.Count}.");
            }
            return(function.Call(this, arguments));
        }
Beispiel #4
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void OnDisable()
 {
     if (null != _onDisable)
     {
         _onDisable.Call(_this, null);
     }
 }
        private void BlockTag(string tag, IDictionary attributes, ICallable block)
        {
            Output.Write("<{0}", tag);

            var attributeValues = new System.Collections.Generic.List <string>();

            if (null != attributes)
            {
                foreach (DictionaryEntry entry in attributes)
                {
                    attributeValues.Add(string.Format("{0}=\"{1}\"", entry.Key, entry.Value));
                }
            }

            if (0 != attributeValues.Count)
            {
                Output.Write(" ");
                Output.Write(string.Join(" ", attributeValues.ToArray()));
            }

            Output.Write(">");
            if (block != null)
            {
                block.Call(null);
            }
            Output.Write("</{0}>", tag);
        }
Beispiel #6
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void OnDestroy()
 {
     if (null != _onDestroy)
     {
         _onDestroy.Call(_this, null);
     }
 }
Beispiel #7
0
        //call an ICallable object directly
        public static object Run(Environment env, ICallable callable, List <object> arguments)
        {
            try {
                //build the call object
                Token token = new Token(TokenType.EOF, "internal", null, -1);

                //build a new interpreter
                Interpreter interpreter = new Interpreter(env);
                Resolver    resolver    = new Resolver(interpreter);

                resolver.Resolve(((ScriptFunction)callable).GetDeclaration());

                //call the ICallable, returning the result
                return(callable.Call(interpreter, token, arguments));

                //WARNING: duplicate code
            } catch (ErrorHandler.AssertError) {
                ConsoleOutput.Log("Assert error caught at Run()");
                ConsoleOutput.Log("The program will now exit early");
            } catch (ErrorHandler.ParserError e) {
                ConsoleOutput.Log("Parser error caught at Run()");
                ConsoleOutput.Log("The following output is for internal debugging only, and will be removed from the final release:\n" + e.ToString());
            } catch (ErrorHandler.ResolverError e) {
                ConsoleOutput.Log("Resolver error caught at Run()");
                ConsoleOutput.Log("The following output is for internal debugging only, and will be removed from the final release:\n" + e.ToString());
            } catch (ErrorHandler.RuntimeError e) {
                ConsoleOutput.Log("Runtime error caught at Run()");
                ConsoleOutput.Log("The following output is for internal debugging only, and will be removed from the final release:\n" + e.ToString());
            } catch (Exception e) {
                ConsoleOutput.Log("Terminal error caught at Run()");
                ConsoleOutput.Log("The following output is for internal debugging only, and will be removed from the final release:\n" + e.ToString());
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Evaluate a function call expression
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public object VisitFunctionCallExpr(FunctionCall expr)
        {
            // get the called function
            object callee = Evaluate(expr.Callee);
            // evaluate the passed arguments
            List <object> arguments = new List <object>();

            foreach (Expr argument in expr.Arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                throw new RuntimeError(expr.Keyword, "Only functions are callable");
            }

            ICallable function = (ICallable)callee;

            // if the passed arguments are less than or exceep function argument length
            if (arguments.Count != function.ArgumentLength)
            {
                throw new RuntimeError(expr.Keyword, $"Expected {function.ArgumentLength} arguments but got {arguments.Count}");
            }
            // call the function
            return(function.Call(this, arguments));
        }
Beispiel #9
0
        /// <summary>
        /// Called by Unity.
        /// </summary>
        protected virtual void Awake()
        {
            try
            {
                _host.Execute(Script.String());
            }
            catch (Exception exception)
            {
                Debug.LogWarning("Could not execute script: " + exception.Message);

                return;
            }

            _this = JsValue.FromObject(_host, this);

            _update      = _host.GetFunction("Update");
            _fixedUpdate = _host.GetFunction("FixedUpdate");
            _lateUpdate  = _host.GetFunction("LateUpdate");
            _awake       = _host.GetFunction("Awake");
            _start       = _host.GetFunction("Start");
            _onEnable    = _host.GetFunction("OnEnable");
            _onDisable   = _host.GetFunction("OnDisable");
            _onDestroy   = _host.GetFunction("OnDestroy");

            if (null != _awake)
            {
                _awake.Call(_this, null);
            }
        }
Beispiel #10
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void Update()
 {
     if (null != _update)
     {
         _update.Call(_this, null);
     }
 }
Beispiel #11
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void FixedUpdate()
 {
     if (null != _fixedUpdate)
     {
         _fixedUpdate.Call(_this, null);
     }
 }
Beispiel #12
0
        object Expr.IVisitor <object> .Visit(Expr.Call _call)
        {
            object callee = Evaluate(_call.callee);

            List <object> arguments = new List <object>();

            foreach (Expr argument in _call.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                throw new RuntimeError(_call.paren, "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            if (arguments.Count != function.Arity)
            {
                throw new RuntimeError(_call.paren, "Expected " + function.Arity + " arguments, but got " + arguments.Count + ".");
            }



            return(function.Call(this, arguments));
        }
Beispiel #13
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void Start()
 {
     if (null != _start)
     {
         _start.Call(_this, null);
     }
 }
Beispiel #14
0
        public object VisitCallExpr(Expr.Call expr)
        {
            object callee = Evaluate(expr.callee);

            List <object> arguments = new List <object>();

            foreach (Expr argument in expr.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                throw new RuntimeError(expr.paren,
                                       "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            if (arguments.Count != function.Arity())
            {
                throw new RuntimeError(expr.paren, "Expected " +
                                       function.Arity() + " arguments but got " +
                                       arguments.Count + ".");
            }

            return(function.Call(this, arguments));
        }
Beispiel #15
0
        public static object GroupBy(object proc, object list)
        {
            ICallable p      = RequiresNotNull <ICallable>(proc);
            Cons      e      = Requires <Runtime.Cons>(list);
            Hashtable result = new Hashtable();

            while (e != null)
            {
                object key = p.Call(e.car);

                object c = result[key];
                result[key] = new Cons(e.car, c);

                e = e.cdr as Cons;
            }

            Hashtable final = new Hashtable(result.Count);

            //now reverse the values
            foreach (DictionaryEntry de in result)
            {
                final[de.Key] = Reverse(de.Value);
            }

            return(final);
        }
Beispiel #16
0
        public static object Partition(object proc, object list)
        {
            ICallable p = RequiresNotNull <ICallable>(proc);
            Cons      e = Requires <Runtime.Cons>(list);
            Cons      h = null, head = null;
            Cons      h2 = null, head2 = null;

            while (e != null)
            {
                if (IsTrue(p.Call(e.car)))
                {
                    if (h == null)
                    {
                        h = head = new Cons(e.car);
                    }
                    else
                    {
                        h = (Cons)(h.cdr = new Cons(e.car));
                    }
                }
                else
                {
                    if (h2 == null)
                    {
                        h2 = head2 = new Cons(e.car);
                    }
                    else
                    {
                        h2 = (Cons)(h2.cdr = new Cons(e.car));
                    }
                }
                e = e.cdr as Cons;
            }
            return(Values(head, head2));
        }
Beispiel #17
0
        public object Visit(Call expr)
        {
            object callee = Evaluate(expr.callee);

            List <object> arguments = new List <object>();

            foreach (Expr argument in expr.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                throw new ErrorHandler.RuntimeError(expr.paren, "Can't call this datatype: " + (callee == null ? "null" : callee.ToString()));
            }

            ICallable called = (ICallable)callee;

            if (arguments.Count != called.Arity())
            {
                throw new ErrorHandler.RuntimeError(expr.paren, "Expected " + called.Arity() + " arguments but received " + arguments.Count);
            }

            return(called.Call(this, expr.paren, arguments));
        }
Beispiel #18
0
		private void BlockTag(string tag, IDictionary attributes, ICallable block)
		{
			Output.Write("<{0}", tag);

			System.Collections.Generic.List<string> attributeValues = new System.Collections.Generic.List<string>();

			if (null != attributes)
			{
				foreach(DictionaryEntry entry in attributes)
				{
					attributeValues.Add(string.Format("{0}=\"{1}\"", entry.Key, entry.Value));
				}
			}

			if (0 != attributeValues.Count)
			{
				Output.Write(" ");
				Output.Write(string.Join(" ", attributeValues.ToArray()));
			}

			Output.Write(">");
			if (block != null)
			{
				block.Call(null);
			}
			Output.Write("</{0}>", tag);
		}
Beispiel #19
0
        public object VisitCallExpr(Call expr)
        {
            Object callee = Evaluate(expr.Callee);

            List <Object> arguments = new List <Object>();

            foreach (Expr argument in  expr.Arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is ICallable))
            {
                // TODO: Change error message to not mention classes explicitly
                // since this shows up before classes are implemented.
                throw new RuntimeError(expr.Paren, "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            if (arguments.Count < function.RequiredArguments())
            {
                throw new RuntimeError(expr.Paren, "Not enough arguments.");
            }

            return(function.Call(this, arguments));
        }
Beispiel #20
0
 /// <summary>
 /// Called by Unity.
 /// </summary>
 protected virtual void LateUpdate()
 {
     if (null != _lateUpdate)
     {
         _lateUpdate.Call(_this, null);
     }
 }
 public int Call(ICallable callable, double salience, object value, IContinuation succ, IFailure fail)
 {
     if (callable is IAgent)
         ((IAgent)callable).Initialize(this, salience);
     if (salience > 0)
         return callable.Call(value, succ, fail);
     return 1;
 }
Beispiel #22
0
        /// <summary>
        /// Submits the specified callable to the thread pool.
        /// </summary>
        /// <param name="callable">The callable.</param>
        /// <returns></returns>
        public Future <T> Submit <T>(ICallable <T> callable)
        {
            var future = new SimpleFutureImpl <T>();

            _taskQueue.Push(
                () => future.Value = callable.Call());
            return(future);
        }
Beispiel #23
0
 /// <summary>
 /// Call click callback, if there is one.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void BalloonTipClicked(object sender, EventArgs e)
 {
     if (trayCallback != null)
     {
         trayCallback.Call();
         trayCallback = null;
     }
 }
Beispiel #24
0
 public static void eachInterface(ICallable callable, IEnumerable enumerable)
 {
     object[] args = new object[1];
     foreach (object item in enumerable)
     {
         args[0] = item;
         callable.Call(args);
     }
 }
Beispiel #25
0
        /// <summary>
        /// Submits the specified callable to the thread pool.
        /// </summary>
        /// <param name="callable">The callable.</param>
        /// <returns></returns>
        public IFuture <T> Submit <T>(ICallable <T> callable)
        {
            var future = new FutureImpl <T>();

            Log.Debug("Submit: Instance {0} - enqueuing callable", _id);
            _taskQueue.Push(
                () => future.Value = callable.Call());
            return(future);
        }
Beispiel #26
0
 public bool MoveNext()
 {
     if (_enumerator.MoveNext())
     {
         _arguments[0] = _enumerator.Current;
         _current      = _function.Call(_arguments);
         return(true);
     }
     return(false);
 }
Beispiel #27
0
        [Test] public void InvokeAnyCopiesContextWhenNewTaskForCallableWasOverriden([Values(true, false)] bool isTimed)
        {
            var cc             = SetupContextCarrier();
            var runnableFuture = MockRepository.GenerateMock <IRunnableFuture <T> >();

            _callable.Stub(x => x.Call()).Return(TestData <T> .Four);
            _sut.Stub(x => x.NewTaskFor(Arg <ICallable <T> > .Is.NotNull)).Return(runnableFuture);
            runnableFuture.Stub(x => x.Run()).Do(new Action(() => _callable.Call()));

            if (isTimed)
            {
                _sut.InvokeAny(Delays.Small, _callable, _callable);
            }
            else
            {
                _sut.InvokeAny(_callable, _callable);
            }
            runnableFuture.AssertWasCalled(x => x.Run());
            Mockery.Assert(cc.ActivityOf(x => x.Restore()).First < _callable.ActivityOf(x => x.Call()).First);
        }
Beispiel #28
0
    private static void CallPhoneNumbers(ICallable phone, string[] phoneNumbers)
    {
        StringBuilder result = new StringBuilder();

        foreach (var phoneNumber in phoneNumbers)
        {
            result.AppendLine(phone.Call(phoneNumber));
        }

        Console.Write(result);
    }
Beispiel #29
0
 public virtual void  Run()
 {
     try
     {
         enclosingInstance.Value = function.Call();
     }
     catch (System.Exception ex)
     {
         enclosingInstance.Exception = ex;
     }
 }
Beispiel #30
0
 static object GetValue(ICallable <object> callable)
 {
     try
     {
         return(callable.Call());
     }
     catch (Exception exception)
     {
         return(ThrowHelper.FromInvalidOperationException_Cqrs(callable, exception));
     }
 }
 public void RenderBody(TextWriter writer)
 {
     if (body == null)
     {
         throw new MonoRailException("This component does not have a body content to be rendered");
     }
     using (parent.SetOutputStream(writer))
     {
         body.Call(new object[] { writer });
     }
 }
Beispiel #32
0
 static object GetValue(ICallable <object> callable)
 {
     try
     {
         return(callable.Call());
     }
     catch (Exception exception)
     {
         throw new InvalidOperationException($"Could not generate value for callable [{callable}]", exception);
     }
 }
Beispiel #33
0
		private void BlockTag(string tag, IDictionary attributes, ICallable block)
		{
			writer.WriteStartElement(tag);

			if (null != attributes)
			{
				foreach(DictionaryEntry entry in attributes)
				{
					writer.WriteAttributeString((string) entry.Key, (string) entry.Value);
				}
			}

			if (block != null)
			{
				block.Call(null);
			}
			writer.WriteEndElement();
		}
        public static object callSpecial(Context cx, ICallable fun, IScriptable thisObj, object [] args, IScriptable scope, IScriptable callerThis, int callType, string filename, int lineNumber)
        {
            if (callType == Node.SPECIALCALL_EVAL) {
                if (BuiltinGlobal.isEvalFunction (fun)) {
                    return evalSpecial (cx, scope, callerThis, args, filename, lineNumber);
                }
            }
            else if (callType == Node.SPECIALCALL_WITH) {
                if (BuiltinWith.IsWithFunction (fun)) {
                    throw Context.ReportRuntimeErrorById ("msg.only.from.new", "With");
                }
            }
            else {
                throw Context.CodeBug ();
            }

            return fun.Call (cx, scope, thisObj, args);
        }
 /// <summary> Execute top call to script or function.
 /// When the runtime is about to execute a script or function that will
 /// create the first stack frame with scriptable code, it calls this method
 /// to perform the real call. In this way execution of any script
 /// happens inside this function.
 /// </summary>
 protected internal virtual object DoTopCall(ICallable callable, Context cx, IScriptable scope, IScriptable thisObj, object [] args)
 {
     return callable.Call (cx, scope, thisObj, args);
 }
Beispiel #36
0
 public static void ForEach(Context ctx, IEnumerable<object> set, ICallable func)
 {
     foreach (var obj in set)
     {
         func.Call(ctx.GameState, ctx, new[] { obj });
     }
 }
Beispiel #37
0
        public static IEnumerable map(object enumerable, ICallable function)
        {
            if (null == enumerable) throw new ArgumentNullException("enumerable");
            if (null == function) throw new ArgumentNullException("function");

            object[] args = new object[1];
            foreach (object item in iterator(enumerable))
            {
                args[0] = item;
                yield return function.Call(args);
            }
        }
Beispiel #38
0
        /// <summary> Call {@link
        /// Callable#call(Context cx, Scriptable scope, Scriptable thisObj,
        /// Object[] args)}
        /// using the Context instance associated with the current thread.
        /// If no Context is associated with the thread, then
        /// {@link ContextFactory#makeContext()} will be called to construct
        /// new Context instance. The instance will be temporary associated
        /// with the thread during call to {@link ContextAction#run(Context)}.
        /// <p>
        /// It is allowed to use null for <tt>factory</tt> argument
        /// in which case the factory associated with the scope will be
        /// used to create new context instances.
        /// 
        /// </summary>
        public static object Call(ContextFactory factory, ICallable callable, IScriptable scope, IScriptable thisObj, object [] args)
        {
            if (factory == null) {
                factory = ContextFactory.Global;
            }

            Context cx = CurrentContext;
            if (cx != null) {
                object result;
                if (cx.factory != null) {
                    result = callable.Call (cx, scope, thisObj, args);
                }
                else {
                    // Context was associated with the thread via Context.enter,
                    // set factory to make Context.enter/exit to be no-op
                    // during call
                    cx.factory = factory;
                    try {
                        result = callable.Call (cx, scope, thisObj, args);
                    }
                    finally {
                        cx.factory = null;
                    }
                }
                return result;
            }

            cx = PrepareNewContext (AppDomain.CurrentDomain, factory);
            try {
                return callable.Call (cx, scope, thisObj, args);
            }
            finally {
                ReleaseContext (cx);
            }
        }