Exemple #1
0
/*------------------------------------------------------------------------*/
static _NIL_TYPE_ IDX(_NIL_TYPE_)
 { _EXP_TYPE_ dct, exp, nbr, tab;
   _TAG_TYPE_ tag;
   _UNS_TYPE_ siz;
   _stk_claim_();
   _stk_pop_EXP_(nbr);
   tag = _ag_get_TAG_(nbr);
   if (tag == _NBR_TAG_)
     { siz = _ag_get_NBU_(nbr);
       if (siz == 0)
         { _stk_zap_EXP_();
           _stk_peek_EXP_(dct);
           _ag_set_DCT_VAL_(dct, _EMPTY_);
           _ag_set_DCT_DCT_(dct, _DCT_);
           _DCT_ = dct;
           _stk_poke_EXP_(_EMPTY_);
           _stk_zap_CNT_(); }
       else if (siz > 0)
         { _mem_claim_SIZ_(siz);
           tab = _ag_make_TAB_(siz);
           _stk_peek_EXP_(exp);
           _stk_poke_EXP_(tab);
           _stk_push_EXP_(exp);
           _stk_push_EXP_(_ONE_);
           _stk_push_EXP_(exp);
           _stk_poke_CNT_(INI);
           _stk_push_CNT_(EXP); }
       else
         _error_(_SIZ_ERROR_);}
   else
     _error_(_SIZ_ERROR_); }
Exemple #2
0
/*--------------------------------------------------------------------------*/
static _NIL_TYPE_ LARG(_NIL_TYPE_)
 { _EXP_TYPE_ dct, exp, val, ltab;
   _TAG_TYPE_ tag;
   _stk_claim_();
   _stk_pop_EXP_(val);
   tag = _ag_get_TAG_(val);
   if (tag == _VOI_TAG_)
     { _stk_pop_EXP_(exp);
       ltab = _ag_make_LTAB_();
       _stk_peek_EXP_(dct);
       _ag_set_DCT_VAL_(dct, ltab);
       _ag_set_DCT_DCT_(dct, _DCT_);
       _DCT_ = dct;
       _ag_set_LTAB_CONCR_(ltab, _EMPTY_);
       _ag_set_LTAB_LZEXP_(ltab, exp);
       _ag_set_LTAB_DCT_(ltab, _DCT_);
       _stk_poke_EXP_(ltab);
       _stk_zap_CNT_(); }
   else if (tag == _TAB_TAG_)
     { ltab = _ag_make_LTAB_();
       _stk_peek_EXP_(exp);
       _stk_poke_EXP_(ltab);
       _stk_push_EXP_(exp);
       _stk_push_EXP_(val);
       _stk_push_EXP_(_ONE_);
       exp = _ag_get_TAB_EXP_(val, 1);
       _stk_push_EXP_(exp);
       _stk_poke_CNT_(INIC);
       _stk_push_CNT_(EXP); }
   else
     _error_(_IAG_ERROR_); }
Exemple #3
0
static _UNS_TYPE_ allocate(const _UNS_TYPE_ siz)
 { _UNS_TYPE_ ofs = _mem_FREE_;
   _mem_FREE_ += siz + 1;
   #ifndef NDEBUG
   if (_mem_FREE_ > _mem_TOP_)
     _error_(_MEM_ERROR_);
   #endif
   return ofs; }
