intn->origsize = 0; /* no reliable way to figure this out */
- if (BitVector_from_Dec_static(from_dec_data, conv_bv,
- (unsigned char *)str) == ErrCode_Ovfl)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
+ switch (BitVector_from_Dec_static(from_dec_data, conv_bv,
+ (unsigned char *)str)) {
+ case ErrCode_Pars:
+ yasm_error_set(YASM_ERROR_VALUE, N_("invalid decimal literal"));
+ break;
+ case ErrCode_Ovfl:
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
+ break;
+ default:
+ break;
+ }
if (Set_Max(conv_bv) < 32) {
intn->type = INTNUM_UL;
intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
intn->origsize = (unsigned char)strlen(str);
- if(intn->origsize > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
-
- BitVector_from_Bin(conv_bv, (unsigned char *)str);
+ switch (BitVector_from_Bin(conv_bv, (unsigned char *)str)) {
+ case ErrCode_Pars:
+ yasm_error_set(YASM_ERROR_VALUE, N_("invalid binary literal"));
+ break;
+ case ErrCode_Ovfl:
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
+ break;
+ default:
+ break;
+ }
if (Set_Max(conv_bv) < 32) {
intn->type = INTNUM_UL;
intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
intn->origsize = strlen(str)*3;
- if(intn->origsize > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
-
- BitVector_from_Oct(conv_bv, (unsigned char *)str);
+ switch (BitVector_from_Oct(conv_bv, (unsigned char *)str)) {
+ case ErrCode_Pars:
+ yasm_error_set(YASM_ERROR_VALUE, N_("invalid octal literal"));
+ break;
+ case ErrCode_Ovfl:
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
+ break;
+ default:
+ break;
+ }
if (Set_Max(conv_bv) < 32) {
intn->type = INTNUM_UL;
intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
intn->origsize = strlen(str)*4;
- if(intn->origsize > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
-
- BitVector_from_Hex(conv_bv, (unsigned char *)str);
+ switch (BitVector_from_Hex(conv_bv, (unsigned char *)str)) {
+ case ErrCode_Pars:
+ yasm_error_set(YASM_ERROR_VALUE, N_("invalid hex literal"));
+ break;
+ case ErrCode_Ovfl:
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
+ break;
+ default:
+ break;
+ }
if (Set_Max(conv_bv) < 32) {
intn->type = INTNUM_UL;
intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
intn->origsize = len*8;
if(intn->origsize > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Character constant too large for internal format"));
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Character constant too large for internal format"));
if (len > 4) {
BitVector_Empty(conv_bv);
*size = (ptr-ptr_orig)+1;
if(i > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
else if (sign && (*ptr & 0x40) == 0x40)
BitVector_Interval_Fill(conv_bv, i, BITVECT_NATIVE_SIZE-1);
intn->origsize = 0;
if (srcsize*8 > BITVECT_NATIVE_SIZE)
- yasm_warn_set(YASM_WARN_GENERAL,
- N_("Numeric constant too large for internal format"));
+ yasm_error_set(YASM_ERROR_OVERFLOW,
+ N_("Numeric constant too large for internal format"));
/* Read the buffer into a bitvect */
BitVector_Empty(conv_bv);
self.intn = <yasm_intnum *>__get_voidp(value, IntNum)
return
- val = None
if isinstance(value, str):
- val = long(value, base)
+ if base == 2:
+ self.intn = yasm_intnum_create_bin(value)
+ elif base == 8:
+ self.intn = yasm_intnum_create_oct(value)
+ elif base == 10 or base is None:
+ self.intn = yasm_intnum_create_dec(value)
+ elif base == 16:
+ self.intn = yasm_intnum_create_hex(value)
+ elif base == "nasm":
+ self.intn = yasm_intnum_create_charconst_nasm(value)
+ else:
+ raise ValueError("base must be 2, 8, 10, 16, or \"nasm\"")
elif isinstance(value, (int, long)):
- val = long(value)
-
- if val is None:
+ _PyLong_AsByteArray(long(value), buf, 16, 1, 1)
+ self.intn = yasm_intnum_create_sized(buf, 1, 16, 0)
+ else:
raise ValueError
- _PyLong_AsByteArray(val, buf, 16, 1, 1)
- self.intn = yasm_intnum_create_sized(buf, 1, 16, 0)
-
def __dealloc__(self):
if self.intn != NULL: yasm_intnum_destroy(self.intn)
def test_to_from(self):
for i in self.legal_values:
self.assertEquals(i, int(IntNum(i)))
+ self.assertEquals(i, long(IntNum(i)))
def test_overflow(self):
for i in self.overflow_values:
self.assertRaises(OverflowError, IntNum, i)
+ str_values = [
+ "0", "00000", "1234", "87654321", "010101010", "FADCBEEF"
+ ]
+ base_values = [2, 8, 10, 12, 16, None, "nasm", "foo"]
+
+ def test_from_str(self):
+ pass
+
+ def test_from_str_base(self):
+ pass
+
def test_exceptions(self):
self.assertRaises(ZeroDivisionError, IntNum(1).__div__, 0)