[ZPT] CVS: Packages/TAL - TALGenerator.py:1.46
fred@digicool.com
fred@digicool.com
Tue, 12 Jun 2001 23:39:06 -0400 (EDT)
Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv3396
Modified Files:
TALGenerator.py
Log Message:
Add another optimization stage to detect longer sequences in the bytecode.
--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py 2001/06/12 21:58:36 1.45
+++ TALGenerator.py 2001/06/13 03:39:05 1.46
@@ -158,7 +158,7 @@
output.append(self.optimizeArgsList(item))
rawseen = cursor+1
collect = []
- return output
+ return self.optimizeCommonTriple(output)
def optimizeArgsList(self, item):
if len(item) == 2:
@@ -195,6 +195,29 @@
new.append(end)
collect.extend(new)
return opt
+
+ def optimizeCommonTriple(self, program):
+ if len(program) < 3:
+ return program
+ output = program[:2]
+ prev2, prev1 = output
+ for item in program[2:]:
+ if ( item[0] == "beginScope"
+ and prev1[0] == "setPosition"
+ and prev2[0] == "rawtextColumn"):
+ position = output.pop()[1]
+ text, column = output.pop()[1]
+ prev1 = None, None
+ closeprev = 0
+ if output and output[-1][0] == "endScope":
+ closeprev = 1
+ output.pop()
+ item = ("rawtextBeginScope",
+ (text, column, position, closeprev, item[1]))
+ output.append(item)
+ prev2 = prev1
+ prev1 = item
+ return output
def todoPush(self, todo):
self.todoStack.append(todo)