int prEvent_IsRest(struct VMGlobals *g, int numArgsPushed) { PyrSlot *dictslots = slotRawObject(g->sp)->slots; PyrSlot *arraySlot = dictslots + ivxIdentDict_array; if (isKindOfSlot(arraySlot, class_array)) { PyrSlot key, typeSlot; static PyrSymbol *s_type = getsym("type"); static PyrSymbol *s_rest = getsym("rest"); PyrSymbol *typeSym; // test 'this[\type] == \rest' first SetSymbol(&key, s_type); identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot); if(!slotSymbolVal(&typeSlot, &typeSym) && typeSym == s_rest) { SetBool(g->sp, 1); return errNone; } else { PyrObject *array = slotRawObject(arraySlot); PyrSymbol *slotSym; static PyrSymbol *s_empty = getsym(""); static PyrSymbol *s_r = getsym("r"); static PyrClass *class_rest = getsym("Rest")->u.classobj; static PyrClass *class_metarest = getsym("Meta_Rest")->u.classobj; PyrSlot *slot; int32 size = array->size; int32 i; slot = array->slots + 1; // scan only the odd items for (i = 1; i < size; i += 2, slot += 2) { if (isKindOfSlot(slot, class_rest) || isKindOfSlot(slot, class_metarest) ) { SetBool(g->sp, 1); return errNone; } else if(!slotSymbolVal(slot, &slotSym)) { if(slotSym == s_empty || slotSym == s_r || slotSym == s_rest ) { SetBool(g->sp, 1); return errNone; } } // why no 'else'? // slotSymbolVal nonzero return = not a symbol; // non-symbols don't indicate rests, so, ignore them. } } } else { return errWrongType; } SetBool(g->sp, 0); return errNone; }
/// Returns whether the slot is considered a rest for \c Event.isRest. static bool slotIsRestlike(PyrSlot* slot) { PyrSymbol * slotSym; if (isKindOfSlot(slot, class_rest) || isKindOfSlot(slot, class_metarest)) { return true; } else if(!slotSymbolVal(slot, &slotSym)) { return slotSym == s_empty || slotSym == s_r || slotSym == s_rest; } // why no 'else'? // slotSymbolVal nonzero return = not a symbol; // non-symbols don't indicate rests, so, ignore them. return false; }
int prEvent_IsRest(struct VMGlobals *g, int numArgsPushed) { PyrSlot *dictslots = slotRawObject(g->sp)->slots; PyrSlot *arraySlot = dictslots + ivxIdentDict_array; static int isRestCount = 0; if (!isKindOfSlot(arraySlot, class_array)) { return errWrongType; } PyrSlot key, typeSlot; PyrSymbol *typeSym; // easy tests first: 'this[\type] == \rest' SetSymbol(&key, s_type); identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot); if(!slotSymbolVal(&typeSlot, &typeSym) && typeSym == s_rest) { SetBool(g->sp, 1); return errNone; } // and, 'this[\isRest] == true' SetSymbol(&key, s_isRest); identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot); if(IsTrue(&typeSlot)) { if (isRestCount == 0) post("\nWARNING: Setting isRest to true in an event is deprecated. See the Rest helpfile for supported ways to specify rests.\n\n"); isRestCount = (isRestCount + 1) % 100; SetBool(g->sp, 1); return errNone; } // failing those, scan slot values for something rest-like PyrObject *array = slotRawObject(arraySlot); SetBool(g->sp, dictHasRestlikeValue(array) ? 1 : 0); return errNone; }