mirror of
https://github.com/michaelcmartin/Ophis.git
synced 2025-01-08 07:30:16 +00:00
Switch to "new-style" classes, because come on.
Ophis was originally written for Python 2.1, and it kind of shows. Python 2.3 introduced booleans and optparse, so there's no reason to not use new-style classes.
This commit is contained in:
parent
1bbb2f1f1b
commit
d955fe00a1
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import Ophis.Errors as Err
|
import Ophis.Errors as Err
|
||||||
|
|
||||||
class Environment:
|
class Environment(object):
|
||||||
"""Environment class.
|
"""Environment class.
|
||||||
Controls the various scopes and global abstract execution variables."""
|
Controls the various scopes and global abstract execution variables."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -13,7 +13,7 @@ import os
|
|||||||
# You may use, modify, and distribute this file under the MIT
|
# You may use, modify, and distribute this file under the MIT
|
||||||
# license: See README for details.
|
# license: See README for details.
|
||||||
|
|
||||||
class Lexeme:
|
class Lexeme(object):
|
||||||
"Class for lexer tokens. Used by lexer and parser."
|
"Class for lexer tokens. Used by lexer and parser."
|
||||||
def __init__(self, type="UNKNOWN", value=None):
|
def __init__(self, type="UNKNOWN", value=None):
|
||||||
self.type = type.upper()
|
self.type = type.upper()
|
||||||
@ -137,7 +137,7 @@ def lex(point, line):
|
|||||||
add_EOL()
|
add_EOL()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class ParseLine:
|
class ParseLine(object):
|
||||||
"Maintains the parse state of a line of code. Enables arbitrary lookahead."
|
"Maintains the parse state of a line of code. Enables arbitrary lookahead."
|
||||||
def __init__(self, lexemes):
|
def __init__(self, lexemes):
|
||||||
self.lexemes = lexemes
|
self.lexemes = lexemes
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import Ophis.Errors as Err
|
import Ophis.Errors as Err
|
||||||
|
|
||||||
class Node:
|
class Node(object):
|
||||||
"""The default IR Node
|
"""The default IR Node
|
||||||
Instances of Node always have the three fields ppt(Program Point),
|
Instances of Node always have the three fields ppt(Program Point),
|
||||||
nodetype(a string), and data (a list)."""
|
nodetype(a string), and data (a list)."""
|
||||||
@ -38,7 +38,7 @@ NullNode = Node("<none>", "None")
|
|||||||
def SequenceNode(ppt, nodelist):
|
def SequenceNode(ppt, nodelist):
|
||||||
return Node(ppt, "SEQUENCE", *nodelist)
|
return Node(ppt, "SEQUENCE", *nodelist)
|
||||||
|
|
||||||
class Expr:
|
class Expr(object):
|
||||||
"""Base class for Ophis expressions
|
"""Base class for Ophis expressions
|
||||||
All expressions have a field called "data" and a boolean field
|
All expressions have a field called "data" and a boolean field
|
||||||
called "hardcoded". An expression is hardcoded if it has no
|
called "hardcoded". An expression is hardcoded if it has no
|
||||||
|
@ -20,7 +20,7 @@ import Ophis.Macro as Macro
|
|||||||
|
|
||||||
# The passes themselves
|
# The passes themselves
|
||||||
|
|
||||||
class Pass:
|
class Pass(object):
|
||||||
"""Superclass for all assembler passes. Automatically handles IR
|
"""Superclass for all assembler passes. Automatically handles IR
|
||||||
types that modify the environent's structure, and by default
|
types that modify the environent's structure, and by default
|
||||||
raises an error on anything else. Override visitUnknown in your
|
raises an error on anything else. Override visitUnknown in your
|
||||||
@ -67,7 +67,7 @@ class Pass:
|
|||||||
print>>sys.stderr, "Current IR:"
|
print>>sys.stderr, "Current IR:"
|
||||||
print>>sys.stderr, node
|
print>>sys.stderr, node
|
||||||
|
|
||||||
class FixPoint:
|
class FixPoint(object):
|
||||||
"""A specialized class that is not a pass but can be run like one.
|
"""A specialized class that is not a pass but can be run like one.
|
||||||
This class takes a list of passes and a "fixpoint" function."""
|
This class takes a list of passes and a "fixpoint" function."""
|
||||||
def __init__(self, name, passes, fixpoint):
|
def __init__(self, name, passes, fixpoint):
|
||||||
|
Loading…
Reference in New Issue
Block a user