home *** CD-ROM | disk | FTP | other *** search
- /*
- o_array.c
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #include "l_proto.h"
- #include "o_proto.h"
-
- static void
- bind_array(mproc p, eindex ei)
- {
- uint len, i;
-
- if (!(eattr(p,ei) & A_WRITE))
- return;
- len = elen(p, ei);
- for (i = 0; i < len; i++) {
- eindex e = array_get(p, ei, i);
- eptr ep = eaddr(current, e);
- if (eptype(ep) == T_NAME && (epattr(ep) & A_EXECUTABLE)) {
- eindex o;
- if (dict_load(p, e, &o) == OK &&
- etype(p,o) == T_PROC) {
- array_put(p, ei, i, o);
- incref(p, o);
- }
- } else if (eptype(ep) == T_ARRAY && (epattr(ep) & A_EXECUTABLE))
- bind_array(p, e);
- }
- }
-
-
- retcode
- o_array()
- {
- uint len;
-
- load_1_arg(ei, ep);
-
- if (eptype(ep) != T_INT)
- return ERR_TYPE_CHECK;
- if (ep->V.i < 0)
- return ERR_RANGE_CHECK;
- ei = new_array(current, ep->V.i);
- if (!ei)
- return ERR_IMPLEMENTATION_LIMIT;
- decref(current, current->os[current->osp-1]);
- current->os[current->osp-1] = ei;
- return OK;
- }
-
-
- retcode
- o_bind()
- {
- load_1_arg(ei, ep);
-
- if (eptype(ep) != T_ARRAY || !(epattr(ep) & A_EXECUTABLE))
- return ERR_TYPE_CHECK;
- bind_array(current, ei);
- return OK;
- }
-
-
- retcode
- o_makearray()
- {
- eindex ei, *ea, *ip;
- eptr ep;
- ushort i, j;
-
- for (i=current->osp, ip=current->os+i-1; i > 0; i--, ip--)
- if (*ip == mark)
- break;
- if (i==0)
- return ERR_NO_MARK_FOUND;
-
- decref(current, mark);
- *ip = new_array(current, current->osp - i);
- ep = eaddr(current,*ip);
- ea = ep->V.arr.a;
- for (j=current->osp-i, ip++; j > 0; j--)
- *ea++ = *ip++;
- erefcnt(current,null_val) -= current->osp - i;
-
- current->osp = i;
- return OK;
- }
-
- retcode
- o_mark()
- {
- if( current->osp >= MAXOSTACK)
- return ERR_OSTACK_OVERFLOW;
- current->os[current->osp++] = mark;
- incref(current, mark);
- return OK;
- }
-