Adding support for type checking.
This commit is contained in:
parent
531e215ffd
commit
1862ece03e
|
|
@ -9,6 +9,7 @@ class AnyJoyType(object):
|
||||||
Joy type variable. Represents any Joy value.
|
Joy type variable. Represents any Joy value.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
accept = tuple, int, float, long, str, unicode, bool, Symbol
|
||||||
prefix = 'a'
|
prefix = 'a'
|
||||||
|
|
||||||
def __init__(self, number):
|
def __init__(self, number):
|
||||||
|
|
@ -25,7 +26,10 @@ class AnyJoyType(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
return issubclass(other.__class__, self.__class__)
|
return (
|
||||||
|
issubclass(other.__class__, self.__class__)
|
||||||
|
or isinstance(other, self.accept)
|
||||||
|
)
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
# 'a string' >= AnyJoyType() should be False.
|
# 'a string' >= AnyJoyType() should be False.
|
||||||
|
|
@ -39,13 +43,31 @@ class AnyJoyType(object):
|
||||||
return hash(repr(self))
|
return hash(repr(self))
|
||||||
|
|
||||||
|
|
||||||
class BooleanJoyType(AnyJoyType): prefix = 'b'
|
class BooleanJoyType(AnyJoyType):
|
||||||
class NumberJoyType(AnyJoyType): prefix = 'n'
|
accept = bool
|
||||||
class FloatJoyType(NumberJoyType): prefix = 'f'
|
prefix = 'b'
|
||||||
class IntJoyType(FloatJoyType): prefix = 'i'
|
|
||||||
|
|
||||||
|
class NumberJoyType(AnyJoyType):
|
||||||
|
accept = int, float, long, complex
|
||||||
|
prefix = 'n'
|
||||||
|
|
||||||
|
|
||||||
|
class FloatJoyType(NumberJoyType):
|
||||||
|
accept = float
|
||||||
|
prefix = 'f'
|
||||||
|
|
||||||
|
|
||||||
|
class IntJoyType(FloatJoyType):
|
||||||
|
accept = int
|
||||||
|
prefix = 'i'
|
||||||
|
|
||||||
|
|
||||||
class StackJoyType(AnyJoyType):
|
class StackJoyType(AnyJoyType):
|
||||||
|
|
||||||
|
accept = tuple
|
||||||
prefix = 's'
|
prefix = 's'
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
# Imitate () at the end of cons list.
|
# Imitate () at the end of cons list.
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue