Changeset 1376


Ignore:
Timestamp:
Mar 18, 2004, 10:04:11 PM (17 years ago)
Author:
orlov
Message:

  • Fixed printing of objects.
Location:
to-imperative/branches/parenth_term/runtime
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/branches/parenth_term/runtime/rf_box.hh

    r502 r1376  
    3434
    3535  inline void put (Expr const& _expr) ;
    36   inline Expr get () ;
     36  inline Expr get () const ;
    3737
     38  inline pxx::WString to_string () const ;
    3839
    3940};
  • to-imperative/branches/parenth_term/runtime/rf_box.ih

    r502 r1376  
    6565}
    6666
    67 inline Expr Box::get ()
     67inline Expr Box::get () const
    6868{
    6969  return content;
     70}
     71
     72inline pxx::WString Box::to_string () const
     73{
     74  size_t max_len = hex_ptr_len + 10;
     75  wchar_t str[max_len];
     76  int len = swprintf(str, max_len, L"<Box|%p|", this);
     77  if (-1 == len)
     78    FATAL("<Box|%p| is more then %u wide characters", this, max_len);
     79  return pxx::WString(str, len) + pxx::WString(content) + pxx::WString(L">");
    7080}
    7181
  • to-imperative/branches/parenth_term/runtime/rf_channel.hh

    r1363 r1376  
    3434  inline bool operator == (Object const& _obj) const ;
    3535
     36  inline pxx::WString to_string () const ;
     37
    3638  inline bool open (char const* _fname, char const* _mode) ;
    3739  inline void close () ;
  • to-imperative/branches/parenth_term/runtime/rf_channel.ih

    r1363 r1376  
    8282}
    8383
     84inline pxx::WString Channel::to_string () const
     85{
     86  size_t max_len = hex_ptr_len + max_int_len + 15;
     87  wchar_t str[max_len];
     88  int len =
     89      swprintf(str, max_len, L"<Channel|%p|%d>", this, fp ? fileno(fp) : -1);
     90  if (-1 == len) {
     91    FATAL("<Channel|%p|%d> is more then %u wide characters",
     92          this, fp ? fileno(fp) : -1, max_len);
     93  }
     94  return pxx::WString(str, len);
     95}
     96
    8497}
    8598
  • to-imperative/branches/parenth_term/runtime/rf_common.hh

    r1312 r1376  
    3232extern uintptr_t stack_size ;
    3333
     34#if UINTPTR_MAX == UINT32_MAX
     35static const uint8_t hex_ptr_len = 8;
     36#elif UINTPTR_MAX == UINT64_MAX
     37static const uint8_t hex_ptr_len = 16;
     38#else
     39#error "Unsupported pointer size"
     40#endif
     41
     42static const uint8_t max_int_len = 10;
     43// FIXME: Is int 32 bits everywhere?
     44
    3445#if DEBUG
    3546extern uintptr_t empty_copy ;
  • to-imperative/branches/parenth_term/runtime/rf_expr.ih

    r1367 r1376  
    862862        if (fprintf(_fp, "%" PRIdPTR, ((Int32 const&)(*p)).to_int()) == -1)
    863863          return false;
    864       } else if (p->get_type() == type_int) {
     864      } else { // if (p->get_type() == type_int) {
    865865//        mpz_t* z = static_cast<Integer*>(p)->get_mpz_ptr();
    866866//        if (!mpz_out_str(_fp, 10, *z)) return false;
    867867        if (!write_wstr(_fp, (WString)(*p))) return false;
    868       } else {
    869         fprintf(_fp, " <%u|%p> ", p->get_type(), p->ptr_data2);
     868//      } else {
     869//        fprintf(_fp, " <%u|%p> ", p->get_type(), p->ptr_data2);
    870870//        FATAL("Not supported yet");
    871871      }
     
    882882  for (Term* p = first; p < last; p++) {
    883883    if (p->is_sym()) {
    884       if (!(p->is_dynamic())) {
    885         WString s = (WString)(*p);
    886         size_t len = s.get_length();
    887         char buf[MB_CUR_MAX + 1];
    888         for (size_t i = 0; i < len; i++) {
    889           size_t n = wctomb(buf, s[i]);
    890           if (n != (size_t)(-1)) {
    891             buf[n] = 0;
    892             if (fputs(buf, _fp) == EOF) return false;
    893           } else {
    894             if (fputc('?', _fp) == EOF) return false;
    895           }
    896         }
    897       } else { 
    898         if (fprintf(_fp,"<%u|%p>", p->get_type(), p->ptr_data2) < 0)
    899           return false;   
    900      } 
     884      WString s = (WString)(*p);
     885      size_t len = s.get_length();
     886      char buf[MB_CUR_MAX + 1];
     887      for (size_t i = 0; i < len; i++) {
     888        size_t n = wctomb(buf, s[i]);
     889        if (n != (size_t)(-1)) {
     890          buf[n] = 0;
     891          if (fputs(buf, _fp) == EOF) return false;
     892        } else {
     893          if (fputc('?', _fp) == EOF) return false;
     894        }
     895      }
    901896    } else if (p->is_ref()) {
    902897      if (fputc('(', _fp) == EOF) return false;
  • to-imperative/branches/parenth_term/runtime/rf_object.ih

    r1287 r1376  
    111111inline pxx::WString Object::to_string () const
    112112{
    113   return (pxx::WString(L""));
     113  size_t max_len = hex_ptr_len + 15;
     114  wchar_t str[max_len];
     115  int len = swprintf(str, max_len, L"<Object|%p>", this);
     116  if (-1 == len)
     117    FATAL("<Object|%p> is more then %u wide characters", this, max_len);
     118  return pxx::WString(str, len);
    114119}
    115120
  • to-imperative/branches/parenth_term/runtime/rf_table.hh

    r1288 r1376  
    4444  inline uint32_t hash () const;
    4545  inline bool operator == (Object const&) const;
     46  inline pxx::WString to_string () const;
    4647};
    4748 
  • to-imperative/branches/parenth_term/runtime/rf_table.ih

    r1288 r1376  
    151151}
    152152
     153inline pxx::WString Table::to_string () const
     154{
     155  size_t max_len = hex_ptr_len + 15;
     156  wchar_t str[max_len];
     157  int len = swprintf(str, max_len, L"<Table|%p>", this, root);
     158  if (-1 == len)
     159    FATAL("<Table|%p> is more then %u wide characters", this, max_len);
     160  return pxx::WString(str, len);
     161}
    153162 
    154163}
  • to-imperative/branches/parenth_term/runtime/rf_term.hh

    r1367 r1376  
    133133  inline bool is_ref () const ;
    134134  ///
    135   /// Check whether a term is a dynamic symbol
    136   inline bool is_dynamic() const;
    137   ///
    138135  /// Check whether a term is a border symbol
    139136  inline bool is_border () const ;
  • to-imperative/branches/parenth_term/runtime/rf_term.ih

    r1367 r1376  
    7777  return get_short_type() > type_parenth;
    7878}
    79 
    80 inline bool Term::is_dynamic() const
    81 {
    82   unsigned obj = get_type();
    83   return (obj==type_box) || (obj==type_vector) || (obj==type_table) || (obj==type_channel);
    84 }
    85 
    8679
    8780inline bool Term::is_ref () const
  • to-imperative/branches/parenth_term/runtime/rf_vector.hh

    r1287 r1376  
    2424  inline Vector (size_t _length, Expr const& _fill) ;
    2525  inline Vector (Expr const& _expr, size_t _length) ;
    26   inline Vector (Vector const& _vector, size_t _index, size_t _length);
     26  inline Vector (Vector const& _vector, size_t _index, size_t _length) ;
    2727
    2828  inline unsigned get_type () const ;
     
    3030
    3131  inline bool operator == (Object const& _obj) const ;
    32   inline const Vector& operator = (Vector const&);
     32  inline const Vector& operator = (Vector const&) ;
     33
     34  inline pxx::WString to_string () const ;
    3335};
    3436
  • to-imperative/branches/parenth_term/runtime/rf_vector.ih

    r1287 r1376  
    9797}
    9898
     99inline pxx::WString Vector::to_string () const
     100{
     101  size_t max_len = hex_ptr_len * 2 + 15;
     102  wchar_t str[max_len];
     103  int len = swprintf(str, max_len, L"<Vector|%p|%p>", this, get_data());
     104  if (-1 == len) {
     105    FATAL("<Vector|%p|%p> is more then %u wide characters",
     106          this, get_data(), max_len);
     107  }
     108  return pxx::WString(str, len);
     109}
    99110
    100111}
Note: See TracChangeset for help on using the changeset viewer.