slightly optimized the most called function

This commit is contained in:
Irmen de Jong 2018-02-16 13:59:18 +01:00
parent daca1cce37
commit 191978c8fb
3 changed files with 21 additions and 11 deletions

View File

@ -2,9 +2,6 @@
class CodeGenerator: class CodeGenerator:
BREAKPOINT_COMMENT_SIGNATURE = "~~~BREAKPOINT~~~"
BREAKPOINT_COMMENT_DETECTOR = r".(?P<address>\w+)\s+ea\s+nop\s+;\s+{:s}.*".format(BREAKPOINT_COMMENT_SIGNATURE)
def generate_call(self, stmt: CallStmt) -> None: def generate_call(self, stmt: CallStmt) -> None:
self.p("\t\t\t\t\t; " + stmt.lineref) self.p("\t\t\t\t\t; " + stmt.lineref)
if stmt.condition: if stmt.condition:

View File

@ -87,17 +87,18 @@ class AstNode:
raise LookupError("no scope found in node ancestry", self) raise LookupError("no scope found in node ancestry", self)
def all_nodes(self, *nodetypes: type) -> Generator['AstNode', None, None]: def all_nodes(self, *nodetypes: type) -> Generator['AstNode', None, None]:
nodetypes = nodetypes or (AstNode, ) if not self.nodes:
if self.nodes is None: # this is the case when a node has been pruned away (nodes=None) or we don't have any child nodes
# this is the case when a node has been pruned away
return return
child_nodes = list(self.nodes) child_nodes = list(self.nodes)
if nodetypes:
for node in child_nodes:
if isinstance(node, nodetypes):
yield node
else:
yield from child_nodes
for node in child_nodes: for node in child_nodes:
if isinstance(node, nodetypes): yield from node.all_nodes(*nodetypes)
yield node
for node in child_nodes:
if isinstance(node, AstNode):
yield from node.all_nodes(*nodetypes)
def remove_node(self, node: 'AstNode') -> None: def remove_node(self, node: 'AstNode') -> None:
assert node.parent is self assert node.parent is self

12
run_profile.py Normal file
View File

@ -0,0 +1,12 @@
import cProfile
from il65.compile import PlyParser
from il65.optimize import optimize
def parse():
parser = PlyParser(enable_floats=True)
parsed_module = parser.parse_file("testsource/large.ill")
optimize(parsed_module)
cProfile.run("parse()", filename="profile.dat")