#include #include #include "system.h" # include "stdio.h" # include "defines.h" # include "object.h" # include "dict.h" # include "operator.h" # include "error.h" #include "path.h" static struct object stack[DICT_STACK_LIMIT] ; static int stacktop ; void dict_invalid(char *mem_bound) { int i ; for ( i=0 ; icur ; i++ ){ /*changed for speed with operators*/ if(dict->dictent[i].key.value.v_string.chars == kptr) return(dict->dictent[i].value); } return(none) ; } struct object odictget(struct dict *dict, struct object key) { register int i; for(i=0;icur; i++) if(equal(dict->dictent[i].key,key) == TRUE) return(dict->dictent[i].value); return(none); } struct object dictstackget(struct object key, char *errorname) { struct object object ; int i ; for ( i=stacktop-1 ; i>=0 ; i-- ){ object = dictget(stack[i].value.v_dict,key) ; if ( object.type != OB_NONE ) return(object); /*was break*/ } if ( object.type == OB_NONE && errorname != NULL ){ fprintf(stderr,"key %d:leng %d %s\n",key.type,key.value.v_string.length, key.value.v_string.chars); pserror(errorname, "dictstackget") ; } return(object) ; } void dictstackinit(void) { int i ; char c; struct object systemdict , statusd, dummy, name, product, temp; struct object userdict, errordict, symbolencoding; struct dict *charstrings,*scharstrings; true = makebool(TRUE); false = makebool(FALSE); zero = makereal(0.); null = makenull(); systemdict = makedict(9+Op_nel+1) ; Systemdict = systemdict.value.v_dict ; sysdictput(cname("systemdict"),&systemdict) ; sysdictput(cname("true"),&true) ; sysdictput(cname("false"),&false) ; sysdictput(cname("null"),&null) ; if(Op_nel != nNop_nel) pserror("operator tables different size", "dictstackinit"); for ( i=0 ; icur ; i++ ){ if(dict->dictent[i].key.type == key.type && dict->dictent[i].key.value.v_string.chars == key.value.v_string.chars) break ; } if ( i == dict->cur ){ if ( dict->cur >= dict->max ){ fprintf(stderr,"dict max %d %d adding %s ",dict->max, key.type,key.value.v_string.chars); pserror("dictfull", "dictput") ; } SAVEITEM(dict->cur) ; dict->cur++ ; dict->dictent[i].key = key ; } else SAVEITEM(dict->dictent[i].value) ; dict->dictent[i].value = object ; } void sysdictput(struct object key, struct object *object) { int i; SAVEITEM(Systemdict->cur) ; i=Systemdict->cur++; Systemdict->dictent[i].key = key ; Systemdict->dictent[i].value = *object ; } void loaddict(struct dict *dict, struct object key, struct object *object) { int i; SAVEITEM(dict->cur) ; i=dict->cur++; dict->dictent[i].key = key ; dict->dictent[i].value = *object ; } void odictput(struct dict *dict, struct object key, struct object object) { int i ; for ( i=0 ; icur ; i++ ){ if(equal(dict->dictent[i].key, key) == TRUE){ break ; } } if ( i == dict->cur ){ if ( dict->cur >= dict->max ){ fprintf(stderr,"dict max %d %d",dict->max,key.type); pserror("dictfull", "odictput") ; } SAVEITEM(dict->cur) ; dict->cur++ ; dict->dictent[i].key = key ; } else SAVEITEM(dict->dictent[i].value) ; dict->dictent[i].value = object ; } void dictOP(void) { struct object object; object = integer("dict"); push(makedict(object.value.v_int)) ; } void beginOP(void) { struct object object ; object = pop() ; if ( object.type != OB_DICTIONARY ) pserror("typecheck", "begin") ; if ( stacktop == DICT_STACK_LIMIT ) pserror("dictstackoverflow", "begin") ; stack[stacktop++] = object ; } void begin(struct object object) { if ( stacktop == DICT_STACK_LIMIT ) pserror("dictstackoverflow", "begin") ; stack[stacktop++] = object ; } void endOP(void) { if ( stacktop <= 2 ) pserror("stackunderflow", "end") ; --stacktop ; } void maxlengthOP(void) { struct object object ; object = pop() ; if ( object.type != OB_DICTIONARY ) pserror("typecheck", "maxlength") ; push(makeint(object.value.v_dict->max)) ; } void currentdictOP(void) { push(stack[stacktop-1]) ; } void defOP(void) { struct object value, key ; value = pop() ; key = pop() ; if(key.type == OB_NAME)dictput(stack[stacktop-1].value.v_dict,key,value) ; else odictput(stack[stacktop-1].value.v_dict,key,value) ; } void loadOP(void) { push(dictstackget(pop(),"undefined:load")) ; } void knownOP(void) { struct object key, dict, item ; key = pop() ; dict = pop() ; if ( dict.type != OB_DICTIONARY ) pserror("typecheck", "known") ; item = dictget(dict.value.v_dict,key); if ( item.type == OB_NONE ) push(false) ; else push(true) ; } void whereOP(void) { int i ; struct object key, item ; key = pop() ; for ( i=stacktop-1 ; i>=0 ; i-- ){ item = dictget(stack[i].value.v_dict,key); if ( item.type != OB_NONE ) break ; } if ( i >= 0 ){ push(stack[i]) ; push(true) ; } else push(false) ; } void storeOP(void) { int i ; struct object key, value, item ; value = pop() ; key = pop() ; for ( i=stacktop-1 ; i>=0 ; i-- ){ item = dictget(stack[i].value.v_dict,key); if ( item.type != OB_NONE ) break ; } if ( i >= 0 ) dictput(stack[i].value.v_dict,key,value) ; else dictput(stack[stacktop-1].value.v_dict,key,value) ; } void countdictstackOP(void) { push(makeint(stacktop)) ; } void dictstackOP(void) { int i ; struct object array ; array = pop() ; if ( array.type != OB_ARRAY ) pserror("typecheck", "dictstack") ; if ( stacktop > array.value.v_array.length ) pserror("rangecheck", "dictstack") ; for ( i=0 ; i