diff options
| author | mryouse | 2022-07-06 01:55:50 +0000 | 
|---|---|---|
| committer | mryouse | 2022-07-06 01:55:50 +0000 | 
| commit | 6ee92c12a58637101e1cd54caea222630a2e9d4b (patch) | |
| tree | 137c3589a5b560f015e02562e6dc356fde5fa354 | |
| parent | 8b2996445fb91125d8c367ddac246ea3d2d05adc (diff) | |
add a type to types called :type
| -rw-r--r-- | neb/__init__.py | 1 | ||||
| -rw-r--r-- | neb/std/types.py | 7 | ||||
| -rw-r--r-- | neb/typeclass.py | 1 | 
3 files changed, 9 insertions, 0 deletions
| diff --git a/neb/__init__.py b/neb/__init__.py index 7296c58..dd7245a 100644 --- a/neb/__init__.py +++ b/neb/__init__.py @@ -174,6 +174,7 @@ class TypeWrap:          self.name = name          self.parent = parent          self.is_func = is_func +        self.type_ = TypeEnum.TYPE      def validate_type(self, target, env, ns):          # if it's an any type, it's valid diff --git a/neb/std/types.py b/neb/std/types.py index 872f29a..0d3db03 100644 --- a/neb/std/types.py +++ b/neb/std/types.py @@ -74,6 +74,11 @@ def interpretIsHandle(symbol, args, env, ns):  TYPES.register("handle?", Builtin("handle?", interpretIsHandle, [Arg("arg", TypeEnum.ANY)], return_type=Type(":bool"))) +def interpretIsType(symbol, args, env, ns): +    return Bool(isinstance(args[0], TypeWrap)) + +TYPES.register("type?", Builtin("type?", interpretIsType, [Arg("arg", TypeEnum.ANY)], return_type=Type(":bool"))) +  # add types to env  any_type = NebType(":any", None, interpretIsAny)  literal_type = NebType(":literal", any_type, interpretIsLiteral) @@ -84,6 +89,7 @@ number_type = NebType(":number", literal_type, interpretIsNumber)  int_type = NebType(":int", number_type, interpretIsInt)  float_type = NebType(":float", number_type, interpretIsFloat)  handle_type = NebType(":handle", any_type, interpretIsHandle) +type_type = NebType(":type", any_type, interpretIsType)  TYPES.register(":any", any_type)  TYPES.register(":literal", literal_type) @@ -94,3 +100,4 @@ TYPES.register(":number", number_type)  TYPES.register(":int", int_type)  TYPES.register(":float", float_type)  TYPES.register(":handle", handle_type) +TYPES.register(":type", type_type) diff --git a/neb/typeclass.py b/neb/typeclass.py index a6daaf9..75f61b1 100644 --- a/neb/typeclass.py +++ b/neb/typeclass.py @@ -10,6 +10,7 @@ class TypeEnum(Enum):      LITERAL = auto()      BOOL = auto()      HANDLE = auto() +    TYPE = auto()      USER = auto()      def __str__(self): | 
