Commits

Anonymous committed 553f4b5

Do some (but by no means all) pep8-ification.

Comments (0)

Files changed (6)

+syntax: glob
+
+*.pyc
+
                          help="printf format to use for pointers in "
                               "--trace-marking (default: %default)")
     optparser.add_option("-i", "--interactive",
-                         action="store_true", dest="interactive", default=False,
+                         action="store_true", dest="interactive",
+                         default=False,
                          help="enter interactive mode")
     optparser.add_option("-m", "--trace-marking",
-                         action="store_true", dest="trace_marking", default=False,
+                         action="store_true", dest="trace_marking",
+                         default=False,
                          help="trace marking actions in generated C source")
     optparser.add_option("-p", "--pedigree",
                          dest="pedigree", default=__file__,

src/eightebed/context.py

 
 notset = object()
 isset = object()
+
+
 class Context(dict):
     """
     >>> d = Context({ 'a': 2, 'b': 3 })
             return self[name]
         if self.parent is None:
             if default is notset:
-                raise KeyError, name
+                raise KeyError(name)
             return default
         return self.parent.lookup(name, default=default)
 
     def declare(self, name, value):
         if self.lookup(name, default=isset) is not isset:
-            raise KeyError, "%s already declared" % name
+            raise KeyError("%s already declared" % name)
         self[name] = value
 
     def empty(self):

src/eightebed/drivers.py

     if options.verbose:
         sys.stdout.write(output)
     if output != '':
-        raise RuntimeError, "Compilation failed!"
+        raise RuntimeError("Compilation failed!")
     if options.run:
         logger.info("Running...")
         output = Popen(["./a.out"], stdout=PIPE).communicate()[0]
 
 def load_and_go(ast, options=None):
     class LoadAndGoOptions(object):
-        verbose=False
-        run=True
-        clean=True
-        compiler="gcc"
-        pedigree=__file__ + ":load_and_go"
-        trace_marking=False
-        pointer_format="$%08lx"
+        verbose = False
+        run = True
+        clean = True
+        compiler = "gcc"
+        pedigree = __file__ + ":load_and_go"
+        trace_marking = False
+        pointer_format = "$%08lx"
     options = options or LoadAndGoOptions()
     file = open("tmp.c", "w")
     ast.emit(file, options)
     options.run = True
     options.clean = True
     while True:
-        sys.stdout.write("> ");
+        sys.stdout.write("> ")
         cmd = sys.stdin.readline().strip()
         if cmd == "quit":
             break

src/eightebed/parser.py

         self.typedecls = data[0]
         self.vardecls = data[1]
         self.block = data[2]
+
     def __repr__(self):
-        return "%s(%s, %s, %s)" % (self.__class__.__name__, repr(self.typedecls), repr(self.vardecls), repr(self.block))
+        return "%s(%s, %s, %s)" % (
+            self.__class__.__name__,
+            repr(self.typedecls), repr(self.vardecls), repr(self.block)
+        )
+
     def typecheck(self, types, vars):
         for typedecl in self.typedecls:
             typedecl.typecheck(types, vars)
         for vardecl in self.vardecls:
             vardecl.typecheck(types, vars)
         self.block.typecheck(types, vars)
+
     def vanalyze(self, context):
         self.block.vanalyze(context)
+
     def emit(self, stream, options):
         stream.write("""\
 /* Achtung!  This Source was Automatically Generated by %s! */
 class Block(object):
     def __init__(self, data):
         self.stmts = data[1]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.stmts))
+
     def typecheck(self, types, vars):
         block_types = Context(parent=types)
         block_vars = Context(parent=vars)
         for stmt in self.stmts:
             stmt.typecheck(block_types, block_vars)
+
     def vanalyze(self, context):
         for stmt in self.stmts:
             stmt.vanalyze(context)
+
     def emit(self, stream):
         for stmt in self.stmts:
             stmt.emit(stream)
 
+
 class TypeDecl(object):
     def __init__(self, data):
         self.name = data[1]
         self.type = data[2]
+
     def __repr__(self):
         return "TypeDecl(%s, %s)" % (repr(self.name), repr(self.type))
+
     def typecheck(self, types, vars):
         types.declare(self.name, self.type)
         self.type.typecheck(types, vars)
         if not isinstance(self.type, TypeStruct):
-            raise TypeError, "Only structs may be named"
+            raise TypeError("Only structs may be named")
         return self.type
