git @ Cat's Eye Technologies SixtyPical / 9c68b6a
Serialize routines with in() sets first, and in the right order. Chris Pressey 3 years ago
2 changed file(s) with 34 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
6363 self.fall_in_map = new_fall_in_map
6464
6565 def serialize(self):
66 self.fall_out_map = {}
67 for key, values in self.fall_in_map.iteritems():
68 for value in values:
69 assert value not in self.fall_out_map
70 self.fall_out_map[value] = key
71 for routine in self.program.routines:
72 if routine.name not in self.fall_out_map:
73 self.fall_out_map[routine.name] = None
66 pending_routines = sorted(self.fall_in_map.keys())
67 routine_names = sorted([routine.name for routine in self.program.routines])
68 for routine_name in routine_names:
69 if routine_name not in pending_routines:
70 pending_routines.append(routine_name)
7471
7572 roster = []
76 pending_routines = copy(self.fall_out_map)
7773 while pending_routines:
7874 # Pick a routine that is still pending to be serialized.
79 key = pending_routines.keys()[0]
75 key = pending_routines[0]
8076
8177 in_set = self.fall_in_map.get(key, [])
8278
8581 chains = find_chains(self.fall_in_map, key, lambda k: k in pending_routines)
8682 chains.sort(key=len, reverse=True)
8783 routines = chains[0]
84 routines.reverse()
8885
8986 # Append (r1,r2,...,rn) to the roster and remove r1,r2,...rn from R.
9087 # A sublist like this appearing in the roster has meaning
9188 # "optimize the final goto out of all but the last routine in the sublist".
9289 for r in routines:
93 del pending_routines[r]
90 pending_routines.remove(r)
9491 roster.append(routines)
9592
9693 return roster
127127 = *** serialization:
128128 = [
129129 = [
130 = "main",
131 = "foo"
132 = ],
133 = [
134 = "bar"
130 = "bar",
131 = "foo"
132 = ],
133 = [
134 = "main"
135135 = ]
136136 = ]
137137
176176 = *** serialization:
177177 = [
178178 = [
179 = "main"
180 = ],
181 = [
182 = "bar",
183 = "foo"
179 = "foo",
180 = "bar"
181 = ],
182 = [
183 = "main"
184184 = ]
185185 = ]
186186
210210 = *** serialization:
211211 = [
212212 = [
213 = "main"
214 = ],
215 = [
216 = "bar"
217 = ],
218 = [
219 = "foo"
213 = "bar"
214 = ],
215 = [
216 = "foo"
217 = ],
218 = [
219 = "main"
220220 = ]
221221 = ]
222222
245245 = *** serialization:
246246 = [
247247 = [
248 = "main"
249 = ],
250 = [
251 = "bar"
252 = ],
253 = [
254 = "foo"
255 = ]
256 = ]
248 = "bar"
249 = ],
250 = [
251 = "foo"
252 = ],
253 = [
254 = "main"
255 = ]
256 = ]