Browse Source

data,num: add convenience definitions

main
Shiz 4 months ago
parent
commit
4400209545
3 changed files with 12 additions and 5 deletions
  1. +5
    -5
      sx/__init__.py
  2. +3
    -0
      sx/types/data.py
  3. +4
    -0
      sx/types/num.py

+ 5
- 5
sx/__init__.py View File

@ -5,12 +5,12 @@ from .core.expr import BaseExpr, Expr, const, infer
from .core.meta import Wrapper, Generic
del core
from .types.data import Nothing, Static, Ignored, Data, data, Bits
from .types.data import Nothing, Static, Ignored, Data, data, Bits, bit, nibble
from .types.num import (
Bool, Int, Float, bool, int8, uint8,
int16, uint16, int16be, int16le, uint16be, uint16le,
int32, uint32, int32be, int32le, uint32be, uint32le,
int64, uint64, int64be, int64le, uint64be, uint64le,
Bool, Int, Float, bool, int8, uint8, byte,
int16, uint16, int16be, int16le, uint16be, uint16le, word,
int32, uint32, int32be, int32le, uint32be, uint32le, dword,
int64, uint64, int64be, int64le, uint64be, uint64le, qword,
float16, float16le, float16be, binary16, binary16le, binary16be, half,
float32, float32le, float32be, binary32, binary32le, binary32be, float_,
float64, float64le, float64be, binary64, binary64le, binary64be, double,


+ 3
- 0
sx/types/data.py View File

@ -88,6 +88,9 @@ class Bits(Type[int]):
def __repr__(self) -> str:
return f'{__name__}.Bits({self.amount!r})'
bit = Bits(1)
nibble = Bits(4)
T = TypeVar('T')


+ 4
- 0
sx/types/num.py View File

@ -46,11 +46,13 @@ class Int(Type[int]):
return f'{__name__}.Int({self.bits!r}, endian={self.endian!r}, signed={self.signed!r})'
int8 = Int(8, endian=Endian.Little, signed=True)
byte = \
uint8 = Int(8, endian=Endian.Little, signed=False)
int16 = \
int16le = Int(16, endian=Endian.Little, signed=True)
int16be = Int(16, endian=Endian.Big, signed=True)
word = \
uint16 = \
uint16le = Int(16, endian=Endian.Little, signed=False)
uint16be = Int(16, endian=Endian.Big, signed=False)
@ -58,6 +60,7 @@ uint16be = Int(16, endian=Endian.Big, signed=False)
int32 = \
int32le = Int(32, endian=Endian.Little, signed=True)
int32be = Int(32, endian=Endian.Big, signed=True)
dword = \
uint32 = \
uint32le = Int(32, endian=Endian.Little, signed=False)
uint32be = Int(32, endian=Endian.Big, signed=False)
@ -65,6 +68,7 @@ uint32be = Int(32, endian=Endian.Big, signed=False)
int64 = \
int64le = Int(64, endian=Endian.Little, signed=True)
int64be = Int(64, endian=Endian.Big, signed=True)
qword = \
uint64 = \
uint64le = Int(64, endian=Endian.Little, signed=False)
uint64be = Int(64, endian=Endian.Big, signed=False)


Loading…
Cancel
Save