Commits

ebo  committed a7432e1

generate some more interesting functions for changeglobals
output some stats into the program

  • Participants
  • Parent commits 36b7a1f

Comments (0)

Files changed (4)

File globalsgen.py

 from pygen.cgen import *
 from arithgen import ArithGen
+from iterables import IterableGenerator
 
 from utils import eval_branches, FunctionGenerator
 
 
 
 class ChangeGlobalGenerator(FunctionGenerator):
+    """
+    This generates some code to change a global 
+    and test if the changed function is executed.
+    """
     def __init__(self, module, stats, opts, rng):
         self.opts = opts
         self.module = module
         f.content.append("global len")
         f.content.append("del len")
         return f
-        
+
 
 
     def generate(self, opts, args_num, globals):
         fon = self.generate_globalon()
         foff = self.generate_globaloff()
-        
-        self.module.content.insert(0,fon)
-        self.module.content.insert(0,foff)
-        
+
+        self.module.content.insert(0, fon)
+        self.module.content.insert(0, foff)
+
+        iter_gen = IterableGenerator(self.module, self.stats, self.opts, self.rng)
+
+        iter = iter_gen.get_iterable(["1", "2", "3", "4"])
+
         f = self.create_function(0)
         f.content.extend(
-        [
-            CallStatement(fon, []),
-            "result = len(range(100))",
-            CallStatement(foff, []),
-            "return result"
-        ]
+            [
+                CallStatement(fon, []),
+                Assignment("result", '=', [CallStatement("len", iter)]),
+                CallStatement(foff, []),
+                "return result"
+            ]
         )
-        
+
         return f
 

File iterables.py

             return [gen.generate(2, literals)]
 
 class YieldFunctionGenerator(FunctionGenerator):
+    """
+    Returns a generator which uses yield.
+    """
     def __init__(self, module, stats, opts, rng):
         self.opts = opts
         self.module = module
         return CallStatement(f, pargs)
 
 class ListComprehensionGenerator(FunctionGenerator):
+    """
+    Returns a listcomprehension either as a list or a generator.
+    """
     def __init__(self, module, stats, opts, rng):
         self.opts = opts
         self.module = module
                 main.append(Assignment('x', '=', ['5.0']))
                 main.append('print x,')
 
+        self.module.main_body.insert(0, "print 'prog_size: %d'" % (lopts["prog_size"] - self.prog_size,))
+        self.module.main_body.insert(1, "print 'func_number: %d'" % (self.func_number,))
+        self.module.main_body.insert(2, "print 'arg_number: %d'" % (self.arg_number,))
         return self.module
 
     def arith_integer(self, opts, args_num, globals=[]):

File pygen/cgen.py

     @visit.when(CallStatement)
     def visit(self, depth, node):
         args = ", ".join(self.visit_args(node.args))
-        fun = "".join([node.func.name, '(', args, ')'])
+        
+        if isinstance(node.func, basestring):
+            fun = "".join([node.func, '(', args, ')'])
+        else:
+            fun = "".join([node.func.name, '(', args, ')'])
         return [self.code(depth, fun)]
 
     @visit.when(Assignment)