home *** CD-ROM | disk | FTP | other *** search
- /*
- o_init.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 <stdlib.h>
-
- #include "l_proto.h"
- #include "o_proto.h"
-
-
- static struct built_in_s {
- char *n;
- retcode (*fct)();
- } b[] = {
- {"!", o_exec},
- {"$", o_submit},
- {"%", o_mod},
- {"&", o_and},
- {"`", o_length},
- {"(", o_begin},
- {")", o_end},
- {"*", o_mul},
- {"+", o_add},
- {",", o_currentqueue},
- {"-", o_sub},
- {".", o_currentdict},
- {"/", o_div},
- {":", o_put},
- {";", o_random},
- {"<", o_lt},
- {"=", o_eq},
- {">", o_gt},
- {"?", o_ifelse},
- {"@", o_gmt},
-
- {"A", o_array},
- {"B", o_bind},
- {"C", o_copy},
- {"D", o_dict},
- {"E", o_enter},
- {"F", o_find},
- {"G", o_get},
- {"H", o_halted},
- {"I", o_index},
- {"J", o_exit},
- {"K", o_known},
- {"L", o_loop},
- /* M checksum */
- {"N", o_neg},
- {"O", o_count},
- {"P", o_pop},
- {"Q", o_qstate},
- {"R", o_roll},
- {"S", o_string},
- {"T", o_getattr},
- {"U", o_undef},
- {"V", o_leave},
- {"W", o_setattr},
- {"X", o_exch},
- {"Y", o_type},
- {"Z", o_halt},
- {"[", o_mark},
- {"]", o_makearray},
- {"^", o_xor},
-
- {"|", o_or},
-
- {"~", o_not},
-
- {"_cta", o_toarray},
- {"_cte", o_toextern},
- {"_cti", o_toint},
- {"_ctk", o_tokey},
- {"_ctl", o_toliteral},
- {"_ctm", o_tomsgr},
- {"_ctn", o_toname},
- {"_cts", o_tostring},
- {"_ctt", o_totime},
- {"_ctx", o_toexecutable},
-
- {"_hid", o_hostid},
- {"_stk", o_stack},
-
- {0, 0}
- };
-
-
- eindex loop_mark;
- eindex loop_iproc;
- eindex loop_aproc;
- eindex loop_dproc;
- eindex loop_sproc;
- eindex halt_mark;
- eindex halted_proc;
-
- static struct loops_s {
- eindex *e;
- retcode (*fct)();
- } loops[] = {
- {&loop_iproc, the_loop_iproc},
- {&loop_aproc, the_loop_aproc},
- {&loop_dproc, the_loop_dproc},
- {&loop_sproc, the_loop_sproc},
- {&halted_proc, the_halted_proc}
- };
-
- retcode
- operator_init()
- {
- struct built_in_s *bp;
- eindex ei, ce, fe;
- eptr ep;
- retcode rc;
- int i;
-
- for (bp = b; bp->n; bp++) {
- ce = name_add((byteptr)(bp->n), strlen(bp->n), A_EXECUTABLE);
- fe = new_element(0, T_PROC);
- if (!ce || !fe)
- return ERR_IN_INIT;
- ep = gaddr(fe);
- epattr(ep) |= A_EXECUTABLE;
- ep->V.pro.fct = bp->fct;
- rc = dict_def(0, systemdict, ce, fe);
- if (rc!=OK)
- return rc;
- decref(0, ce);
- decref(0, fe);
- }
-
- halt_mark = new_element(0, T_MARK);
- loop_mark = new_element(0, T_MARK);
-
- for (i=0; i < sizeof(loops)/sizeof(struct loops_s); i++) {
- ei = new_element(0, T_PROC);
- ep = gaddr(ei);
-
- epattr(ep) |= A_EXECUTABLE;
- ep->V.pro.fct = loops[i].fct;
- *(loops[i].e) = ei;
- }
-
- return OK;
- }
-