Exemple #4
0
/*------------------------------------------------------------------------*/
static _NIL_TYPE_ SET(_NIL_TYPE_)
 { _EXP_TYPE_ arg, dct, exp, fun, idx, inv, nam, set, tab, ltab;
   _TAG_TYPE_ tag;
   _stk_claim_();
   _mem_claim_();
   _stk_peek_EXP_(set);
   inv = _ag_get_SET_INV_(set);
   exp = _ag_get_SET_EXP_(set);
   tag = _ag_get_TAG_(inv);
   switch (tag)
    { case _VAR_TAG_:
        nam = _ag_get_VAR_NAM_(inv);
        _dct_locate_(nam, dct, _DCT_);
        _stk_poke_EXP_(dct);
        _stk_push_EXP_(exp);
        _stk_poke_CNT_(CHG);
        _stk_push_CNT_(EXP);
        break;
      case _APL_TAG_:
        fun = _ag_make_FUN_();
        inv = _ag_get_SET_INV_(set);
        nam = _ag_get_APL_NAM_(inv);
        arg = _ag_get_APL_ARG_(inv);
        _dct_locate_(nam, dct, _DCT_);
        _ag_set_DCT_VAL_(dct, fun);
        _ag_set_FUN_NAM_(fun, nam);
        _ag_set_FUN_ARG_(fun, arg);
        _ag_set_FUN_EXP_(fun, exp);
        _ag_set_FUN_DCT_(fun, _DCT_);
        _stk_poke_EXP_(fun);
        _stk_zap_CNT_();
        break;
      case _TBL_TAG_:
        nam = _ag_get_TBL_NAM_(inv);
        idx = _ag_get_TBL_IDX_(inv);
        _dct_locate_(nam, dct, _DCT_);
        tab = _ag_get_DCT_VAL_(dct);
        _stk_poke_EXP_(tab);
        _stk_push_EXP_(idx);
        _stk_push_EXP_(exp);
        _stk_poke_CNT_(RPL);
        _stk_push_CNT_(SWP);
        _stk_push_CNT_(EXP);
        break;
      case _LTBL_TAG_:
        nam = _ag_get_TBL_NAM_(inv);
        arg = _ag_get_TBL_IDX_(inv);
        _dct_locate_(nam, dct, _DCT_);
        ltab = _ag_get_DCT_VAL_(dct);
        _stk_poke_EXP_(ltab);
        _stk_push_EXP_(exp);
        _stk_push_EXP_(arg);
        _stk_poke_CNT_(LRPL);
        _stk_push_CNT_(EXP);
      break;
      default:
       _error_(_AGR_ERROR_); }}
Exemple #5
0
/*-------------------------------------------------------------------------*/
static _NIL_TYPE_ DEF(_NIL_TYPE_)
 { _EXP_TYPE_ arg, dct, def, exp, fun, idx, inv, nam;
   _TAG_TYPE_ tag;
   _stk_claim_();
   _mem_claim_();
   dct = _ag_make_DCT_();
   _stk_peek_EXP_(def);
   inv = _ag_get_DEF_INV_(def);
   exp = _ag_get_DEF_EXP_(def);
   tag = _ag_get_TAG_(inv);
   switch (tag)
    { case _VAR_TAG_:
        nam = _ag_get_VAR_NAM_(inv);
        _ag_set_DCT_NAM_(dct, nam);
        _stk_poke_EXP_(dct);
        _stk_push_EXP_(exp);
        _stk_poke_CNT_(ASS);
        _stk_push_CNT_(EXP);
        break;
      case _APL_TAG_:
        fun = _ag_make_FUN_();
        nam = _ag_get_APL_NAM_(inv);
        arg = _ag_get_APL_ARG_(inv);
        _ag_set_DCT_NAM_(dct, nam);
        _ag_set_DCT_VAL_(dct, fun);
        _ag_set_DCT_DCT_(dct, _DCT_);
        _DCT_ = dct;
        _ag_set_FUN_NAM_(fun, nam);
        _ag_set_FUN_ARG_(fun, arg);
        _ag_set_FUN_EXP_(fun, exp);
        _ag_set_FUN_DCT_(fun, dct);
        _stk_poke_EXP_(fun);
        _stk_zap_CNT_();
        break;
      case _TBL_TAG_:
        nam = _ag_get_TBL_NAM_(inv);
        idx = _ag_get_TBL_IDX_(inv);
        _ag_set_DCT_NAM_(dct, nam);
        _stk_poke_EXP_(dct);
        _stk_push_EXP_(exp);
        _stk_push_EXP_(idx);
        _stk_poke_CNT_(IDX);
        _stk_push_CNT_(EXP);
        break;
      case _LTBL_TAG_:   // Added Lazy Tabulation
        nam = _ag_get_LTBL_NAM_(inv);
        arg = _ag_get_LTBL_ARG_(inv);
        _ag_set_DCT_NAM_(dct, nam);
        _stk_poke_EXP_(dct);
        _stk_push_EXP_(exp);
        _stk_push_EXP_(arg);
        _stk_poke_CNT_(LARG);
        _stk_push_CNT_(EXP);
        break;
      default:
        _error_(_AGR_ERROR_); }}