+
     def emit(self, stream, options):
         if isinstance(self.type, TypeStruct):
             stream.write("typedef \n")
             stream.write(" %s;\n" % self.name)
             self.type.emit(stream)
             stream.write(";\n")
-            stream.write("static void mark_%s(_ptr outcast, %s* p) {" % (self.name, self.name))
-            marking_text = options.pointer_format + (" @%s " % self.name) + options.pointer_format
+            stream.write("static void mark_%s(_ptr outcast, %s* p) {" %
+                         (self.name, self.name))
+            marking_text = (options.pointer_format + (" @%s " % self.name) +
+                            options.pointer_format)
             stream.write(r"""
 #ifdef TRACE_MARKING
 fprintf(stderr, "-> BEGIN marking %s\n", (long)outcast.p, (long)p);
 
 # These classes double as AST components and as type expressions.
 
+
 class Type(object):
     def equiv(self, other):
         raise NotImplementedError
+
     def points_to(self):
         return None
+
     def resolve(self, types):
         return self
+
     def get_member_type(self, name):
         return None
 
+
 class TypeVoid(Type):
     def __init__(self, data=None):
         pass
+
     def equiv(self, other):
         return isinstance(other, TypeVoid)
+
     def emit(self, stream):
         stream.write("void")
 
+
 class TypeInt(Type):
     def __init__(self, data=None):
         pass
+
     def __repr__(self):
         return "%s()" % (self.__class__.__name__)
+
     def typecheck(self, types, vars):
         return self
+
     def equiv(self, other):
         return isinstance(other, TypeInt)
+
     def emit(self, stream):
         stream.write("int")
 
+
 struct_id = 0
+
+
 class TypeStruct(Type):
     def __init__(self, data):
         global struct_id
         self.members = data[2]
         self.id = struct_id
         struct_id += 1
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.members))
+
     def typecheck(self, types, vars):
         for member in self.members:
             type_ = member.typecheck(types, vars)
             if isinstance(type_, TypeStruct):
-                raise TypeError, "Structs may not contain other structs"
+                raise TypeError("Structs may not contain other structs")
         return self
+
     def equiv(self, other):
         return False
+
     def emit(self, stream):
         stream.write("struct s_%s {\n" % self.id)
         for member in self.members:
             member.emit(stream)
         stream.write("}")
+
     def emit_forward(self, stream):
         stream.write("struct s_%s" % self.id)
+
     def get_member_type(self, name):
         for decl in self.members:
             if decl.name == name:
                 return decl.type
         return None
 
+
 class TypePtr(Type):
     def __init__(self, data):
         self.target = data[2]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.target))
+
     def typecheck(self, types, vars):
         self.target.typecheck(types, vars)
         if isinstance(self.target, TypeNamed):
             return self
         else:
-            raise TypeError, "Pointer type must point to named type"
+            raise TypeError("Pointer type must point to named type")
+
     def equiv(self, other):
         return isinstance(other, TypePtr) and self.target.equiv(other.target)
+
     def points_to(self):
         return self.target
+
     def emit(self, stream):
         stream.write("/* ")
         self.target.emit(stream)
         stream.write(" */ ")
         stream.write("_ptr")
 
+
 class TypeNamed(Type):
     def __init__(self, data):
         self.name = data
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.name))
+
     def typecheck(self, types, vars):
-        return True # can't look self up yet, might not exist yet
+        return True  # can't look self up yet, might not exist yet
+
     def equiv(self, other):
         return isinstance(other, TypeNamed) and self.name == other.name
+
     def emit(self, stream):
         stream.write(self.name)
+
     def resolve(self, types):
         return types.lookup(self.name)
 
+
 class Decl(object):
     def __init__(self, data):
         self.type = data[0]
         self.name = data[1]
+
     def __repr__(self):
-        return "%s(%s, %s)" % (self.__class__.__name__, repr(self.name), repr(self.type))
+        return "%s(%r, %r)" % (self.__class__.__name__, self.name, self.type)
+
     def typecheck(self, types, vars):
         self.type.typecheck(types, vars)
         return self.type
+
     def emit(self, stream):
         self.type.emit(stream)
         stream.write(" %s;\n" % self.name)
 
+
 class VarDecl(object):
     def __init__(self, data):
         decl = data[1]
         self.type = decl.type
         self.name = decl.name
+
     def __repr__(self):
         return "%s(%s, %s)" % (self.__class__.__name__, repr(self.name), repr(self.type))
+
     def typecheck(self, types, vars):
         self.type.typecheck(types, vars)
         vars.declare(self.name, self.type)
         return self.type
+
     def emit(self, stream):
         self.type.emit(stream)
         stream.write(" %s;\n" % self.name)
+
     def emit_marker(self, stream):
         if isinstance(self.type, TypePtr):
             stream.write("""
             self.type.points_to().emit(stream)
             stream.write(" *)%s.p);\n  }\n" % self.name)
 
+
 class WhileStmt(object):
     def __init__(self, data):
         self.expr = data[1]
         self.block = data[2]
+
     def __repr__(self):
         return "%s(%s, %s)" % (self.__class__.__name__, repr(self.expr), repr(self.block))
+
     def typecheck(self, types, vars):
         self.expr.typecheck(types, vars)
         self.block.typecheck(types, vars)
         return TypeVoid()
+
     def vanalyze(self, context):
         self.expr.vanalyze(context)
         self.block.vanalyze(context)
+
     def emit(self, stream):
         stream.write("while(")
         self.expr.emit(stream)
         self.block.emit(stream)
         stream.write("}\n")
 
+
 class IfStmt(object):
     def __init__(self, data):
         self.expr = data[1]
             self.else_ = elsepart[0][1]
         else:
             self.else_ = Block(['{', [], '}'])
+
     def __repr__(self):
         return "%s(%s, %s, %s)" % (self.__class__.__name__, repr(self.expr), repr(self.then), repr(self.else_))
+
     def typecheck(self, types, vars):
         self.expr.typecheck(types, vars)
         self.then.typecheck(types, vars)
         self.else_.typecheck(types, vars)
         return TypeVoid()
+
     def vanalyze(self, context):
         self.expr.vanalyze(context)
         # If the test expr is exactly "valid x", put x into context,
                 subcontext[self.expr.expr.name] = True
         self.then.vanalyze(subcontext)
         self.else_.vanalyze(context)
+
     def emit(self, stream):
         stream.write("if(")
         self.expr.emit(stream)
         self.else_.emit(stream)
         stream.write("}\n")
 
+
 class FreeStmt(object):
     def __init__(self, data):
         self.ref = data[1]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.ref))
