Exemplo n.º 1
0
    def testLoop(self):
        from pymud.mob import Mob
        finish(interpret("""loop {
say forever
break
}
""",Mob(commands={'say':say,'break':breakCommand},variables={})))
Exemplo n.º 2
0
 def visitIfStatement(self,node,*args):
     yield
     finish(self.visit(node.condition))
     if node.condition.value in self.conditions and\
         self.conditions[node.condition.value]:
         call = self.visit(node.script)
         while step(call): yield
Exemplo n.º 3
0
 def visitHelpStatement(self,node,*args):
     yield
     finish(self.visit(node.command))
     commandName = node.command.value
     if commandName in self.commands:
         self.instance.sendMessage("help",name=commandName,help=self.commands[commandName].__doc__)
     else:
         self.instance.sendMessage("invalidcommand",name=commandName)
Exemplo n.º 4
0
 def run(self,n=1):
     self.tick += n
     for queue in self.itemQueues.keys():
         if self.tick % queue == 0:
             if queue in self.itemIterators and self.itemIterators[queue]:
                 finish(self.itemIterators[queue])
                 self.itemIterators[queue] = None
             self.itemIterators[queue] = self.runItemQueue(queue)
     for queue,iterator in self.itemIterators.iteritems():
         step(iterator)
Exemplo n.º 5
0
    def testStrings(self):
        from pymud.mob import Mob
        finish(interpret("""hello there\n""",Mob(commands={},variables={})))
        finish(interpret("""hello there
line 2
line 3
variable $var
""",Mob(commands={},variables={'var':5})))
        call = interpret("""hello there
line 2
line 3
variable $var
""",Mob(commands={},variables={'var':5}))
        for x in xrange(10):
            print "%s:" % x
            step(call)
Exemplo n.º 6
0
 def visitExpressionStatement(self,node,*args):
     """Handles the command statement case and the print statement case"""
     yield
     command = node.expressions[0]
     finish(self.visit(command))
     if command.value in self.commands:
         for expression in node.expressions[1:]:
             finish(self.visit(expression))
         func = self.commands[command.value]
         arguments = map(lambda x: x.value,node.expressions[1:])
         if hasattr(func,'im_self') and func.im_self:
             call = func(*arguments)
         else:
             call =func(*[self.instance] + arguments)
         if isinstance(call,GeneratorType):
             while step(call): yield
     else:
         for expression in node.expressions[1:]:
             finish(self.visit(expression))
         self.instance.default(map(lambda x: str(x.value),node.expressions))
Exemplo n.º 7
0
 def syncAll(self):
     if not self.writeBackIterator:
         self.writeBackIterator = self.partialSync()
     finish(self.writeBackIterator)
     self.db.dict.sync()
Exemplo n.º 8
0
 def visitAssign(self,node,*args):
     yield
     finish(self.visit(node.variable))
     for symbol in node.expression:
         finish(self.visit(symbol))
     self.instance.variables[str(node.variable.value)] = " ".join(map(lambda x:str(x.value),node.expression))
Exemplo n.º 9
0
    def testHelp(self):
        from pymud.mob import Mob
        finish(interpret("""? say
""",Mob(commands={'say':say,'break':breakCommand},variables={})))
Exemplo n.º 10
0
    def testIf(self):
        from pymud.mob import Mob
        finish(interpret("""if alive {
say i am alive
}
""",Mob(commands={'say':say},variables={})))
Exemplo n.º 11
0
 def testCommand(self):
     from pymud.mob import Mob
     finish(interpret("""say hello\n""",Mob(commands={'say':say},variables={})))
Exemplo n.º 12
0
 def test(self):
     def a(rule,o,result):
         return iter(xrange(5))
     o = Struct()
     call = SteppableRule(Pass,a)(o)
     finish(call)