Exemple #6
0
/*------------------------------------------------------------------------*/
static _NIL_TYPE_ BND(_NIL_TYPE_)
 { _EXP_TYPE_ act, arg, dct, exp, fun, frm, nam, nbr, par, val, xdc;
   _CNT_TYPE_ cnt;
   _TAG_TYPE_ tag;
   _UNS_TYPE_ ctr, siz;
   _stk_claim_();
   _mem_claim_();
   _stk_pop_EXP_(val);
   _stk_pop_EXP_(dct);
   _ag_set_DCT_VAL_(dct, val);
   _stk_pop_EXP_(nbr);
   _stk_pop_EXP_(arg);
   siz = _ag_get_TAB_SIZ_(arg);
   ctr = _ag_get_NBU_(nbr);
   if (ctr == siz)
     { _stk_zap_EXP_();
       _stk_zap_CNT_();
       _stk_peek_CNT_(cnt);
       if (cnt != RET)
         { _stk_peek_EXP_(exp);
           _stk_poke_EXP_(_DCT_);
           _stk_push_EXP_(exp);
           _stk_push_CNT_(RET); }
       _stk_push_CNT_(EXP);
       _DCT_ = dct; }
   else
     { _stk_peek_EXP_(par);
       frm = _ag_get_TAB_EXP_(par, ++ctr);
       act = _ag_get_TAB_EXP_(arg, ctr);
       tag = _ag_get_TAG_(frm);
       _stk_push_EXP_(arg);
       nbr = _ag_succ_NBR_(nbr);
       _stk_push_EXP_(nbr);
       xdc = _ag_make_DCT_();
       _stk_push_EXP_(xdc);
       _ag_set_DCT_DCT_(xdc, dct);
       switch (tag)
        { case _VAR_TAG_:
            nam = _ag_get_VAR_NAM_(frm);
            _ag_set_DCT_NAM_(xdc, nam);
            _stk_push_EXP_(act);
            _stk_push_CNT_(EXP);
            break;
          case _APL_TAG_:
            fun = _ag_make_FUN_();
            nam = _ag_get_APL_NAM_(frm);
            arg = _ag_get_APL_ARG_(frm);
            _ag_set_DCT_NAM_(xdc, nam);
            _ag_set_FUN_NAM_(fun, nam);
            _ag_set_FUN_ARG_(fun, arg);
            _ag_set_FUN_EXP_(fun, act);
            _ag_set_FUN_DCT_(fun, _DCT_);
            _stk_push_EXP_(fun);
             break;
          default:
            _error_(_IPM_ERROR_); }}}
Exemple #7
0
_EXP_TYPE_ _env_make_NAM_(const _STR_TYPE_ str)
 { _SIZ_TYPE_ idx;
   _EXP_TYPE_ nam;
   for (idx = 1; idx < DCT_top; idx++)
     { nam = _ag_get_TAB_EXP_(_NAMES_, idx);
       if (!strcmp(str, _ag_get_TXT_(nam)))
         return nam; }
   if (DCT_top > DCT_siz)
     _error_(_DCT_ERROR_);
   nam = _ag_make_TXT_(str);
   _ag_set_TAB_EXP_(_NAMES_, DCT_top++, nam);
   return nam; }
Exemple #8
0
/*------------------------------------------------------------------------*/
static _NIL_TYPE_ RPL(_NIL_TYPE_)
 { _EXP_TYPE_ nbr, tab, val;
   _UNS_TYPE_ ctr, siz;
   _TAG_TYPE_ tag;
   _stk_pop_EXP_(nbr);
   _stk_pop_EXP_(val);
   _stk_peek_EXP_(tab);
   tag = _ag_get_TAG_(tab);
   if (TAB_tab[tag])
     { siz = _ag_get_TAB_SIZ_(tab);
       tag = _ag_get_TAG_(nbr);
       if (tag == _NBR_TAG_)
         { ctr = _ag_get_NBU_(nbr);
           if ((ctr > 0) && (ctr <= siz))
             { _ag_set_TAB_EXP_(tab, ctr, val);
               _stk_zap_CNT_(); }
           else
             _error_(_RNG_ERROR_); }
       else
         _error_(_IIX_ERROR_); }
   else
     _error_(_NAT_ERROR_); }
