// Dump the contents of the obarray LOCAL void nyx_show_obarray() { LVAL array = getvalue(obarray); LVAL sym; int i; for (i = 0; i < HSIZE; i++) { for (sym = getelement(array, i); sym; sym = cdr(sym)) { LVAL syma = car(sym); printf("_sym_ = "); xlprint(getvalue(s_stdout), syma, TRUE); if (getvalue(syma)) { printf(" _type_ = %s _val_ = ", _types_[ntype(getvalue(syma))]); xlprint(getvalue(s_stdout), getvalue(syma), TRUE); } if (getfunction(syma)) { printf(" _type_ = %s _fun_ = ", _types_[ntype(getfunction(syma))]); xlprint(getvalue(s_stdout), getfunction(syma), TRUE); } printf("\n"); } } }
LOCAL void test_one_env(LVAL environment, int i, char *s) { register LVAL fp,ep; LVAL val; /* check the environment list */ for (fp = environment; fp; fp = cdr(fp)) { /* check that xlenv is good */ if (!consp(fp)) { sprintf(buf,"%s: xlenv 0x%lx, frame 0x%lx, type(frame) %d\n", s, xlenv, fp, ntype(fp)); errputstr(buf); report_exit("xlenv points to a bad list", i); } /* check for an instance variable */ if ((ep = car(fp)) && objectp(car(ep))) { /* do nothing */ } /* check an environment stack frame */ else { for (; ep; ep = cdr(ep)) { /* check that ep is good */ if (!consp(ep)) { sprintf(buf,"%s: fp 0x%lx, ep 0x%lx, type(ep) %d\n", s, fp, ep, ntype(ep)); errputstr(buf); report_exit("car(fp) points to a bad list", i); } /* check that car(ep) is nonnull */ if (!car(ep)) { sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx\n", s, ep, car(ep)); errputstr(buf); report_exit("car(ep) (an association) is NULL", i); } /* check that car(ep) is a cons */ if (!consp(car(ep))) { sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx, type(car(ep)) %d\n", s, ep, car(ep), ntype(car(ep))); errputstr(buf); report_exit("car(ep) (an association) is not a cons", i); } /* check that car(car(ep)) is a symbol */ if (!symbolp(car(car(ep)))) { sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx, car(car(ep)) 0x%lx, type(car(car(ep))) %d\n", s, ep, car(ep), car(car(ep)), ntype(car(car(ep)))); errputstr(buf); report_exit("car(car(ep)) is not a symbol", i); } } } } }
/* * Stash a net name in the extra host hash table. * If a new entry is put in the hash table, deduce what * net the machine is attached to from the net character. * * If the machine is already known, add the given attached * net to those already known. */ static int mstash(char name[], int attnet) { register struct xtrahash *xp; int x; xp = xlocate(name); if (xp == (struct xtrahash *) 0) { printf(gettext("Ran out of machine id spots\n")); return(0); } if (xp->xh_name == NOSTR) { if (midfree >= XHSIZE) { printf(gettext("Out of machine ids\n")); return(0); } xtab[midfree] = xp; xp->xh_name = savestr(name); xp->xh_mid = 0200 + midfree++; } x = ntype(attnet); if (x == 0) xp->xh_attnet |= AN; else xp->xh_attnet |= x; return(xp->xh_mid); }
/* xtype - return type of a thing */ LVAL xtype(void) { LVAL arg; if (!(arg = xlgetarg())) return (NIL); switch (ntype(arg)) { case SUBR: return (a_subr); case FSUBR: return (a_fsubr); case CONS: return (a_cons); case SYMBOL: return (a_symbol); case FIXNUM: return (a_fixnum); case FLONUM: return (a_flonum); case STRING: return (a_string); case OBJECT: return (a_object); case STREAM: return (a_stream); case VECTOR: return (a_vector); case CLOSURE: return (a_closure); case CHAR: return (a_char); case USTREAM: return (a_ustream); case EXTERN: return (exttype(arg)); default: xlfail("bad node type"); return NIL; /* never happens */ } }
int anycomplex P1C(LVAL, x) { LVAL data; data = compounddataseq(x); switch (ntype(data)) { case CONS: for (; consp(data); data = cdr(data)) if (complexp(car(data))) return TRUE; return FALSE; case VECTOR: { int i, n; n = getsize(data); for (i = 0; i < n; i++) if (complexp(getelement(data, i))) return TRUE; return FALSE; } case TVEC: switch (gettvectype(data)) { case CD_CXFIXTYPE: case CD_CXFLOTYPE: case CD_COMPLEX: case CD_DCOMPLEX: return TRUE; default: return FALSE; } default: return FALSE; } }
/* find length of a compound item's data sequence */ int compounddatalen P1C(LVAL, x) { switch (ntype(x)) { case OBJECT: { LVAL n = send_message(x, sk_data_length); if (! fixp(n) || getfixnum(n) < 0) xlerror("bad length", n); return((int) getfixnum(n)); } case CONS: return(llength(x)); case DARRAY: x = getdarraydata(x); if (stringp(x)) xlbadtype(x); /* fall through */ case VECTOR: case TVEC: return(gettvecsize(x)); case SYMBOL: if (null(x)) return(0); default: xlbadtype(x); return(0); } }
/* xstring - return a string consisting of a single character */ LVAL xstring(void) { LVAL arg; /* get the argument */ arg = xlgetarg(); xllastarg(); /* make sure its not NIL */ if (null(arg)) xlbadtype(arg); /* check the argument type */ switch (ntype(arg)) { case STRING: return (arg); case SYMBOL: return (getpname(arg)); case CHAR: buf[0] = (int)getchcode(arg); buf[1] = '\0'; return (cvstring(buf)); case FIXNUM: buf[0] = getfixnum(arg); buf[1] = '\0'; return (cvstring(buf)); default: xlbadtype(arg); return NIL; /* never happens */ } }
/* xsort - built-in function 'sort' */ LVAL xsort(void) { LVAL sortlist(); LVAL list,fcn; /* protect some pointers */ xlstkcheck(2); xlsave(list); xlsave(fcn); /* get the list to sort and the comparison function */ list = xlgalist(); fcn = xlgetarg(); xllastarg(); /* sort the list */ list = sortlist(list,fcn); if (list && (ntype(list) == FREE_NODE)) { stdputstr("error in sort 2"); } /* restore the stack and return the sorted list */ xlpopn(2); return (list); }
/* xtype - return type of a thing */ LVAL xtype() { LVAL arg; if (!(arg = xlgetarg())) return (NIL); switch (ntype(arg)) { case SUBR: return (a_subr); case FSUBR: return (a_fsubr); case CONS: return (a_cons); case SYMBOL: return (a_symbol); case FIXNUM: return (a_fixnum); case FLONUM: return (a_flonum); case STRING: return (a_string); case OBJECT: return (a_object); case STREAM: return (a_stream); case VECTOR: return (a_vector); case CLOSURE: return (a_closure); case CHAR: return (a_char); case USTREAM: return (a_ustream); case STRUCT: return (getelement(arg,0)); default: xlfail("bad node type"); } }
LOCAL VOID pushnextargs P4C(LVAL, fcn, int, n, LVAL, args, int, i) { LVAL *newfp, next, value = NULL; /* build a new argument stack frame */ newfp = xlsp; pusharg(cvfixnum((FIXTYPE)(newfp - xlfp))); pusharg(fcn); pusharg(cvfixnum((FIXTYPE)n)); /* push the arguments and shift the list pointers */ for (next = args; consp(next); next = cdr(next)) { switch (ntype(car(next))) { case VECTOR: value = getelement(car(next), i); break; case TVEC: value = gettvecelement(car(next), i); break; case CONS: value = car(car(next)); rplaca(next, cdr(car(next))); break; } pusharg(value); } /* establish the new stack frame */ xlfp = newfp; }
tryhide() { #ifdef HAS_COM register nodep hidenode; register nodep wheretopatch; if(is_a_revorhide(cursparent) ) cursor = cursparent; grab_range(R_FORCE|R_FLIST); if( c_at_root(sel_node)) { error( ER(10,"hideprogram`Can't hide the whole program") ); } wheretopatch = node_kid(sel_node,sel_first); if( !(ntype_info(ntype(wheretopatch)) & F_LINE ) ) error( ER(11,"badhide`You must select at least a whole line for hiding") ); if( sel_first == sel_last && is_a_revorhide(wheretopatch) ) { change_ntype(wheretopatch, N_HIDE); cursor = wheretopatch; } else { hidenode = l_lower(N_HIDE, 1); cursor = kid1(hidenode); /* the hide comment */ } #endif HAS_COM }
char *OpenDDLParser::parseName( char *in, char *end, Name **name ) { *name = ddl_nullptr; if( ddl_nullptr == in || in == end ) { return in; } // ignore blanks in = lookForNextToken( in, end ); if( *in != '$' && *in != '%' ) { return in; } NameType ntype( GlobalName ); if( *in == '%' ) { ntype = LocalName; } in++; Name *currentName( ddl_nullptr ); Text *id( ddl_nullptr ); in = parseIdentifier( in, end, &id ); if( id ) { currentName = new Name( ntype, id ); if( currentName ) { *name = currentName; } } return in; }
/* xleval - evaluate an xlisp expression (checking for *evalhook*) */ LVAL xleval(LVAL expr) { /* check for control codes */ if (--xlsample <= 0) { xlsample = SAMPLE; oscheck(); } /* check for *evalhook* */ if (getvalue(s_evalhook)) return (evalhook(expr)); /* check for nil */ if (null(expr)) return (NIL); /* dispatch on the node type */ switch (ntype(expr)) { case CONS: return (evform(expr)); case SYMBOL: return (xlgetvalue(expr)); default: return (expr); } }
/* xgensym - generate a symbol */ LVAL xgensym(void) { char sym[STRMAX+11]; /* enough space for prefix and number */ LVAL x; /* get the prefix or number */ if (moreargs()) { x = xlgetarg(); switch (ntype(x)) { case SYMBOL: x = getpname(x); case STRING: strncpy(gsprefix, (char *) getstring(x),STRMAX); gsprefix[STRMAX] = '\0'; break; case FIXNUM: gsnumber = getfixnum(x); break; default: xlerror("bad argument type",x); } } xllastarg(); /* create the pname of the new symbol */ sprintf(sym,"%s%d",gsprefix,gsnumber++); /* make a symbol with this print name */ return (xlmakesym(sym)); }
/* eql - internal eql function */ int eql P2C(LVAL, arg1, LVAL, arg2) { /* compare the arguments */ if (arg1 == arg2) return (TRUE); else if (arg1 != NIL) { switch (ntype(arg1)) { case FIXNUM: return (fixp(arg2) ? getfixnum(arg1)==getfixnum(arg2) : FALSE); #ifdef BIGNUMS case RATIO: return (ratiop(arg2) ? compareratio(arg1, arg2) : FALSE); case BIGNUM: return (bignump(arg2) ? comparebignum(arg1, arg2) == 0 : FALSE); #endif case FLONUM: return (floatp(arg2) ? getflonum(arg1)==getflonum(arg2) : FALSE); case COMPLEX: return (complexp(arg2) ? comparecomplex(arg1,arg2) : FALSE); default: return (FALSE); } } else return (FALSE); }
/* xlputc - put a character to a file or stream */ VOID xlputc P2C(LVAL, fptr, int, ch) { LVAL lptr; FILEP fp; /* TAA MOD -- delete output to NIL and character counting 1/97 */ /* check for output to an unnamed stream */ if (ntype(fptr) == USTREAM) { /* TAA MOD, was ustreamp() */ lptr = consa(cvchar((unsigned char)ch)); if (gettail(fptr)!=NIL) rplacd(gettail(fptr),lptr); else sethead(fptr,lptr); settail(fptr,lptr); } /* otherwise, check for terminal output or file output */ else { fp = getfile(fptr); if (fp == CLOSED) /* TAA MOD -- give error */ xlfail("can't write closed stream"); if (fp == CONSOLE) /* TAA MOD -- for redirecting */ ostputc(ch); else { if ((fptr->n_sflags & S_FORWRITING) == 0) xlerror("can't write read-only file stream", fptr); if ((fptr->n_sflags & S_WRITING) == 0) { /* possible direction change*/ if (fptr->n_sflags & S_READING) { OSSEEKCUR(fp, (getsavech(fptr)?(setsavech(fptr,'\0'),-1L):0L)); } fptr->n_sflags |= S_WRITING; fptr->n_sflags &= ~S_READING; #ifdef BIGNUMS if ((fptr->n_sflags & S_BINARY) == 0) #endif fptr->n_cpos = 0; /* best guess */ } #ifdef BIGNUMS if ((fptr->n_sflags & S_BINARY) == 0) { #endif if (ch == '\n') fptr->n_cpos = 0; else fptr->n_cpos++; #ifdef BIGNUMS } #endif #ifdef OSAGETC if (((fptr->n_sflags & S_BINARY) ? OSPUTC(ch,fp) : OSAPUTC(ch,fp)) == EOF) /* TAA MOD to check for write to RO file */ xlerror("write failed", fptr); #else if (OSPUTC(ch,fp)==EOF) /* TAA MOD to check for write to RO file*/ xlerror("write failed", fptr); #endif } } }
static void optim1(char netstr[], char name[]) { char path[STSIZ], rpath[STSIZ]; register char *cp, *cp2; register int tp, nc; cp = netstr; prefer(cp); *name = '\0'; /* * If the address ultimately points back to us, * just return a null network path. */ if ((int)strlen(cp) > 1 && cp[strlen(cp) - 2] == LOCAL) return; while (*cp != 0) { *path = '\0'; tp = ntype(cp[1]); nc = cp[1]; while (*cp && tp == ntype(cp[1])) { stradd(path, sizeof (path), *cp++); cp++; } switch (netkind(tp)) { default: nstrcpy(rpath, sizeof (rpath), path); break; case IMPLICIT: optimimp(path, rpath); break; case EXPLICIT: optimex(path, rpath); break; } for (cp2 = rpath; *cp2 != 0; cp2++) { stradd(name, BUFSIZ, *cp2); stradd(name, BUFSIZ, nc); } } optiboth(name); prefer(name); }
/* sweep - sweep all unmarked nodes and add them to the free list */ LOCAL void sweep(void) { struct segment *seg; //NODE *p; int n; /* empty the free list */ fnodes = NIL; nfree = 0; /* add all unmarked nodes */ for (seg = segs; seg != NULL; seg = seg->sg_next) { //p = &seg->sg_nodes[0]; NODE *SNT end = 0; NODE * BND(__this, end) p = 0; end = &seg->sg_nodes[0] + seg->sg_size; p = &seg->sg_nodes[0]; for (n = seg->sg_size; n--; p++) { if (!(p->n_flags & MARK)) { switch (ntype(p)) { case STR: if (p->n_strtype == DYNAMIC && p->n_str != NULL) { total -= (long) (strlen(p->n_str)+1); free(p->n_str); } break; case FPTR: if (p->n_fp) fclose(p->n_fp); break; case VECT: if (p->n_vsize) { //sm: total -= (long) (p->n_vsize * sizeof(NODE **)); total -= (long) (p->n_vsize * sizeof(*(p->n_vdata))); // see xlisp.h defn of NODE free(p->n_vdata); } break; } #ifdef DEPUTY memset(&p->n_info, 0, sizeof(p->n_info)); //matth #else rplaca(p,NIL); #endif p->n_type = FREE; p->n_flags = 0; rplacd(p,fnodes); fnodes = p; nfree++; } else p->n_flags &= ~(MARK | LEFT); } p = 0; } }
/* return value of a number coerced to a FLOTYPE */ FLOTYPE makefloat P1C(LVAL, x) { switch (ntype(x)) { case FIXNUM: return ((FLOTYPE) getfixnum(x)); case FLONUM: return getflonum(x); #ifdef BIGNUMS case BIGNUM: return cvtbigflonum(x); case RATIO: return cvtratioflonum(x); #endif } xlerror("not a real number", x); return 0.0; /* never reached */ }
/* livecdr - do we need to follow the cdr? */ LOCAL int livecdr(NODE *n) { switch (ntype(n)) { case SUBR: case FSUBR: case INT: case FLOAT: case STR: case FPTR: case OBJ: case VECT: return (FALSE); case SYM: case LIST: return (cdr(n) != NIL); default: printf("bad node type (%d) found during right scan\n",ntype(n)); osfinish (); exit(1); } /*NOTREACHED*/ }
/* ARRAY-DATA-ADDRESS array */ LVAL xarraydata_addr() { LVAL x = xlgetarg(); xllastarg(); switch (ntype(x)) { case DARRAY: x = getdarraydata(x); /* and drop through */ case VECTOR: case STRING: case TVEC: return newnatptr(gettvecdata(x), x); default: return xlbadtype(x); } }
/* xsendmsg - send a message to an object */ LOCAL LVAL xsendmsg(LVAL obj, LVAL cls, LVAL sym) { LVAL msg=NULL,msgcls,method,val,p; /* look for the message in the class or superclasses */ for (msgcls = cls; msgcls; ) { /* lookup the message in this class */ for (p = getivar(msgcls,MESSAGES); p; p = cdr(p)) if ((msg = car(p)) && car(msg) == sym) goto send_message; /* look in class's superclass */ msgcls = getivar(msgcls,SUPERCLASS); } /* message not found */ xlerror("no method for this message",sym); send_message: /* insert the value for 'self' (overwrites message selector) */ *--xlargv = obj; ++xlargc; /* invoke the method */ if ((method = cdr(msg)) == NULL) xlerror("bad method",method); switch (ntype(method)) { case SUBR: val = (*getsubr(method))(); break; case CLOSURE: if (gettype(method) != s_lambda) xlerror("bad method",method); val = evmethod(obj,msgcls,method); break; default: xlerror("bad method",method); } /* after creating an object, send it the ":isnew" message */ if (car(msg) == k_new && val) { xlprot1(val); xsendmsg(val,getclass(val),k_isnew); xlpop(); } /* return the result value */ return (val); }
/* xlxeval - evaluate an xlisp expression (bypassing *evalhook*) */ LVAL xlxeval(LVAL expr) { /* check for nil */ if (null(expr)) return (NIL); /* dispatch on node type */ switch (ntype(expr)) { case CONS: return (evform(expr)); case SYMBOL: return (xlgetvalue(expr)); default: return (expr); } }
/* equal - internal equal function */ int equal P2C(LVAL, arg1, LVAL, arg2) { FIXTYPE n=0; /* for circularity check -- 6/93 */ /* compare the arguments */ isItEqual: /* turn tail recursion into iteration */ if (arg1 == arg2) return (TRUE); else if (arg1 != NIL) { switch (ntype(arg1)) { case FIXNUM: return (fixp(arg2) ? getfixnum(arg1)==getfixnum(arg2) : FALSE); #ifdef BIGNUMS case RATIO: return (ratiop(arg2) ? compareratio(arg1, arg2) : FALSE); case BIGNUM: return (bignump(arg2) ? comparebignum(arg1, arg2) == 0 : FALSE); #endif case FLONUM: return (floatp(arg2) ? getflonum(arg1)==getflonum(arg2) : FALSE); case COMPLEX: return (complexp(arg2) ? comparecomplex(arg1,arg2) : FALSE); case STRING: /* TAA MOD */ return (stringp(arg2) ? stringcmp(arg1,arg2) : FALSE); case CONS: /* TAA MOD turns tail recursion into iteration */ /* Not only is this faster, but greatly reduces chance */ /* of stack overflow */ #ifdef STSZ if (consp(arg2) && (stchck(), equal(car(arg1),car(arg2)))) #else if (consp(arg2) && equal(car(arg1),car(arg2))) #endif { arg1 = cdr(arg1); arg2 = cdr(arg2); if (++n > nnodes) xlfail("circular list"); goto isItEqual; } return FALSE; default: return (FALSE); } } else return (FALSE); }
unsigned long lisp2ulong P1C(LVAL, x) { unsigned long n = 0; switch (ntype(x)) { case FIXNUM: if (getfixnum(x) < 0) xlbadtype(x); n = getfixnum(x); break; #ifdef BIGNUMS case BIGNUM: if (! cvtbigulong(x, &n)) xlbadtype(x); break; #endif /* BIGNUMS */ default: xlbadtype(x); } return n; }
/* Common Lisp REDUCE function (internal version) */ LVAL reduce P4C(LVAL, fcn,LVAL, sequence, int, has_init, LVAL, initial_value) { LVAL next, result; int i, n; /* protect some pointers */ xlstkcheck(3); xlsave(next); xlsave(result); xlprotect(fcn); switch (ntype(sequence)) { case CONS: next = sequence; if (has_init) result = initial_value; else { result = car(next); next = cdr(next); } for (; consp(next); next = cdr(next)) result = xsfuncall2(fcn, result, car(next)); break; case VECTOR: case TVEC: n = gettvecsize(sequence); i = 0; if (has_init) result = initial_value; else { result = gettvecelement(sequence, 0); i = 1; } for (; i < n; i++) result = xsfuncall2(fcn, result, gettvecelement(sequence, i)); break; default: xlbadtype(sequence); } /* restore the stack frame */ xlpopn(3); return(result); }
/* get compound item's data sequence */ LVAL compounddataseq P1C(LVAL, x) { switch (ntype(x)) { case OBJECT: { LVAL seq = send_message(x, sk_data_seq); if (! listp(seq) && ! vectorp(seq) && ! tvecp(seq)) xlerror("not a sequence", seq); return(seq); } case DARRAY: return(getdarraydata(x)); case CONS: case VECTOR: case TVEC: return(x); case SYMBOL: if (null(x)) return(x); /* fall through */ default: return(xlbadtype(x)); } }
void decl(syn_state *ss) { switch (ss->cur_token) { case DBLTYPE: case INTTYPE: ntype(ss); break; default: ss->error_count++; print_error(ss, "expected a type declaration"); break; } if (ss->cur_token == IDENT) { next_token(ss); } else { ss->error_count++; print_error(ss, "expected an identifier"); } switch (ss->cur_token) { case ASSIGN: case COMMA: case SEMI: decl_tail(ss); break; default: ss->error_count++; print_error(ss, "expected an assignment"); break; } switch (ss->cur_token) { case COMMA: case SEMI: more_decls(ss); break; default: ss->error_count++; print_error(ss, "expected a comma"); break; } }
/* internal predicate */ int compoundp P1C(LVAL, x) { switch (ntype(x)) { case FIXNUM: case FLONUM: case COMPLEX: return(FALSE); case CONS: return(TRUE); case DARRAY: x = getdarraydata(x); if (stringp(x)) return(FALSE); /* fall through */ case VECTOR: case TVEC: return(gettvecsize(x) > 0 ? TRUE :FALSE); case OBJECT: return(kind_of_p(x, getvalue(s_compound_data_proto))); default: return(FALSE); } }
nyx_rval nyx_get_type(LVAL expr) { if (expr==NULL) return nyx_error; switch(ntype(expr)) { case FIXNUM: return nyx_int; case FLONUM: return nyx_double; case STRING: return nyx_string; case VECTOR: { /* make sure it's a vector of sounds */ int i; for(i=0; i<getsize(expr); i++) if (!soundp(getelement(expr, i))) return nyx_error; return nyx_audio; } case CONS: { /* see if it's a list of time/string pairs representing a label track */ if (is_labels(expr)) return nyx_labels; else return nyx_error; } case EXTERN: { if (soundp(expr)) return nyx_audio; } } /* switch */ return nyx_error; }