mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-25 23:49:17 +00:00
Serialize main first. However, this could use a fresh approach.
This commit is contained in:
parent
9c68b6a7e0
commit
7fa54f53cb
@ -64,12 +64,22 @@ class FallthruAnalyzer(object):
|
||||
self.fall_in_map = new_fall_in_map
|
||||
|
||||
def serialize(self):
|
||||
# NOTE, we can probably do this completely differently;
|
||||
# construct the fall_out map
|
||||
# construct fall_out chains
|
||||
# sort these by length
|
||||
# do the longest ones first
|
||||
|
||||
pending_routines = sorted(self.fall_in_map.keys())
|
||||
routine_names = sorted([routine.name for routine in self.program.routines])
|
||||
for routine_name in routine_names:
|
||||
if routine_name not in pending_routines:
|
||||
pending_routines.append(routine_name)
|
||||
|
||||
# make sure `main` appears first, whatever else may be the case.
|
||||
pending_routines.remove('main')
|
||||
pending_routines = ['main'] + pending_routines
|
||||
|
||||
roster = []
|
||||
while pending_routines:
|
||||
# Pick a routine that is still pending to be serialized.
|
||||
|
@ -104,6 +104,9 @@ If main does a `goto foo`, then it can fall through to `foo`.
|
||||
More than one routine can fall through to a routine. We pick one
|
||||
of them to fall through, when selecting the order of routines.
|
||||
|
||||
Also note, `main` is always serialized first, so that the entry
|
||||
point of the entire program appears at the beginning of the code.
|
||||
|
||||
| define foo routine trashes a, z, n
|
||||
| {
|
||||
| ld a, 0
|
||||
@ -128,11 +131,11 @@ of them to fall through, when selecting the order of routines.
|
||||
= *** serialization:
|
||||
= [
|
||||
= [
|
||||
= "bar",
|
||||
= "foo"
|
||||
= "main"
|
||||
= ],
|
||||
= [
|
||||
= "main"
|
||||
= "bar",
|
||||
= "foo"
|
||||
= ]
|
||||
= ]
|
||||
|
||||
@ -177,11 +180,11 @@ fall through to the other.
|
||||
= *** serialization:
|
||||
= [
|
||||
= [
|
||||
= "foo",
|
||||
= "bar"
|
||||
= "main"
|
||||
= ],
|
||||
= [
|
||||
= "main"
|
||||
= "foo",
|
||||
= "bar"
|
||||
= ]
|
||||
= ]
|
||||
|
||||
@ -211,13 +214,13 @@ routine.
|
||||
= *** serialization:
|
||||
= [
|
||||
= [
|
||||
= "main"
|
||||
= ],
|
||||
= [
|
||||
= "bar"
|
||||
= ],
|
||||
= [
|
||||
= "foo"
|
||||
= ],
|
||||
= [
|
||||
= "main"
|
||||
= ]
|
||||
= ]
|
||||
|
||||
@ -246,12 +249,12 @@ because we don't necessarily know what actual routine the vector contains.
|
||||
= *** serialization:
|
||||
= [
|
||||
= [
|
||||
= "main"
|
||||
= ],
|
||||
= [
|
||||
= "bar"
|
||||
= ],
|
||||
= [
|
||||
= "foo"
|
||||
= ],
|
||||
= [
|
||||
= "main"
|
||||
= ]
|
||||
= ]
|
||||
|
Loading…
Reference in New Issue
Block a user