Carl Friedrich Bolz avatar Carl Friedrich Bolz committed 2580111

use a linked list

Comments (0)

Files changed (1)

 
 
 class Continuation(object):
-    pass
+    def __init__(self, next):
+        self.next = next
 
 class Eval(Continuation):
-    def __init__(self, w_obj):
+    def __init__(self, next, w_obj):
+        Continuation.__init__(self, next)
         self.w_obj = w_obj
 
-    def execute(self, todo, building):
-        w_obj = self.w_obj.evaluate_hnf()
-        if isinstance(w_obj, Constructor):
-            if w_obj.args:
-                todo.append(Build(w_obj.name, len(w_obj.args)))
-                for i in range(len(w_obj.args) - 1, -1, -1):
-                    todo.append(Eval(w_obj.args[i]))
-            else:
-                building.append(w_obj)
+    def execute(self, building):
+        todo = self.next
+        function = None
+        w_obj = self.w_obj
+        w_obj = w_obj.evaluate_hnf()
+        if isinstance(w_obj, Constructor) and w_obj.args:
+            todo = Build(todo, w_obj.name, len(w_obj.args))
+            for i in range(len(w_obj.args) - 1, -1, -1):
+                todo = Eval(todo, w_obj.args[i])
         else:
             building.append(w_obj)
+        return todo
 
 class Build(Continuation):
-    def __init__(self, name, num_args):
+    def __init__(self, next, name, num_args):
+        Continuation.__init__(self, next)
         self.name = name
         self.num_args = num_args
 
-    def execute(self, todo, building):
+    def execute(self, building):
         args = [building.pop() for i in range(self.num_args)]
         args.reverse()
         building.append(Constructor(self.name, args))
+        return self.next
 
 def evaluate_normal_form(w_obj):
-    todo = [Eval(w_obj)]
+    todo = Eval(None, w_obj)
     building = []
-    while todo:
-        next = todo.pop()
-        next.execute(todo, building)
+    while todo is not None:
+        todo = todo.execute(building)
     assert len(building) == 1
     return building[0]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.