aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2022-07-20 02:53:42 +0000
committermryouse2022-07-20 02:53:42 +0000
commiteb021d2ea4227dd06a4e4b39c2be333f94d210f8 (patch)
tree0e8d0e49b06c671c484a43bcb4ef6a574d21721e
parent8a3642042e75294707e543135767dcdfb85a620a (diff)
WIP combine environments correctly
-rw-r--r--neb.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/neb.py b/neb.py
index 558cdf5..cd60cb8 100644
--- a/neb.py
+++ b/neb.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-from neb import lex, parse, interpret, NebPanic, Environment
+from neb import lex, parse, interpret, NebPanic, Environment, MultiFunction, Builtin, UserFunction
from neb.std import *
import sys
import readline
@@ -17,6 +17,37 @@ class NebCompleter:
def build_std(repl=False):
GLOBALS = Environment()
+
+ envs = [ BOOLEAN.environment,
+ CORE.environment,
+ FUNCTOOLS.environment,
+ FS.environment,
+ LISTS.environment,
+ MATH.environment,
+ STRINGS.environment,
+ SYS.environment,
+ TERM.environment,
+ TYPES.environment ]
+
+ global_dict = {}
+ for env in envs:
+ for key, val in env.items():
+ if key not in global_dict:
+ global_dict[key] = val
+ continue
+ global_item = global_dict[key]
+ if isinstance(global_item, MultiFunction):
+ for i in val.impls.values():
+ global_item.register(i)
+ elif isinstance(global_item, Builtin) or isinstance(global_item, UserFunction):
+ mf = MultiFunction(key)
+ mf.register(global_item)
+ mf.register(val)
+ global_dict[key] = mf
+ else:
+ raise NebPanic("bad environment juju")
+
+ '''
global_dict = { **BOOLEAN.environment,
**CORE.environment,
**FUNCTOOLS.environment,
@@ -27,9 +58,17 @@ def build_std(repl=False):
**SYS.environment,
**TERM.environment,
**TYPES.environment }
+ '''
if repl:
- global_dict = { **global_dict,
- **REPL.environment }
+ for key, val in REPL.environment.items():
+ if key not in global_dict:
+ global_dict[key] = val
+ elif isinstance(global_dict[key], MultiFunction):
+ for i in val.impls:
+ global_dict[key].register(i)
+ else:
+ raise NebPanic("bad environment juju")
+
GLOBALS.environment = global_dict
return GLOBALS