+
     def typecheck(self, types, vars):
         ref_type = self.ref.typecheck(types, vars)
         if ref_type.points_to() is None:
-            raise TypeError, "%s is not a pointer type" % repr(ref_type)
+            raise TypeError("%r is not a pointer type" % ref_type)
         return TypeVoid()
+
     def vanalyze(self, context):
         self.ref.vanalyze(context)
         # End safe area -- remove all assertions of validity hereafter.
         context.empty()
+
     def emit(self, stream):
         stream.write("_8ebed_free(&")
         self.ref.emit(stream)
         stream.write(");\n")
 
+
 class PrintStmt(object):
     def __init__(self, data):
         self.expr = data[1]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.expr))
+
     def typecheck(self, types, vars):
         expr_type = self.expr.typecheck(types, vars)
         if not expr_type.equiv(TypeInt()):
-            raise TypeError, "%s is not an int" % repr(expr_type)
+            raise TypeError("%r is not an int" % expr_type)
         return TypeVoid()
+
     def vanalyze(self, context):
         self.expr.vanalyze(context)
+
     def emit(self, stream):
         stream.write("printf(\"%d \", ")
         self.expr.emit(stream)
         stream.write(");\n")
 
+
 class AssignStmt(object):
     def __init__(self, data):
         self.ref = data[0]
         self.expr = data[2]
+
     def __repr__(self):
         return "%s(%s, %s)" % (self.__class__.__name__, repr(self.ref), repr(self.expr))
+
     def typecheck(self, types, vars):
         tlhs = self.ref.typecheck(types, vars)
         trhs = self.expr.typecheck(types, vars)
         if trhs.equiv(tlhs):
             return TypeVoid()
         else:
-            raise TypeError, "%s (%s) not equivalent to %s (%s) for vars %s" % (repr(tlhs), repr(self.ref), repr(trhs), repr(self.expr), vars)
+            raise TypeError("%r (%r) not equivalent to %r (%r) for vars %s" %
+                            (tlhs, self.ref, trhs, self.expr, vars))
+
     def vanalyze(self, context):
         self.ref.vanalyze(context)
         self.expr.vanalyze(context)
         # End safe area -- remove all assertions of validity hereafter.
         context.empty()
