git @ Cat's Eye Technologies SixtyPical / 7fa54f5
Serialize main first. However, this could use a fresh approach. Chris Pressey 3 years ago
2 changed file(s) with 35 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
6363 self.fall_in_map = new_fall_in_map
6464
6565 def serialize(self):
66 # NOTE, we can probably do this completely differently;
67 # construct the fall_out map
68 # construct fall_out chains
69 # sort these by length
70 # do the longest ones first
71
6672 pending_routines = sorted(self.fall_in_map.keys())
6773 routine_names = sorted([routine.name for routine in self.program.routines])
6874 for routine_name in routine_names:
6975 if routine_name not in pending_routines:
7076 pending_routines.append(routine_name)
77
78 # make sure `main` appears first, whatever else may be the case.
79 pending_routines.remove('main')
80 pending_routines = ['main'] + pending_routines
7181
7282 roster = []
7383 while pending_routines:
103103 More than one routine can fall through to a routine. We pick one
104104 of them to fall through, when selecting the order of routines.
105105
106 Also note, `main` is always serialized first, so that the entry
107 point of the entire program appears at the beginning of the code.
108
106109 | define foo routine trashes a, z, n
107110 | {
108111 | ld a, 0
127130 = *** serialization:
128131 = [
129132 = [
133 = "main"
134 = ],
135 = [
130136 = "bar",
131137 = "foo"
132 = ],
133 = [
134 = "main"
135138 = ]
136139 = ]
137140
176179 = *** serialization:
177180 = [
178181 = [
182 = "main"
183 = ],
184 = [
179185 = "foo",
180186 = "bar"
181 = ],
182 = [
183 = "main"
184187 = ]
185188 = ]
186189
210213 = *** serialization:
211214 = [
212215 = [
213 = "bar"
214 = ],
215 = [
216 = "foo"
217 = ],
218 = [
219 = "main"
216 = "main"
217 = ],
218 = [
219 = "bar"
220 = ],
221 = [
222 = "foo"
220223 = ]
221224 = ]
222225
245248 = *** serialization:
246249 = [
247250 = [
248 = "bar"
249 = ],
250 = [
251 = "foo"
252 = ],
253 = [
254 = "main"
255 = ]
256 = ]
251 = "main"
252 = ],
253 = [
254 = "bar"
255 = ],
256 = [
257 = "foo"
258 = ]
259 = ]