Source code for curry.icurry.types.iliteral

from .iobject import IObject
from .isymbol import ISymbol
from ...common import Fingerprint
import abc, collections.abc

__all__ = ['IChar', 'IFloat', 'IInt', 'ILiteral', 'IString', 'IUnboxedLiteral']

[docs] class IInt(ISymbol): def __init__(self, value, **kwds): ISymbol.__init__(self, 'Prelude.Int', **kwds) self.value = int(value) @property def _fields_(self): return 'value', @property def modulename(self): return 'Prelude' def __str__(self): return '(%r)' % self.value # parens to suggest boxing def __repr__(self): return 'IInt(value=%r)' % self.value
[docs] class IChar(ISymbol): def __init__(self, value, **kwds): ISymbol.__init__(self, 'Prelude.Char', **kwds) self.value = str(value) assert len(self.value) == 1 # one code point @property def _fields_(self): return 'value', @property def modulename(self): return 'Prelude' def __str__(self): return '(%r)' % self.value # parens to suggest boxing def __repr__(self): return 'IChar(value=%r)' % self.value
[docs] class IFloat(ISymbol): def __init__(self, value, **kwds): ISymbol.__init__(self, 'Prelude.Float', **kwds) self.value = float(value) @property def _fields_(self): return 'value', @property def modulename(self): return 'Prelude' def __str__(self): return '(%r)' % self.value # parens to suggest boxing def __repr__(self): return 'IFloat(value=%r)' % self.value
[docs] class IString(ISymbol): def __init__(self, value, **kwds): ISymbol.__init__(self, 'Prelude._PyString', **kwds) self.value = str(value) # The JSON codec writes the fields and reads them back as keywords # (icurry.json): the value alone, as for the other literals. @property def _fields_(self): return 'value', @property def modulename(self): return 'Prelude' def __str__(self): return '_PyString(%r)' % self.value def __repr__(self): return 'IString(value=%r)' % self.value
[docs] class IUnboxedLiteral(IObject, metaclass=abc.ABCMeta): pass
IUnboxedLiteral.register(int) IUnboxedLiteral.register(str) IUnboxedLiteral.register(float) # An iterator is considered a fundamental data type so that Sprite does not try # to reduce it. This should always be the argument to an instance of # Prelude._biGenerator. IUnboxedLiteral.register(collections.abc.Iterator) # A view of raw memory (used by _PyString). IUnboxedLiteral.register(memoryview) # Extend the builtins to include fingerprints. IUnboxedLiteral.register(Fingerprint)
[docs] class ILiteral(IObject, metaclass=abc.ABCMeta): pass
ILiteral.register(IInt) ILiteral.register(IChar) ILiteral.register(IFloat) ILiteral.register(IUnboxedLiteral) ILiteral.register(IString)