Changeset 719


Ignore:
Timestamp:
May 5, 2003, 5:36:34 AM (18 years ago)
Author:
orlov
Message:
  • Maximum length of ShortInt? number is now static constant initialized at run-time.
Location:
to-imperative/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Convert/to_int.cc

    r708 r719  
    1717
    1818RF_FUNC (To_m_Int, (RF_ARG e_Exp), (RF_RES s_Int))
    19   uint LEN_SHORT_INT = 10;
    2019  uintptr_t len = 0;
    2120  int flag = 0;
     
    6665  };
    6766
    68   if (len >= LEN_SHORT_INT)
     67  if (len >= ShortInt::max_len)
    6968    RF_LIB_ERROR("Argument too large for conversion");
    7069
  • to-imperative/trunk/runtime/rf_short_int.cc

    r710 r719  
    1111namespace rftype
    1212{
     13
     14unsigned ShortInt::compute_max_len ()
     15{
     16  intptr_t i   = INTPTR_MAX / 10000;
     17  unsigned len = 4;
     18  for ( ; i; i /= 10) len++;
     19  return len;
     20}
     21
     22const unsigned ShortInt::max_len = compute_max_len();
    1323
    1424Expr ShortInt::create_expr (intptr_t _n)
     
    92102   
    93103  if (n < 0) {
    94     flag = 1;
    95104    n = -n;
     105    flag = -1;
    96106  }
    97107
    98   wchar_t str[11];
    99   int i = 11;
     108  wchar_t str[max_len + 1];
     109  int i = max_len;
    100110
    101111  if (!n) {
     
    114124    else i++;
    115125  }
    116   return pxx::WString(&str[i], 12 - i);
     126  return pxx::WString(&str[i], max_len + 1 - i);
    117127 
    118128}
  • to-imperative/trunk/runtime/rf_short_int.hh

    r705 r719  
    1919  public Term
    2020{
     21
     22  static unsigned compute_max_len () ;
     23
    2124public:
    2225 
     26  static const unsigned max_len;
     27
    2328  static Expr create_expr (intptr_t _n) ;
    2429  static Expr create_expr (Expr& _expr, int _flag);
    2530
    2631  inline ShortInt (intptr_t n) ;
    27   //  inline ShortInt(const Expr&, bool is_positive, uintptr_t i);
    2832  inline intptr_t to_int () const ;
    2933
  • to-imperative/trunk/samples/Arithm/add.rf

    r593 r719  
    22
    33Main =
    4   {
    5     <PrintLN <"+" 2 3>>;
    6   };
     4  <PrintLN <"+" 2 3>>,
     5  <PrintLN <"+" -2147483646 -1>>;
    76
Note: See TracChangeset for help on using the changeset viewer.