pushThreadBindings() private method

private pushThreadBindings ( Associative bindings ) : void
bindings Associative
return void
Exemplo n.º 1
0
 protected override object Read(PushbackTextReader r, char backquote)
 {
     try
     {
         Var.pushThreadBindings(RT.map(GENSYM_ENV, PersistentHashMap.EMPTY));
         //object form = read(r, true, null, true);
         object form = ReadAux(r);
         return(syntaxQuote(form));
     }
     finally
     {
         Var.popThreadBindings();
     }
 }
Exemplo n.º 2
0
            /// <summary>
            /// Worker method to execute the action on a thread.
            /// </summary>
            /// <param name="state">(not used)</param>
            /// <remarks>corresponds to doRun in Java version</remarks>
            void ExecuteAction(object state)
            {
                try
                {
                    Var.pushThreadBindings(RT.map(RT.AGENT, _agent));
                    Agent.Nested = PersistentVector.EMPTY;

                    bool hadError = false;

                    try
                    {
                        object oldval = _agent.State;
                        object newval = _fn.applyTo(RT.cons(_agent.State, _args));
                        _agent.SetState(newval);
                        _agent.notifyWatches(oldval, newval);
                    }
                    catch (Exception e)
                    {
                        // TODO: report/callback  (Java TODO)
                        _agent.AddError(e);
                        hadError = true;
                    }

                    if (!hadError)
                    {
                        releasePendingSends();
                    }

                    bool             popped = false;
                    IPersistentStack next   = null;
                    while (!popped)
                    {
                        IPersistentStack prior = _agent._q.Get();
                        next   = prior.pop();
                        popped = _agent._q.CompareAndSet(prior, next);
                    }

                    if (next.count() > 0)
                    {
                        ((Action)next.peek()).execute();
                    }
                }
                finally
                {
                    Nested = null;
                    Var.popThreadBindings();
                }
            }
Exemplo n.º 3
0
            //static ListReader _listReader = new ListReader();

            protected override object Read(PushbackTextReader r, char lparen)
            {
                if (ARG_ENV.deref() != null)
                {
                    throw new InvalidOperationException("Nested #()s are not allowed");
                }
                try
                {
                    Var.pushThreadBindings(RT.map(ARG_ENV, PersistentTreeMap.EMPTY));
                    r.Unread('(');
                    ////object form = ReadAux(r, true, null, true);
                    object form = ReadAux(r);
                    //object form = _listReader.invoke(r, '(');

                    IPersistentVector args    = PersistentVector.EMPTY;
                    PersistentTreeMap argsyms = (PersistentTreeMap)ARG_ENV.deref();
                    ISeq rargs = argsyms.rseq();
                    if (rargs != null)
                    {
                        int higharg = (int)((IMapEntry)rargs.first()).key();
                        if (higharg > 0)
                        {
                            for (int i = 1; i <= higharg; ++i)
                            {
                                object sym = argsyms.valAt(i);
                                if (sym == null)
                                {
                                    sym = garg(i);
                                }
                                args = args.cons(sym);
                            }
                        }
                        object restsym = argsyms.valAt(-1);
                        if (restsym != null)
                        {
                            args = args.cons(Compiler._AMP_);
                            args = args.cons(restsym);
                        }
                    }
                    return(RT.list(Compiler.FN, args, form));
                }
                finally
                {
                    Var.popThreadBindings();
                }
            }