perform() public method

public perform ( IoObject target, IoObject locals, IoObject message ) : IoObject
target IoObject
locals IoObject
message IoObject
return IoObject
Esempio n. 1
0
        public static IEnumerator asyncCall(IoContext ctx, IoObject future)
        {
            IoObject  target       = ctx.target;
            IoObject  locals       = ctx.locals;
            IoObject  result       = target;
            IoObject  cachedTarget = target;
            IoMessage msg          = ctx.message;
            IoObject  savedPrevResultAsYieldResult = null;

            do
            {
                if (msg.messageName.Equals(msg.state.semicolonSymbol))
                {
                    target = cachedTarget;
                }
                else
                {
                    result = msg.cachedResult;
                    if (result == null)
                    {
                        if (msg.messageName.value.Equals("yield"))
                        {
                            yield return(result);
                        }
                        else
                        {
                            result = target.perform(target, locals, msg);
                        }
                    }
                    if (result == null)
                    {
                        result = savedPrevResultAsYieldResult;
                    }
                    target = result;
                    savedPrevResultAsYieldResult = result;
                }
            } while ((msg = msg.next) != null);
            future.slots["future"] = result;
            yield return(null);
            //yield return result;
        }
Esempio n. 2
0
        public static IEnumerator <IoObject> slotAsyncWhile(IoObject target, IoObject locals, IoObject message, IoObject future)
        {
            IoMessage m      = message as IoMessage;
            IoObject  result = target.state.ioNil;
            IoObject  cond   = null;

            while (true)
            {
                cond = m.localsValueArgAt(locals, 0);
                //evaluateArgs(m, new EvaluateArgsEventArgs(0), out cond);

                if (cond == target.state.ioFalse || cond == target.state.ioNil)
                {
                    break;
                }

                //result = m.localsValueArgAt(locals, 1);
                //evaluateArgs(m, new EvaluateArgsEventArgs(1), out result);

                IoMessage msg = 1 < m.args.Count ? m.args[1] as IoMessage : null;
                if (msg != null)
                {
                    if (msg.cachedResult != null && msg.next == null)
                    {
                        result = msg.cachedResult;
                        yield return(result);
                    }
                    //result = localMessage.localsPerformOn(locals, locals);

                    result = target;
                    IoObject cachedTarget = target;
                    IoObject savedPrevResultAsYieldResult = null;

                    do
                    {
                        if (msg.messageName.Equals(msg.state.semicolonSymbol))
                        {
                            target = cachedTarget;
                        }
                        else
                        {
                            result = msg.cachedResult;
                            if (result == null)
                            {
                                if (msg.messageName.value.Equals("yield"))
                                {
                                    yield return(result);
                                }
                                else
                                {
                                    result = target.perform(target, locals, msg);
                                }
                            }
                            if (result == null)
                            {
                                target = cachedTarget;
                                //result = savedPrevResultAsYieldResult;
                            }
                            else
                            {
                                target = result;
                            }
                            savedPrevResultAsYieldResult = result;
                        }
                    } while ((msg = msg.next) != null);
                    future.slots["future"] = result;

                    yield return(null);
                }

                result = m.state.ioNil;

                if (target.state.handleStatus() != 0)
                {
                    goto done;
                }
            }
done:
            yield return(null);
        }
Esempio n. 3
0
 public static IoObject slotLocalsForward(IoObject target, IoObject locals, IoObject message)
 {
     IoObject o = target.slots[target.state.selfSymbol] as IoObject;
     if (o != null && o != target)
         return target.perform(o, locals, message);
     return target.state.ioNil;
 }
Esempio n. 4
0
        public static IEnumerator slotAsyncWhile(IoObject target, IoObject locals, IoObject message, IoObject future)
        {
            IoMessage m = message as IoMessage;
            IoObject result = target.state.ioNil;
            IoObject cond = null;

            while (true)
            {
                cond = m.localsValueArgAt(locals, 0);
                //evaluateArgs(m, new EvaluateArgsEventArgs(0), out cond);

                if (cond == target.state.ioFalse || cond == target.state.ioNil)
                {
                    break;
                }

                //result = m.localsValueArgAt(locals, 1);
                //evaluateArgs(m, new EvaluateArgsEventArgs(1), out result);

                IoMessage msg = 1 < m.args.Count ? m.args[1] as IoMessage : null;
                if (msg != null)
                {
                    if (msg.cachedResult != null && msg.next == null)
                    {
                        result = msg.cachedResult;
                        yield return result;
                    }
                    //result = localMessage.localsPerformOn(locals, locals);

                    result = target;
                    IoObject cachedTarget = target;
                    IoObject savedPrevResultAsYieldResult = null;

                    do
                    {
                        if (msg.messageName.Equals(msg.state.semicolonSymbol))
                        {
                            target = cachedTarget;
                        }
                        else
                        {
                            result = msg.cachedResult;
                            if (result == null)
                            {
                                if (msg.messageName.value.Equals("yield"))
                                {
                                    yield return result;
                                }
                                else
                                {
                                    result = target.perform(target, locals, msg);
                                }
                            }
                            if (result == null)
                            {
                                target = cachedTarget;
                                //result = savedPrevResultAsYieldResult;
                            }
                            else
                            {
                                target = result;
                            }
                            savedPrevResultAsYieldResult = result;
                        }
                    } while ((msg = msg.next) != null);
                    future.slots["future"] = result;

                    yield return null;
                }

                result = m.state.ioNil;

                if (target.state.handleStatus() != 0)
                {
                    goto done;
                }

            }
            done:
            yield return null;
        }
Esempio n. 5
0
        public IoObject localsPerformOn(IoObject target, IoObject locals)
        {
            if (async)
            {
                IoContext ctx = new IoContext();
                ctx.target = target;
                ctx.locals = locals;
                ctx.message = this;
                IoState state = target.state;
                IoObject future = IoObject.createObject(state);
                IEnumerator e = IoMessage.asyncCall(ctx, future);
                state.contextList.Add(e);
                return future;
            }

            IoObject result = target;
            IoObject cachedTarget = target;
            IoMessage msg = this;
            do
            {
                if (msg.messageName.Equals(msg.state.semicolonSymbol))
                {
                    target = cachedTarget;
                }
                else
                {
                    result = msg.cachedResult;
                    if (result == null)
                    {
                        //if (target.tag.performFunc == null)
                            result = target.perform(target, locals, msg);
                        //else
                        //    result = target.tag.performFunc(target, locals, msg);
                    }
                    if (result == null)
                    {
                        Console.WriteLine("Message chains intermediate mustn't be null");
                    }
                    target = result;
                }
            } while ((msg = msg.next) != null);
            return result;
        }