@@ -25,75 +25,20 @@ def code2parts(code):
2525 print ('evaluating expr ..' )
2626 print (eval (expr ))
2727
28- from collections import defaultdict
29-
3028d = {}
3129
32- """
33- here's the new plan for python's eval
34-
35- Python's module is closely bound to the file system, so it is not possible to use that.
36-
37- I have to use my own globals and locals during exec/eval.
38-
39- Then, I'll just record the calling relationships for the modules. When evaluating, I'll:
40-
41- 1. eval_func(code, nses)
42- - nses is a list of namespaces in order, the last one is this ns
43- - that should be it. The question is where to compute nses. I would
44- 1. compute it when powerRunTree
45- 2. let the kernel knows it by using CODEPOD_ADD_IMPORT. The kernel will record this.
46- """
47-
48- # from ns to nses that should imported
49- import_d = defaultdict (set )
50- # from ns to exported names
51- export_d = defaultdict (set )
52- # from ns to subdeck nses
53- export_sub_d = defaultdict (set )
54- # to=>[from=>names]
55- reexport_d = defaultdict (lambda : defaultdict (set ))
56-
5730def CODEPOD_GETMOD (ns ):
5831 if ns not in d :
5932 d [ns ] = types .ModuleType (ns )
6033 d [ns ].__dict__ ["CODEPOD_GETMOD" ] = CODEPOD_GETMOD
6134 return d [ns ]
6235
63- def merge_dicts (dicts ):
64- """
65- Given any number of dictionaries, shallow copy and merge into a new dict,
66- precedence goes to key-value pairs in latter dictionaries.
67- """
68- result = {}
69- for dictionary in dicts :
70- result .update (dictionary )
71- return result
72-
73- def CODEPOD_ADD_IMPORT (FROM , TO ):
74- import_d [TO ].add (FROM )
75- def CODEPOD_REMOVE_IMPORT (FROM , TO ):
76- if FROM in import_d [TO ]:
77- import_d [TO ].remove (FROM )
78- def CODEPOD_SET_EXPORT (ns , exports ):
79- export_d [ns ] = exports
80- def CODEPOD_SET_EXPORT_SUB (ns , nses ):
81- export_sub_d [ns ] = nses
82- def CODEPOD_ADD_REEXPORT (from_ns , to_ns , names ):
83- reexport_d [to_ns ][from_ns ].update (names )
84-
8536def CODEPOD_EVAL (code , ns ):
8637 # the codepod(code) is the program sent to backend
8738 # codepod is defined on the kernel
8839 mod = CODEPOD_GETMOD (ns )
8940 [stmt , expr ] = code2parts (code )
90-
91- # _dict = merge_dicts([{k:v for k,v in CODEPOD_GETMOD(x).__dict__.items() if k in export_d[x]} for x in import_d[ns]])
92- # for from_ns, names in reexport_d[ns].items():
93- # for name in names:
94- # v = CODEPOD_GETMOD(from_ns).__dict__.get(name, None)
95- # if v:
96- # _dict[name] = v
41+
9742 if stmt :
9843 exec (stmt , mod .__dict__ )
9944 if expr :
0 commit comments