public Context(Context context, Agent agent) { job = context.job; activation = context.activation; letBindings = context.letBindings; myself = context.agent; agentBit = agent.agentBit(); }
public Object callReporterProcedure(Activation newActivation) { boolean oldInReporterProcedure = inReporterProcedure; Command command = null; inReporterProcedure = true; // so use of "ask" will create an exclusive job activation = newActivation; ip = 0; try { do { command = activation.procedure().code()[ip]; if ((agentBit & command.agentBits) == 0) { command.throwAgentClassException(this, agent.kind()); } command.perform(this); if (command.world.comeUpForAir) { comeUpForAir(command); } } while (!finished && job.result == null); } catch (NonLocalExit$ e) { // do nothing } catch (LogoException ex) { EngineException.rethrow(ex, this, command); } finally { inReporterProcedure = oldInReporterProcedure; } ip = activation.returnAddress(); activation = activation.parent(); Object result = job.result; job.result = null; return result; }
// This constructor is used when a Context spawns a Job which // in turn spawns Contexts, such as with _ask. - ST 6/12/06 public Context(Job job, Agent agent, int ip, Activation activation) { this.job = job; this.agent = agent; if (agent != null) { agentBit = agent.agentBit(); } this.ip = ip; this.activation = activation; }
// this method runs until the context is finished void runExclusive() { if (agent.id == -1) // is our agent dead? { finished = true; return; } Command command = null; try { do { command = activation.procedure().code()[ip]; if ((agentBit & command.agentBits) == 0) { command.throwAgentClassException(this, agent.kind()); } command.perform(this); if (command.world.comeUpForAir) { comeUpForAir(command); } } while (!finished); } catch (LogoException ex) { EngineException.rethrow(ex, this, command); } }
// this method runs only until a command switches void stepConcurrent() { if (agent.id == -1) // is our agent dead? { finished = true; return; } Command command = null; try { do { command = activation.procedure().code()[ip]; if ((agentBit & command.agentBits) == 0) { command.throwAgentClassException(this, agent.kind()); } command.perform(this); if (command.world.comeUpForAir) { comeUpForAir(command); } } while (!command.switches && !finished); } catch (LogoException ex) { EngineException.rethrow(ex, this, command); } catch (StackOverflowError ex) { throw new EngineException(this, "stack overflow (recursion too deep)"); } }