NatAgents.borg

NatAgents.borg


{
cl1:cl2:cl3:cl4:void;

Agent()::
  quote(test)~agent("test");

NewAgent()::
    {
    cl1:=new("clone1",
        {ssend(to,tag)::{send(to,tag); sync(to,tag)};
         sreply(tag,to)::{ssend(to,tag)};
         reply(tag,to)::{to->weply(tag)}});
    cl2:=new("clone2",
        {reply(tag,to)::{to->weply(tag)}});
    cl3:=new("clone3",
        {reply(tag,to)::{to->weply(tag)}});
    cl4:=new("clone4",
        {reply(tag,to)::{to->weply(tag)}});
    true
    };


getback(value)::
    {
    cl1->sreply(value,replyer);
    srecv(cl1,any)
    };

KarstenSync()::
    {
    if (is_void(replyer), replyer:=clone(), false);
    value:getback(0);
    value=0
    };

Serialise()::
    {
    if(getback(true),true,ERROR(""));            `check true
     if(getback(false),ERROR(""),true);        `check false
     if(is_void(getback(void)),true,ERROR(""));    `check void
     if(empty~getback(empty),true,ERROR(""));        `check empty
    if(""=getback(""),true,ERROR(""));        `check null
    a:[1];
    a[1]:=a;
    b:getback(a);
    if (b[1]~b,true,ERROR("<[circle]>"));            `check circulaire lijsten
    b:read("test");
    c:getback(b);
    if (c~b,true,ERROR(""));                     `check references
    if (getback(+) ~ +, true, ERROR("native"));         `check natives
    true
    };

Agentdie()::
    {
    cl1->agentdie();
    cl2->agentdie();
    cl3->agentdie();
    cl4->agentdie();
    true};

Agentmove()::
    {
    twice(i)::
        {
        if (i > 0,
            {
            agentmove(uiagent);
            twice(i - 1)
            })
        };
    twice(2);
    true
    };

Clone2Agent()::
  {
  ca(n)::clone2agent(n);
  t:ca("blaargh");
  u:ca("blaargh");
  t!~u
  };

ITEM("agent",Agent,1);
ITEM("newagent",NewAgent,10);
ITEM("karstensync",KarstenSync,10);
ITEM("serialisation",Serialise,10);
ITEM("agentdie",Agentdie,10);
ITEM("agentmove",Agentmove,50);
ITEM("clone2agent",Clone2Agent,1)
}