Exemple #9
0
/*--------------------------------------------------------------------------*/
static _NIL_TYPE_ LTBL(_NIL_TYPE_)
 { _EXP_TYPE_ dct, idx, val, nam, ltab, ltbl;
   _TAG_TYPE_ tag;
   _stk_claim_();
   _stk_peek_EXP_(ltbl);
   nam = _ag_get_TBL_NAM_(ltbl);
   val = _ag_get_TBL_IDX_(ltbl);
   tag = _ag_get_TAG_(val);
   if (tag == _TAB_TAG_) 
      { idx = _ag_get_TAB_EXP_(val, 1);
        _dct_locate_(nam, dct, _DCT_);
        ltab = _ag_get_DCT_VAL_(dct);
        _stk_poke_EXP_(ltab);
        _stk_push_EXP_(idx);
        _stk_poke_CNT_(LREF);
        _stk_push_CNT_(EXP); }
   else 
      _error_(_IIX_ERROR_); }
Exemple #10
0
_NIL_TYPE_ _env_expand_(_NIL_TYPE_)
 { _EXP_TYPE_ exp, stk;
   _UNS_TYPE_ adr, idx, lwn, siz, upn, xsz;
   siz = _ag_get_TAB_SIZ_(_STK_);
   xsz = 2*siz;
   if (xsz > _STK_MAX_)
     _error_(_STK_ERROR_);
   _mem_claim_SIZ_(xsz);
   adr = (_UNS_TYPE_)_mem_cast_raw_(_STK_, _TAB_TAG_);
   lwn = 1 + (_EXP_ - adr)/_EXP_SIZE_;
   upn = 1 + (_CNT_ - adr)/_EXP_SIZE_;
   stk = _ag_make_TAB_(xsz);
   for (idx = 1 ; idx <= lwn ; idx++)
     { exp = _ag_get_TAB_EXP_(_STK_, idx);
       _ag_set_TAB_EXP_(stk, idx, exp); }
   for (idx = siz ; idx >= upn ; idx--)
     { exp = _ag_get_TAB_EXP_(_STK_, idx);
       _ag_set_TAB_EXP_(stk, xsz--, exp); }
   for ( ; xsz > lwn ; xsz--)
     _ag_set_TAB_EXP_(stk, xsz, _VOID_);
   adr   = (_UNS_TYPE_)_mem_cast_raw_(stk, _TAB_TAG_);
   _EXP_ = adr + (lwn - 1)*_EXP_SIZE_;
   _CNT_ = adr + (upn + siz - 1)*_EXP_SIZE_;
   _STK_ = stk; }
Exemple #11
0
_NIL_TYPE_ _scan_error_(const _RES_TYPE_ err)
 { if (scan_mark && scan_start)
     _mark_(scan_start-1, scan_stop-1);
   scan_index = 0;
   _error_(err); }
Exemple #12
0
_EXP_TYPE_ CHK_TAG(const _EXP_TYPE_ exp,
                   const _TAG_TYPE_ tag)
 { if (_mem_STORE_[exp.ptr.ofs].hdr.tag != tag)\
     _error_(_TAG_ERROR_);
   return exp; }
Exemple #13
0
_UNS_TYPE_ CHK_RNG(const _UNS_TYPE_ ofs,
                   const _UNS_TYPE_ idx)
 { if ((idx <= 0) ||
       (idx > _mem_STORE_[ofs].hdr.siz))
     _error_(_IDX_ERROR_);
   return ofs+idx; }
Exemple #14
0
_EXP_TYPE_ CHK_NRW(const _EXP_TYPE_ exp)
 { if (_mem_STORE_[exp.ptr.ofs].hdr.raw)
     _error_(_EXP_ERROR_);
   return exp; }
Exemple #15
0
_TAG_TYPE_ CHK_TGR(const _TAG_TYPE_ tag)
 { if (tag > TAG_MAX)\
     _error_(_TAG_ERROR_);
   return tag; }
Exemple #16
0
_EXP_TYPE_ CHK_NBR(const _EXP_TYPE_ exp)
 { if (exp.nbr.ptr)
     _error_(_EXP_ERROR_);
   return exp; }
Exemple #17
0
_EXP_TYPE_ CHK_PTR(const _EXP_TYPE_ exp)
 { if (!exp.ptr.ptr || (exp.ptr.ofs > _mem_TOP_))
     _error_(_EXP_ERROR_);
   return exp; }