+
     def emit(self, stream):
         self.ref.emit(stream)
         stream.write(" = ")
         self.expr.emit(stream)
         stream.write(";\n")
 
+
 class BinOpExpr(object):
     map = {
-        '+' : '+',
-        '-' : '-',
-        '*' : '*',
-        '/' : '/',
-        '=' : '==',
-        '>' : '>',
-        '&' : '&&',
-        '|' : '||',
+        '+': '+',
+        '-': '-',
+        '*': '*',
+        '/': '/',
+        '=': '==',
+        '>': '>',
+        '&': '&&',
+        '|': '||',
     }
+
     def __init__(self, data):
         self.lhs = data[1]
         self.op = data[2]
         self.rhs = data[3]
+
     def __repr__(self):
         return "%s(%s, %s, %s)" % (self.__class__.__name__, repr(self.lhs), repr(self.op), repr(self.rhs))
+
     def typecheck(self, types, vars):
         trhs = self.lhs.typecheck(types, vars)
         tlhs = self.rhs.typecheck(types, vars)
         if not tlhs.equiv(TypeInt()):
-            raise TypeError, "lhs %s is not an int" % repr(tlhs)
+            raise TypeError("lhs %r is not an int" % tlhs)
         if not trhs.equiv(TypeInt()):
-            raise TypeError, "rhs %s is not an int" % repr(trhs)
+            raise TypeError("rhs %r is not an int" % trhs)
         return TypeInt()
+
     def vanalyze(self, context):
         self.lhs.vanalyze(context)
         self.rhs.vanalyze(context)
+
     def emit(self, stream):
         stream.write("(")
         self.lhs.emit(stream)
         self.rhs.emit(stream)
         stream.write(")")
 
+
 class MallocExpr(object):
     def __init__(self, data):
         self.type = data[1]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.type))
+
     def typecheck(self, types, vars):
         return TypePtr(['', '', self.type])
+
     def vanalyze(self, context):
         pass
+
     def emit(self, stream):
         stream.write("_8ebed_malloc(sizeof(")
         self.type.emit(stream)
         stream.write("))")
 
+
 class ValidExpr(object):
     def __init__(self, data):
         self.expr = data[1]
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.expr))
+
     def typecheck(self, types, vars):
         expr_type = self.expr.typecheck(types, vars)
         if expr_type.points_to() is None:
-            raise TypeError, "%s is not a pointer type" % repr(expr_type)
+            raise TypeError("%r is not a pointer type" % expr_type)
         return TypeInt()
+
     def vanalyze(self, context):
         self.expr.vanalyze(context)
+
     def emit(self, stream):
         stream.write("_8ebed_valid(")
         self.expr.emit(stream)
         stream.write(")")
 
+
 class DottedRef(object):
     def __init__(self, data):
         self.source = data[1]
         self.member_name = data[4]
+
     def __repr__(self):
         return "%s(%s, %s)" % (self.__class__.__name__, repr(self.source), repr(self.member_name))
+
     def typecheck(self, types, vars):
         source_type = self.source.typecheck(types, vars)
         source_type = source_type.resolve(types)
         member_type = source_type.get_member_type(self.member_name)
         if member_type is None:
-            raise TypeError, "%s does not have member %s" % (repr(source_type), self.member_name)
+            raise TypeError("%r does not have member %s" %
+                            (source_type, self.member_name))
         return member_type
+
     def vanalyze(self, context, deref=False):
         self.source.vanalyze(context, deref=deref)
+
     def emit(self, stream):
         self.source.emit(stream)
         stream.write(".%s" % self.member_name)
 
+
 class DeRef(object):
     def __init__(self, data):
         self.source = data[1]
         self._dest_type = None
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.source))
+
     def typecheck(self, types, vars):
         source_type = self.source.typecheck(types, vars)
         dest_type = source_type.points_to()
         if dest_type is None:
-            raise TypeError, "%s is not a pointer type" % repr(source_type)
+            raise TypeError("%r is not a pointer type" % source_type)
         self._dest_type = dest_type
         return dest_type
+
     def vanalyze(self, context, deref=False):
         self.source.vanalyze(context, deref=True)
+
     def emit(self, stream):
         stream.write("(*(")
         self._dest_type.emit(stream)
         self.source.emit(stream)
         stream.write(".p)")
 
