Commits

Jürgen Bömmels committed 608107b

Factor out context creation from execution.py,
solves some problems with cyclic imports

  • Participants
  • Parent commits 62a632e

Comments (0)

Files changed (2)

scheme/execution.py

+
 import scheme.object as ssobject
-import scheme.syntax as syntax
-import scheme.procedure as procedure
 import scheme.macro as macro
-from scheme.ssparser import parse
+
 import py
 
 class Location(object):
     def __init__(self, w_obj=None):
         self.obj = w_obj
 
-OPERATION_MAP = {}
-for mod in (ssobject, syntax, procedure, macro):
-    for obj_name in dir(mod):
-        obj = getattr(mod, obj_name)
-        try:
-            issubclass(obj, ssobject.W_Callable)
-            OPERATION_MAP[obj._symbol_name] = obj(obj._symbol_name)
-        except (TypeError, AttributeError):
-            pass
-
-de_file = py.path.local(__file__).dirpath().join("r5rs_derived_expr.ss")
-de_code = de_file.read()
-de_expr_lst = parse(de_code)
-
 class ExecutionContext(object):
     """Execution context implemented as a dict.
 
             self.cont_stack = cont_stack
 
         if globalscope is None:
+            from scheme.systemcontext import _sys_dict, de_expr_lst
             self.globalscope = {}
-            for name, oper in OPERATION_MAP.items():
+            for name, oper in _sys_dict.items():
                 self.globalscope[name] = Location(oper)
 
             for expr in de_expr_lst:

scheme/systemcontext.py

+
+import scheme.object as ssobject
+import scheme.syntax as syntax
+import scheme.procedure as procedure
+import scheme.macro as macro
+from scheme.ssparser import parse
+
+
+from scheme.execution import ExecutionContext, Location
+
+import py
+
+_sys_dict = {}
+for mod in (ssobject, syntax, procedure, macro):
+    for obj_name in dir(mod):
+        obj = getattr(mod, obj_name)
+        try:
+            issubclass(obj, ssobject.W_Callable)
+            name = obj._symbol_name
+            _sys_dict[name] = obj(name)
+        except (TypeError, AttributeError):
+            pass
+
+de_file = py.path.local(__file__).dirpath().join("r5rs_derived_expr.ss")
+de_code = de_file.read()
+de_expr_lst = parse(de_code)
+
+_sys_ctx = ExecutionContext(globalscope = _sys_dict)
+
+#for expr in de_expr_lst:
+#    expr.eval(_sys_ctx)