/*------------------------------------------------------------------------*/ 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_); }
_NIL_TYPE_ _env_setup_(const _SIZ_TYPE_ siz) { _SIZ_TYPE_ idx; _NAMES_ = _ag_make_TAB_(siz); DCT_top = 1; DCT_siz = siz; for (idx = 1; idx <= DCT_siz; idx++) _ag_set_TAB_EXP_(_NAMES_, idx, _VOID_); }
_EXP_TYPE_ _env_initialise_(const _EXP_TYPE_ dct) { _EXP_TYPE_ env, top, stk; _mem_claim_SIZ_(_STK_INIT_); _CRO_ = _VOID_; //TOEGEVOEGD env = _ag_make_ENV_(); stk = _ag_make_TAB_(_STK_INIT_); top = _ag_make_NBR_(_STK_INIT_ + 1); _ag_set_ENV_DCT_(env, dct); _ag_set_ENV_BOT_(env, _ZERO_); _ag_set_ENV_TOP_(env, top); _ag_set_ENV_TAB_(env, stk); return env; }
_RES_TYPE_ _PICO_INIT_(const _ADR_TYPE_ adr, const _SIZ_TYPE_ siz) { _SIZ_TYPE_ max = siz/_EXP_SIZE_; assert(sizeof(long) == 4); assert(sizeof(double) == 8); if (max < _GLOBAL_SIZE_) return _MEM_ERROR_; _mem_setup_(adr, max); ROOT = _ag_make_TAB_(ROOT_SIZE); ENVIRONMENT = _ag_make_TAB_(_MAX_SES_); for (SES_IDX = 0 ; SES_IDX < _MAX_SES_ ; SES_IDX++) { SES_TAB[SES_IDX].ses = -1; /* zero gave problems in session zero -- DVD */ CTX_VOID(SES_IDX); } _env_setup_((_SIZ_TYPE_)(max*_NAM_FRACT_)); GLOBAL = _nat_install_(); _ag_set_TAB_EXP_(ROOT, GLOBAL_ROOT, GLOBAL); _ag_set_TAB_EXP_(ROOT, NAMES_ROOT, _NAMES_); _ag_set_TAB_EXP_(ROOT, ENVIRONMENT_ROOT, ENVIRONMENT); _STK_MAX_ = (_UNS_TYPE_)(max*_STK_FRACT_); STATUS = ENABLED; return _PICO_DONE_; }
_NIL_TYPE_ _env_save_(const _EXP_TYPE_ env) { _EXP_TYPE_ bot, exp, stk, top; _UNS_TYPE_ adr, idx, lwn, siz, upn; siz = _ag_get_TAB_SIZ_(_STK_); // _mem_claim_SIZ_(siz); // dvd: would corrupt, cfr CLL adr = (_UNS_TYPE_)_mem_cast_raw_(_STK_, _TAB_TAG_); lwn = 1 + (_EXP_ - adr)/_EXP_SIZE_; upn = 1 + (_CNT_ - adr)/_EXP_SIZE_; bot = _ag_make_NBU_(lwn); top = _ag_make_NBU_(upn); stk = _ag_make_TAB_(siz); for (idx = 1 ; idx <= siz ; idx++) { exp = _ag_get_TAB_EXP_(_STK_, idx); _ag_set_TAB_EXP_(stk, idx, exp); } _ag_set_ENV_DCT_(env, _DCT_); _ag_set_ENV_BOT_(env, bot); _ag_set_ENV_TOP_(env, top); _ag_set_ENV_TAB_(env, stk); }
_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; }
/*------------------------------------------------------------------------*/ _NIL_TYPE_ _eval_CAL_(_NIL_TYPE_) { _EXP_TYPE_ act, arg, dct, exp, frm, fun, nam, par, tab, xdc, xfu; _CNT_TYPE_ cnt; _TAG_TYPE_ tag, xtg; _UNS_TYPE_ siz, xsz; _stk_claim_(); _stk_peek_EXP_(arg); tag = _ag_get_TAG_(arg); if (tag != _TAB_TAG_) { _stk_zap_EXP_(); _stk_peek_EXP_(fun); _error_msg_(_NAT_ERROR_, _ag_get_FUN_NAM_(fun)); } siz = _ag_get_TAB_SIZ_(arg); _mem_claim_SIZ_(siz); _stk_pop_EXP_(arg); if (siz == 0) { _stk_peek_EXP_(fun); par = _ag_get_FUN_ARG_(fun); tag = _ag_get_TAG_(par); switch (tag) { case _VAR_TAG_: case _APL_TAG_: dct = _ag_make_DCT_(); par = _ag_get_FUN_ARG_(fun); nam = _ag_get_VAR_NAM_(par); _ag_set_DCT_NAM_(dct, nam); _ag_set_DCT_VAL_(dct, _EMPTY_); xdc = _ag_get_FUN_DCT_(fun); _ag_set_DCT_DCT_(dct, xdc); break; case _TAB_TAG_: xsz = _ag_get_TAB_SIZ_(par); if (xsz == 0) dct = _ag_get_FUN_DCT_(fun); else _error_msg_(_NMA_ERROR_, _ag_get_FUN_NAM_(fun)); break; default: _error_msg_(_IPM_ERROR_, _ag_get_FUN_NAM_(fun)); } exp = _ag_get_FUN_EXP_(fun); _stk_zap_CNT_(); _stk_peek_CNT_(cnt); if (cnt != RET) { _stk_poke_EXP_(_DCT_); _stk_push_EXP_(exp); _stk_push_CNT_(RET); } else _stk_poke_EXP_(exp); _stk_push_CNT_(EXP); _DCT_ = dct; } else { dct = _ag_make_DCT_(); _stk_peek_EXP_(fun); par = _ag_get_FUN_ARG_(fun); exp = _ag_get_FUN_EXP_(fun); xdc = _ag_get_FUN_DCT_(fun); tag = _ag_get_TAG_(par); switch (tag) { case _VAR_TAG_: nam = _ag_get_VAR_NAM_(par); _ag_set_DCT_NAM_(dct, nam); _ag_set_DCT_DCT_(dct, xdc); _stk_poke_EXP_(exp); _stk_push_EXP_(dct); _stk_push_EXP_(arg); tab = _ag_make_TAB_(siz); act = _ag_get_TAB_EXP_(arg, 1); _stk_push_EXP_(tab); _stk_push_EXP_(_ONE_); _stk_push_EXP_(act); _stk_poke_CNT_(ATV); _stk_push_CNT_(EXP); break; case _APL_TAG_: nam = _ag_get_APL_NAM_(par); _ag_set_DCT_NAM_(dct, nam); _ag_set_DCT_DCT_(dct, xdc); _stk_poke_EXP_(exp); _stk_push_EXP_(dct); _stk_push_EXP_(arg); tab = _ag_make_TAB_(siz); _stk_push_EXP_(tab); _stk_push_EXP_(_ONE_); _stk_push_EXP_(par); _stk_poke_CNT_(ATA); break; case _TAB_TAG_: xsz = _ag_get_TAB_SIZ_(par); if (siz != xsz) _error_msg_(_NMA_ERROR_, _ag_get_FUN_NAM_(fun)); frm = _ag_get_TAB_EXP_(par, 1); xtg = _ag_get_TAG_(frm); switch (xtg) { case _VAR_TAG_: act = _ag_get_TAB_EXP_(arg, 1); _stk_poke_EXP_(exp); _stk_push_EXP_(par); _stk_push_EXP_(arg); _stk_push_EXP_(_ONE_); nam = _ag_get_VAR_NAM_(frm); _ag_set_DCT_NAM_(dct, nam); _ag_set_DCT_DCT_(dct, xdc); _stk_push_EXP_(dct); _stk_push_EXP_(act); _stk_poke_CNT_(BND); _stk_push_CNT_(EXP); break; case _APL_TAG_: xfu = _ag_make_FUN_(); par = _ag_get_FUN_ARG_(fun); exp = _ag_get_FUN_EXP_(fun); xdc = _ag_get_FUN_DCT_(fun); act = _ag_get_TAB_EXP_(arg, 1); frm = _ag_get_TAB_EXP_(par, 1); _stk_poke_EXP_(exp); _stk_push_EXP_(par); _stk_push_EXP_(arg); _stk_push_EXP_(_ONE_); nam = _ag_get_APL_NAM_(frm); arg = _ag_get_APL_ARG_(frm); _ag_set_DCT_NAM_(dct, nam); _ag_set_DCT_DCT_(dct, xdc); _stk_push_EXP_(dct); _ag_set_FUN_NAM_(xfu, nam); _ag_set_FUN_ARG_(xfu, arg); _ag_set_FUN_EXP_(xfu, act); _ag_set_FUN_DCT_(xfu, _DCT_); _stk_push_EXP_(xfu); _stk_poke_CNT_(BND); break; default: _error_msg_(_IPM_ERROR_, _ag_get_FUN_NAM_(fun)); } break; default: _error_msg_(_IPM_ERROR_, _ag_get_FUN_NAM_(fun)); }}}
/*-------------------------------------------------------------------------*/ 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_); }