+
 class VarRef(object):
     def __init__(self, data):
         self.name = data
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.name))
+
     def typecheck(self, types, vars):
         #if self.name == 'i':
         #    raise NotImplementedError, vars.lookup(self.name)
         return vars.lookup(self.name)
+
     def vanalyze(self, context, deref=False):
         if deref:
             if not context.lookup(self.name, default=False):
-                raise TypeError, "Attempt to dereference %s in non-safe context" % self.name
+                raise TypeError("Attempt to dereference %s "
+                                "in non-safe context" % self.name)
+
     def emit(self, stream):
         stream.write(self.name)
 
+
 class IntConst(object):
     def __init__(self, data):
         self.value = int(data)
+
     def __repr__(self):
         return "%s(%s)" % (self.__class__.__name__, repr(self.value))
+
     def typecheck(self, types, vars):
         return TypeInt()
+
     def vanalyze(self, context, deref=False):
         pass
+
     def emit(self, stream):
         stream.write(str(self.value))
 
                             Sequence(Terminal('valid'), NonTerminal('Expr')).construct(ValidExpr),
                             NonTerminal('IntLit').construct(IntConst),
                             NonTerminal('Ref'))
-g['BinOp']    = Alternation(Terminal('+'),Terminal('-'),Terminal('*'),Terminal('/'),Terminal('='),Terminal('>'),Terminal('&'), Terminal('|'))
+g['BinOp']    = Alternation(Terminal('+'), Terminal('-'), Terminal('*'),
+                            Terminal('/'), Terminal('='), Terminal('>'),
+                            Terminal('&'), Terminal('|'))
 
 g['TypeName'] = Terminal(lambda x: re.match('^[a-zA-Z]\w*$', x))
 g['VarName']  = Terminal(lambda x: re.match('^[a-zA-Z]\w*$', x))
     s = Stream(r(text))
     return g.parse('Eightebed', s)
 
+
 def parse_file(filename):
     f = open(filename, "r")
     contents = f.read()

src/eightebed/rooibos.py

 import re
 import types
 
+
 class Stream(object):
     """
     A Stream is a kind of wrapper around an iterator which allows
 
 class RegLexer(object):
     """
-    An iterator which, given a string, returns a generator which returns sucessive
-    prefixes of the string based on supplied regexes.
+    An iterator which, given a string, returns a generator which returns
+    sucessive prefixes of the string based on supplied regexes.
 
     >>> t = RegLexer()
     >>> t.register(r'(\d+)',   meta='integer')
         has_match = True
         while has_match:
             has_match = False
-            
+
             has_ignore = True
             while has_ignore:
                 has_ignore = False
             if x(other):
                 return True
         return False
-    
+
     def __iter__(self):
         for x in self._set:
             yield x
 
     def _production(self, grammar):
         if not grammar:
-            raise TypeError, "need grammar to use NonTerminal"
+            raise TypeError("need grammar to use NonTerminal")
         return grammar[self.name]
 
     def parse(self, stream, grammar=None):
     """Container for a set of named productions.
 
     >>> g = Grammar()
-    >>> g['Expr'] = Sequence(Terminal('('),Asteration(Terminal('*')),Terminal(')'))
+    >>> g['Expr'] = Sequence(Terminal('('),Asteration(Terminal('*')),
+    ...                      Terminal(')'))
     >>> g.parse('Expr', Stream(['(','*','*',')']))
     ['(', ['*', '*'], ')']
-    >>> g['Expr'] = Sequence(Terminal('('),Asteration(NonTerminal('Expr')),Terminal(')'))
+    >>> g['Expr'] = Sequence(Terminal('('),Asteration(NonTerminal('Expr')),
+    ...                      Terminal(')'))
     >>> g.parse('Expr', Stream(['(',')']))
     ['(', [], ')']
     >>> s = Stream(['(','(',')',')'])
     >>> g.parse('Expr', Stream(['(','(',')'])) is None
     True
     """
-    
+
     trace = False
 
     def __init__(self, parent=None):
         elif self.parent:
             return self.parent[key]
         else:
-            raise KeyError, "No production '%s' in grammar, and no parent grammar" % key
+            raise KeyError("No production '%s' in grammar, "
+                           "and no parent grammar" % key)
 
     def __setitem__(self, key, value):
         self.productions[key] = value
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.