Exemple #18
0
_NIL_TYPE_ _mem_reclaim_(const _UNS_TYPE_ mrg)
 { sweep();
   update();
   crunch();
   if ((_mem_FREE_ + mrg) > _mem_TOP_)
     _error_(_MEM_ERROR_); }
Exemple #19
0
/*-------------------------------------------------------------------------*/
static _NIL_TYPE_ LRPL(_NIL_TYPE_)
 { _EXP_TYPE_ dct, arg, xdc, exp, nbr, tab, ltab, newtab, i;
   _UNS_TYPE_ ctr, siz, pos;
   _STR_TYPE_ iname;
   _TAG_TYPE_ tag;
   _stk_pop_EXP_(arg);
   _stk_pop_EXP_(exp);
   _stk_peek_EXP_(ltab);
   tag = _ag_get_TAG_(arg);
   if (tag == _VOI_TAG_)                                    // Assign the new lazy expression
     { _ag_set_LTAB_LZEXP_(ltab, exp);
       _ag_set_LTAB_DCT_(ltab, _DCT_);
       _stk_zap_CNT_(); }
   else if (TAB_tab[tag] && (_ag_get_TAB_SIZ_(arg) == 1))   // Assign new member of concrete part
     { tab = _ag_get_LTAB_CONCR_(ltab);
       siz = _ag_get_TAB_SIZ_(tab);
       nbr = _ag_get_TAB_EXP_(arg, 1);
       tag = _ag_get_TAG_(nbr);
       if (tag == _NBR_TAG_)
         { xdc = _ag_get_LTAB_DCT_(ltab);
           pos = _ag_get_NBU_(nbr);
  
           iname = "i";
           _mem_claim_STR_(iname);
           i = _env_make_NAM_(iname);
           dct = _ag_make_DCT_();
           _ag_set_DCT_NAM_(dct, i);
           _ag_set_DCT_VAL_(dct, nbr);
           _ag_set_DCT_DCT_(dct, xdc);
           _stk_poke_EXP_(_DCT_);
           _DCT_ = dct;
           _stk_push_EXP_(exp);
           _stk_push_EXP_(tab);
           if ((pos > 0) && (pos <= 1073741824))            // greatest positive number represented with 31 bits, greater are negative
             { if (pos > siz) 
                 { ctr = _ag_get_NBU_(nbr);                 // make the counter equal to pos
                   _mem_claim_SIZ_(ctr);                    // create a new concrete table
                   newtab = _ag_make_TAB_(ctr);
                   _ag_set_LTAB_CONCR_(ltab, newtab);
                   exp = _ag_make_LAZY_();                  // fill the new concrete table
                   while (ctr > siz) {                      // first fill with <lazy> members
                      _ag_set_TAB_EXP_(newtab, ctr, exp);
                      ctr--; }
                   while (ctr > 0) {                        // now copy the concrete part
                      exp = _ag_get_TAB_EXP_(tab, ctr);
                      _ag_set_TAB_EXP_(newtab, ctr, exp);
                      ctr--; }
                   _stk_poke_EXP_(newtab);
                 }
               _stk_pop_EXP_(tab);
               _stk_peek_EXP_(exp);
               _stk_poke_EXP_(tab);
               _stk_push_EXP_(nbr);
               _stk_push_EXP_(exp);
               _stk_poke_CNT_(ATL);
               _stk_push_CNT_(EXP);
             }
           else
            _error_(_RNG_ERROR_); }
       else
        _error_(_IIX_ERROR_); }
   else
     _error_(_IAG_ERROR_); }
Exemple #20
0
/*------------------------------------------------------------------------*/
static _NIL_TYPE_ NYI(_NIL_TYPE_)
 { _error_(_AGR_ERROR_); }
Exemple #21
0
_NIL_TYPE_ _error_str_(const _RES_TYPE_ err,
                       const _STR_TYPE_ str)
 { STATUS = DISABLED;
   _PICO_MESSAGE_(SES_TAB[SES_IDX].ses, str);
   STATUS = ENABLED;
   _error_(err); }
Exemple #22
0
_EXP_TYPE_ CHK_AGR(const _EXP_TYPE_ exp,
                   const _TAG_TYPE_ tag)
 { if (_ag_get_TAG_(exp) != tag)
     _error_(_AGR_ERROR_);
   return exp; }