public static IoObject slotWhile(IoObject target, IoObject locals, IoObject message) { IoMessage m = message as IoMessage; if (m.async) { IoState state = target.state; IoObject future = IoObject.createObject(state); IEnumerator <IoObject> e = IoObject.slotAsyncWhile(target, locals, message, future); state.contextList.Add(e); return(future); } IoObject result = target.state.ioNil; while (true) { bool sasync = m.async; m.async = false; IoObject cond = m.localsValueArgAt(locals, 0); if (cond == target.state.ioFalse || cond == target.state.ioNil) { break; } m.async = sasync; result = m.localsValueArgAt(locals, 1); if (target.state.handleStatus() != 0) { goto done; } } done: return(result); }
public void setupSingletons() { ioNil = objectProto.clone(this); ioNil.slots["type"] = IOSYMBOL("nil"); core.slots["nil"] = ioNil; ioTrue = IoObject.createObject(this); ioTrue.slots["type"] = IOSYMBOL("true"); core.slots["true"] = ioTrue; ioFalse = IoObject.createObject(this); ioFalse.slots["type"] = IOSYMBOL("false"); core.slots["false"] = ioFalse; }
public IoObject localsProto(IoState state) { IoObject obj = IoObject.createObject(state); IoObject firstProto = obj.protos[0] as IoObject; foreach (var key in firstProto.slots.Keys) { obj.slots[key] = firstProto.slots[key]; } firstProto.protos.Clear(); obj.slots["setSlot"] = new IoCFunction(state, "setSlot", new IoMethodFunc(IoObject.slotSetSlot)); obj.slots["setSlotWithType"] = new IoCFunction(state, "setSlotWithType", new IoMethodFunc(IoObject.slotSetSlotWithType)); obj.slots["updateSlot"] = new IoCFunction(state, "updateSlot", new IoMethodFunc(IoObject.localsUpdateSlot)); obj.slots["thisLocalContext"] = new IoCFunction(state, "thisLocalContext", new IoMethodFunc(IoObject.slotThisLocals)); obj.slots["forward"] = new IoCFunction(state, "forward", new IoMethodFunc(IoObject.slotLocalsForward)); return(obj); }
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 <IoObject> 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); }
public static IoObject slotAsyncCall(IoObject target, IoObject locals, IoObject message) { IoMessage msg = message as IoMessage; IoMessage aMessage = msg.rawArgAt(0); IoObject context = target; if (msg.args.Count >= 2) { context = msg.localsValueArgAt(locals, 1); } IoBlock o = target.rawGetSlot(aMessage.messageName) as IoBlock; if (o != null) { IoMessage mmm = o.containedMessage; mmm.async = true; IoContext ctx = new IoContext(); ctx.target = context; ctx.locals = target; ctx.message = mmm; mmm.async = true; IoState state = target.state; IoObject future = IoObject.createObject(state); IEnumerator <IoObject> e = IoMessage.asyncCall(ctx, future); state.contextList.Add(e); return(future); } else { IoCFunction cf = target.rawGetSlot(aMessage.messageName) as IoCFunction; if (cf != null) { cf.async = true; return(cf.activate(target, locals, aMessage, null)); } } return(aMessage.localsPerformOn(target, locals)); }