diff options
Diffstat (limited to 'neb/__init__.py')
| -rw-r--r-- | neb/__init__.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/neb/__init__.py b/neb/__init__.py index ab0f836..cf51ed6 100644 --- a/neb/__init__.py +++ b/neb/__init__.py @@ -3,6 +3,7 @@ from .parser import parse from .exceptions import * from .typeclass import TypeEnum, is_subtype_of from .structs import * +from copy import deepcopy def interpret(exprs, env, ns=None): ret = None @@ -46,7 +47,8 @@ class Function: self.body = body self.args = args self.many = many - self.type_ = TypeEnum.ANY # TODO no it's not + #self.type_ = TypeEnum.ANY # TODO no it's not + self.type_ = Type(":any") # TODO no it's not self.return_type = Type(":any") def describe(self, name=None): @@ -82,8 +84,11 @@ class Function: ret.append(param) continue ev = evaluate(param, env, ns) - expected_name = f"{arg.type_}" - expected_type = env.get(expected_name) + #expected_name = f"{arg.type_}" + expected_name = arg.type_.name + expected_type = deepcopy(env.get(expected_name)) + if arg.type_.inner is not None: + expected_type.name.inner = arg.type_.inner valid = expected_type.validate_type(ev, env, ns) if not valid.value: exp = f"{arg.type_}" @@ -146,9 +151,11 @@ class UserFunction(Function): prev_type = False elif (isinstance(param, Type) or isinstance(param, MultiType)) and not prev_type and not first: if many is None: - args[-1].type_ = param.name + #args[-1].type_ = param.name + args[-1].type_ = param else: - many.type_ = param.name + #many.type_ = param.name + many.type_ = param prev_type = True else: raise NebPanic("invalid :func signature", param) @@ -171,7 +178,7 @@ class UserFunction(Function): class TypeWrap: def __init__(self, name, parent, is_func): - self.name = name + self.name = ALL_TYPES[name] self.parent = parent self.is_func = is_func @@ -180,14 +187,15 @@ class TypeWrap: if self.parent is None: return Bool(True) if isinstance(self.is_func, UserFunction): - valid = self.is_func.call(Expr([None, target]), env, ns) + valid = self.is_func.call(Expr([self.name, target]), env, ns) else: - valid = self.is_func(None, [target], env, ns) + valid = self.is_func(self.name, [target], env, ns) if valid.value == True: return valid - parent_type = env.get(f"{target.type_}") + #parent_type = env.get(f"{target.type_}") + parent_type = env.get(target.type_.name) while valid.value != True and parent_type.parent is not None: - parent_type = env.get(f"{parent_type.parent}") + parent_type = env.get(parent_type.parent.name.name) valid = Bool(self.name == parent_type.name) # TODO wrong return valid |
