Commit 5e19cbac authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Code.py: Make a wall between non-managed and managed temps

parent 41c28bcd
...@@ -41,8 +41,8 @@ class FunctionState(object): ...@@ -41,8 +41,8 @@ class FunctionState(object):
self.exc_vars = None self.exc_vars = None
self.temps_allocated = [] # of (name, type, manage_ref) self.temps_allocated = [] # of (name, type, manage_ref)
self.temps_free = {} # type -> list of free vars self.temps_free = {} # (type, manage_ref) -> list of free vars with same type/managed status
self.temps_used_type = {} # name -> type self.temps_used_type = {} # name -> (type, manage_ref)
self.temp_counter = 0 self.temp_counter = 0
def new_label(self, name=None): def new_label(self, name=None):
...@@ -117,7 +117,10 @@ class FunctionState(object): ...@@ -117,7 +117,10 @@ class FunctionState(object):
A C string referring to the variable is returned. A C string referring to the variable is returned.
""" """
freelist = self.temps_free.get(type) if not type.is_pyobject and manage_ref is not True:
# Make manage_ref canonical for temps_free lookup purposes
raise ValueError("manage_ref only applicable when type.is_pyobject")
freelist = self.temps_free.get((type, manage_ref))
if freelist is not None and len(freelist) > 0: if freelist is not None and len(freelist) > 0:
result = freelist.pop() result = freelist.pop()
else: else:
...@@ -126,7 +129,7 @@ class FunctionState(object): ...@@ -126,7 +129,7 @@ class FunctionState(object):
result = "%s%d" % (Naming.codewriter_temp_prefix, self.temp_counter) result = "%s%d" % (Naming.codewriter_temp_prefix, self.temp_counter)
if not result in self.names_taken: break if not result in self.names_taken: break
self.temps_allocated.append((result, type, manage_ref)) self.temps_allocated.append((result, type, manage_ref))
self.temps_used_type[result] = type self.temps_used_type[result] = (type, manage_ref)
return result return result
def release_temp(self, name): def release_temp(self, name):
...@@ -134,12 +137,12 @@ class FunctionState(object): ...@@ -134,12 +137,12 @@ class FunctionState(object):
Releases a temporary so that it can be reused by other code needing Releases a temporary so that it can be reused by other code needing
a temp of the same type. a temp of the same type.
""" """
type = self.temps_used_type[name] type, manage_ref = self.temps_used_type[name]
freelist = self.temps_free.get(type) freelist = self.temps_free.get((type, manage_ref))
if freelist is None: if freelist is None:
freelist = [] freelist = []
self.temps_free[type] = freelist self.temps_free[(type, manage_ref)] = freelist
freelist.append(name) freelist.append(name)
def temps_in_use(self): def temps_in_use(self):
...@@ -148,7 +151,7 @@ class FunctionState(object): ...@@ -148,7 +151,7 @@ class FunctionState(object):
""" """
used = [] used = []
for name, type, manage_ref in self.temps_allocated: for name, type, manage_ref in self.temps_allocated:
freelist = self.temps_free.get(type) freelist = self.temps_free.get((type, manage_ref))
if freelist is None or name not in freelist: if freelist is None or name not in freelist:
used.append((name, type, manage_ref)) used.append((name, type, manage_ref))
return used return used
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment