VOID Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::RemoveAll() { Node* pNode = m_pRoot; while (pNode != m_pNil) { if (!IsNil(pNode->m_pLeft)) { pNode = pNode->m_pLeft; SetNil( &pNode->m_pParent->m_pLeft ); } else if (!IsNil(pNode->m_pRight)) { pNode = pNode->m_pRight; SetNil( &pNode->m_pParent->m_pRight ); } else { Node* pParent = pNode->m_pParent; delete pNode; pNode = pParent; } } m_NodeCount = 0; SetNil(&m_pRoot); }
int prSignalFade(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c, *d, *e; int err; int start, end; float lvl0, lvl1; a = g->sp - 4; b = g->sp - 3; c = g->sp - 2; d = g->sp - 1; e = g->sp; err = slotIntVal(b, &start); if (err) { if (IsNil(b)) start = 0; else return err; } err = slotIntVal(c, &end); if (err) { if (IsNil(c)) end = slotRawObject(a)->size; else return err; } err = slotFloatVal(d, &lvl0); if (err) return err; err = slotFloatVal(e, &lvl1); if (err) return err; signal_fade_range(slotRawObject(a), start, end, lvl0, lvl1); return errNone; }
VOID Set<K,ElementTraits>::RemoveAll() { Node* pNode = m_pRoot; while (pNode != m_pNil) { if (!IsNil(pNode->m_pLeft)) { pNode = pNode->m_pLeft; SetNil( &pNode->m_pParent->m_pLeft ); } else if (!IsNil(pNode->m_pRight)) { pNode = pNode->m_pRight; SetNil( &pNode->m_pParent->m_pRight ); } else { Node* pParent = pNode->m_pParent; delete pNode; pNode = pParent; } } m_NodeCount = 0; SetNil(&m_pRoot); }
int arrayAtIdentityHashInPairs(PyrObject *array, PyrSlot *key) { PyrSlot *slots, *test; unsigned int i, start, end, hash, maxHash; hash = calcHash(key); maxHash = array->size >> 1; start = (hash % maxHash) << 1; end = array->size; slots = array->slots; for (i=start; i<end; i+=2) { test = slots + i; if (IsNil(test) || (test->utag == key->utag && test->ui == key->ui)) { return i; } } end = start - 2; for (i=0; i<=end; i+=2) { test = slots + i; if (IsNil(test) || (test->utag == key->utag && test->ui == key->ui)) { return i; } } return -2; }
void initialize_image_object( struct VMGlobals *g, struct PyrObject *obj, Image *image ) { assert( IsNil( obj->slots ) && IsNil( obj->slots+1 ) ); SharedImage *shared_image_ptr = new SharedImage(image); SetPtr( obj->slots, shared_image_ptr ); // dataptr InstallFinalizer( g, obj, 1, finalize_image_object ); // finalizer }
int prIdentDict_Put(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c; a = g->sp - 2; // dict b = g->sp - 1; // key c = g->sp; // value if(IsNil(b)) return errWrongType; if(IsNil(c)) return errFailed; // will call removeAt return identDictPut(g, slotRawObject(a), b, c); }
/* Parse a parameter. Currently only supports normal ones. */ Param ParseParam(VyObj param, bool opt, bool rest){ VyObj default_val = None(); if(opt){ if(IsType(param, TypeCons)){ VyObj name = ListGet(UNWRAP(param, VyCons), 0); default_val = ListGet(UNWRAP(param, VyCons), 0); param = name; } } Param p = {optional: opt, rest: rest, default_value: default_val, name: UNWRAP(param, VySymbol)}; return p; } /* Find how many actual parameters there are */ int CountParams(VyObj list){ int count = 0; while(!IsNil(list)){ if(!ObjEq(Car(list), CreateSymbol("?")) && !ObjEq(Car(list), CreateSymbol(".."))) count++; list = Cdr(list); } return count; }
typename Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::Node* Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::InsertImpl( CONST K& Key, CONST V& Value ) { Node* pNew = new Node( Key, Value ); pNew->m_pParent = pNew->m_pLeft = pNew->m_pRight = m_pNil; Node* pY = NULL; Node* pX = m_pRoot; while (!IsNil(pX)) { pY = pX; if( KeyElementTraits::CompareLessThan(Key,pX->m_Key) ) pX = pX->m_pLeft; else pX = pX->m_pRight; } pNew->m_pParent = pY; if (pY == 0) m_pRoot = pNew; else if( KeyElementTraits::CompareLessThan(Key,pY->m_Key) ) pY->m_pLeft = pNew; else pY->m_pRight = pNew; return pNew; }
int prArray_OSCBytes(VMGlobals *g, int numArgsPushed) { PyrSlot* a = g->sp; PyrObject *array = a->uo; PyrSlot* args = array->slots; int numargs = array->size; if (numargs < 1) return errFailed; big_scpacket packet; if (IsFloat(args) || IsNil(args) || IsInt(args)) { makeSynthBundle(&packet, args, numargs, false); } else if (IsSym(args) || isKindOfSlot(args, class_string)) { makeSynthMsgWithTags(&packet, args, numargs); } else { return errWrongType; } int size = packet.size(); PyrInt8Array* obj = newPyrInt8Array(g->gc, size, 0, true); obj->size = size; memcpy(obj->b, packet.data(), size); SetObject(a, (PyrObject*)obj); //for (int i=0; i<packet.size()/4; i++) post("%d %08X\n", i, packet.buf[i]); return errNone; }
typename Set<K,ElementTraits>::Node* Set<K,ElementTraits>::InsertImpl( CONST K& Key ) { Node* pNew = new Node( Key ); pNew->m_pParent = pNew->m_pLeft = pNew->m_pRight = m_pNil; Node* pY = NULL; Node* pX = m_pRoot; while (!IsNil(pX)) { pY = pX; if( ElementTraits::CompareLessThan(Key,pX->m_Key) ) pX = pX->m_pLeft; else pX = pX->m_pRight; } pNew->m_pParent = pY; if (pY == 0) m_pRoot = pNew; else if( ElementTraits::CompareLessThan(Key,pY->m_Key) ) pY->m_pLeft = pNew; else pY->m_pRight = pNew; return pNew; }
int p_member(value velt, type telt, value vlist, type tlist) { pword *p; /* we require a list or nil */ Check_List(tlist); /* if the list is empty, we fail */ if(IsNil(tlist)) { Fail; } /* the tail of the list */ p = vlist.ptr + 1; /* must be dereferenced! */ Dereference(p); /* * on backtracking we will get the tail of the list * instead of the list itself */ Remember(2, p->val, p->tag); /* * and we behave as the unification * of the element and the head */ Return_Unify_Pw(velt, telt, vlist.ptr->val, vlist.ptr->tag); }
double LLBC_Variant::AsDouble() const { if (IsNil()) { return 0.0; } else if (IsDict()) { return 0.0; } else if (IsStr()) { return LLBC_Str2Double(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return _holder.raw.doubleVal; } if (IsSignedRaw()) { return static_cast<double>(_holder.raw.int64Val); } return static_cast<double>(_holder.raw.uint64Val); }
int prAscTime(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; PyrSlot *slots = a->uo->slots; if (IsNil(slots + 0)) { SetNil(a); return errNone; } struct tm tm0; if (slotIntVal(slots+0, &tm0.tm_year)) return errWrongType; tm0.tm_year -= 1900; if (slotIntVal(slots+1, &tm0.tm_mon)) return errWrongType; tm0.tm_mon -- ; if (slotIntVal(slots+2, &tm0.tm_mday)) return errWrongType; if (slotIntVal(slots+3, &tm0.tm_hour)) return errWrongType; if (slotIntVal(slots+4, &tm0.tm_min)) return errWrongType; if (slotIntVal(slots+5, &tm0.tm_sec)) return errWrongType; if (slotIntVal(slots+6, &tm0.tm_wday)) return errWrongType; const char *text = asctime(&tm0); int size = strlen(text) - 1; // Discard trailing newline PyrString *strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, text, size); SetObject(a, strobj); return errNone; }
LLBC_Variant &LLBC_Variant::BecomeNil() { if (IsNil()) { return *this; } CleanTypeData(_holder.type); _holder.type = LLBC_VariantType::VT_NIL; return *this; }
int identDictPut(struct VMGlobals *g, PyrObject *dict, PyrSlot *key, PyrSlot *value) { PyrSlot *slot, *newslot; int i, index, size; PyrObject *array; bool knows = IsTrue(dict->slots + ivxIdentDict_know); if (knows && IsSym(key)) { if (slotRawSymbol(key) == s_parent) { slotCopy(&dict->slots[ivxIdentDict_parent],value); g->gc->GCWrite(dict, value); return errNone; } if (slotRawSymbol(key) == s_proto) { slotCopy(&dict->slots[ivxIdentDict_proto],value); g->gc->GCWrite(dict, value); return errNone; } } array = slotRawObject(&dict->slots[ivxIdentDict_array]); if (array->IsImmutable()) return errImmutableObject; if (!isKindOf((PyrObject*)array, class_array)) return errFailed; index = arrayAtIdentityHashInPairs(array, key); slot = array->slots + index; slotCopy(&slot[1],value); g->gc->GCWrite(array, value); if (IsNil(slot)) { slotCopy(slot,key); g->gc->GCWrite(array, key); size = slotRawInt(&dict->slots[ivxIdentDict_size]) + 1; SetRaw(&dict->slots[ivxIdentDict_size], size); if (array->size < size*3) { PyrObject *newarray; newarray = newPyrArray(g->gc, size*3, 0, false); newarray->size = ARRAYMAXINDEXSIZE(newarray); nilSlots(newarray->slots, newarray->size); slot = array->slots; for (i=0; i<array->size; i+=2, slot+=2) { if (NotNil(slot)) { index = arrayAtIdentityHashInPairs(newarray, slot); newslot = newarray->slots + index; slotCopy(&newslot[0],&slot[0]); slotCopy(&newslot[1],&slot[1]); } } SetRaw(&dict->slots[ivxIdentDict_array], newarray); g->gc->GCWriteNew(dict, newarray); // we know newarray is white so we can use GCWriteNew } } return errNone; }
int prIdentDict_PutGet(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c, *d, *slot, *newslot; int i, index, size; PyrObject *dict; PyrObject *array; a = g->sp - 2; // dict b = g->sp - 1; // key c = g->sp; // value d = ++g->sp; // push the stack to save the receiver slotCopy(d,a); dict = slotRawObject(d); array = slotRawObject(&dict->slots[ivxIdentDict_array]); if (!isKindOf((PyrObject*)array, class_array)) { SetNil(a); --g->sp; return errFailed; } index = arrayAtIdentityHashInPairs(array, b); slot = array->slots + index; slotCopy(a,&slot[1]); slotCopy(&slot[1],c); g->gc->GCWrite(array, c); if (IsNil(slot)) { slotCopy(slot,b); g->gc->GCWrite(array, b); size = slotRawInt(&dict->slots[ivxIdentDict_size]) + 1; SetRaw(&dict->slots[ivxIdentDict_size], size); if (array->size < size*3) { PyrObject *newarray; newarray = newPyrArray(g->gc, size*3, 0, true); newarray->size = ARRAYMAXINDEXSIZE(newarray); nilSlots(newarray->slots, newarray->size); slot = array->slots; for (i=0; i<array->size; i+=2, slot+=2) { if (NotNil(slot)) { index = arrayAtIdentityHashInPairs(newarray, slot); newslot = newarray->slots + index; slotCopy(&newslot[0],&slot[0]); slotCopy(&newslot[1],&slot[1]); } } SetRaw(&dict->slots[ivxIdentDict_array], newarray); g->gc->GCWriteNew(dict, newarray); // we know newarray is white so we can use GCWriteNew } } --g->sp; return errNone; }
BOOL Set<K,ElementTraits>::Delete( Node* pZ ) { if (pZ == NULL) return false; Node* pY = NULL; Node* pX = NULL; if (IsNil(pZ->m_pLeft) || IsNil(pZ->m_pRight)) pY = pZ; else pY = Successor(pZ); if (!IsNil(pY->m_pLeft)) pX = pY->m_pLeft; else pX = pY->m_pRight; pX->m_pParent = pY->m_pParent; if (IsNil(pY->m_pParent)) m_pRoot = pX; else if (pY == pY->m_pParent->m_pLeft) pY->m_pParent->m_pLeft = pX; else pY->m_pParent->m_pRight = pX; if (pY->m_Status == Node::Black) DeleteFixup(pX); if (pY != pZ) SwapNode(pY, pZ); if (m_pRoot != NULL) SetNil(&m_pRoot->m_pParent); delete pZ; return true; }
int arrayAtIdentityHashInPairsWithHash(PyrObject *array, PyrSlot *key, int hash) { PyrSlot *slots, *test; unsigned int i, start, end, maxHash; maxHash = array->size >> 1; start = (hash % maxHash) << 1; end = array->size; slots = array->slots; for (i=start; i<end; i+=2) { test = slots + i; if (IsNil(test) || SlotEq(test, key)) return i; } end = start - 2; for (i=0; i<=end; i+=2) { test = slots + i; if (IsNil(test) || SlotEq(test, key)) return i; } return -2; }
int arrayAtIdentityHash(PyrObject *array, PyrSlot *key) { PyrSlot *slots, *test; unsigned int i, start, end, hash, maxHash; hash = calcHash(key); maxHash = array->size; start = hash % maxHash; end = array->size; slots = array->slots; for (i=start; i<end; i++) { test = slots + i; if (IsNil(test) || SlotEq(test, key)) return i; } end = start - 1; for (i=0; i<=end; i++) { test = slots + i; if (IsNil(test) || SlotEq(test, key)) return i; } return -1; }
int identDictPut(struct VMGlobals *g, PyrObject *dict, PyrSlot *key, PyrSlot *value) { PyrSlot *slot, *newslot; int i, index, size; PyrObject *array; bool knows = IsTrue(dict->slots + ivxIdentDict_know); if (knows && IsSym(key)) { if (key->us == s_parent) { slotCopy(&dict->slots[ivxIdentDict_parent],value); g->gc->GCWrite(dict, value); return errNone; } if (key->us == s_proto) { slotCopy(&dict->slots[ivxIdentDict_proto],value); g->gc->GCWrite(dict, value); return errNone; } } array = dict->slots[ivxIdentDict_array].uo; if (!isKindOf((PyrObject*)array, class_array)) return errFailed; index = arrayAtIdentityHashInPairs(array, key); slot = array->slots + index; slotCopy(&slot[1],value); g->gc->GCWrite(array, value); if (IsNil(slot)) { slotCopy(slot,key); g->gc->GCWrite(array, key); size = ++dict->slots[ivxIdentDict_size].ui; if (array->size < size*3) { PyrObject *newarray; newarray = newPyrArray(g->gc, size*3, 0, false); newarray->size = ARRAYMAXINDEXSIZE(newarray); nilSlots(newarray->slots, newarray->size); slot = array->slots; for (i=0; i<array->size; i+=2, slot+=2) { if (NotNil(slot)) { index = arrayAtIdentityHashInPairs(newarray, slot); newslot = newarray->slots + index; slotCopy(&newslot[0],&slot[0]); slotCopy(&newslot[1],&slot[1]); } } dict->slots[ivxIdentDict_array].uo = newarray; g->gc->GCWrite(dict, newarray); } } return errNone; }
typename Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::Node* Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::RightRotate( Node* pNode ) { Assert(pNode != 0); if(pNode == 0) return 0; Node* pLeft = pNode->m_pLeft; pNode->m_pLeft = pLeft->m_pRight; if (!IsNil(pLeft->m_pRight)) pLeft->m_pRight->m_pParent = pNode; pLeft->m_pParent = pNode->m_pParent; if (IsNil(pNode->m_pParent)) m_pRoot = pLeft; else if (pNode == pNode->m_pParent->m_pRight) pNode->m_pParent->m_pRight = pLeft; else pNode->m_pParent->m_pLeft = pLeft; pLeft->m_pRight = pNode; pNode->m_pParent = pLeft; return pNode; }
int prSignalReverse(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c; int err, start, end; a = g->sp - 2; b = g->sp - 1; c = g->sp; err = slotIntVal(b, &start); if (err) { if (IsNil(b)) start = 0; else return err; } err = slotIntVal(c, &end); if (err) { if (IsNil(c)) end = slotRawObject(a)->size; else return err; } signal_reverse_range(slotRawObject(a), start, end); return errNone; }
typename Set<K,ElementTraits>::Node* Set<K,ElementTraits>::RightRotate( Node* pNode ) { Assert(pNode != 0); if(pNode == 0) return 0; Node* pLeft = pNode->m_pLeft; pNode->m_pLeft = pLeft->m_pRight; if (!IsNil(pLeft->m_pRight)) pLeft->m_pRight->m_pParent = pNode; pLeft->m_pParent = pNode->m_pParent; if (IsNil(pNode->m_pParent)) m_pRoot = pLeft; else if (pNode == pNode->m_pParent->m_pRight) pNode->m_pParent->m_pRight = pLeft; else pNode->m_pParent->m_pLeft = pLeft; pLeft->m_pRight = pNode; pNode->m_pParent = pLeft; return pNode; }
static int disconnectSharedMem(VMGlobals *g, PyrObject * object) { int ptrIndex = 0; PyrSlot * ptrSlot = object->slots + ptrIndex; if (IsNil(ptrSlot)) // already disconnected return errNone; assert(IsPtr(ptrSlot)); server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot); delete client; SetNil(ptrSlot); return errNone; }
bool QObjectProxy::eventFilter( QObject * watched, QEvent * event ) { int type = event->type(); if( type == ScMethodCallType ) { ScMethodCallEvent* mce = static_cast<ScMethodCallEvent*>( event ); qscDebugMsg("executing SC method: %s\n", mce->method->name ); scMethodCallEvent( mce ); return true; } else { EventHandlerData eh = eventHandlers.value( type, EventHandlerData() ); if( eh.type == type ) { PyrSymbol *symMethod = eh.method; qscDebugMsg("catching event %i with handler '%s'\n", type, symMethod->name ); InterpretEventFn interpreter = eh.interpretFn; QList<QVariant> args; if( interpreter ) { qscDebugMsg("got interpreter\n"); (this->*interpreter) ( event, args ); } if( eh.direct ) { qscDebugMsg("direct!\n"); PyrSlot result; QtCollider::execute( scObject, symMethod, args, &result ); if( IsNil( &result ) ) return false; else { if( IsFalse( &result ) ) event->ignore(); return true; } } else { qscDebugMsg("indirect\n"); ScMethodCallEvent *e = new ScMethodCallEvent( symMethod, args ); QApplication::postEvent( this, e ); } } return false; } }
int QObjectProxy::getProperty( const char *property, PyrSlot *ret, PyrSlot *retExtra ) { qscDebugMsg("GET: %s\n", property); bool haveExtra = !IsNil( retExtra ); PropertyData p; p.name = property; p.slot = haveExtra ? retExtra : ret; QVariant err( errNone ); syncRequest( GetProperty, QVariant::fromValue<PropertyData>( p ), &err ); if( haveExtra ) slotCopy( ret, retExtra ); qscDebugMsg("GOT: %s\n", property); return err.toInt(); }
int prStrFTime(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 1; PyrSlot *b = g->sp; PyrSlot *slots = a->uo->slots; if (IsNil(slots + 0)) { SetNil(a); return errNone; } struct tm tm0; if (slotIntVal(slots+0, &tm0.tm_year)) return errWrongType; tm0.tm_year -= 1900; if (slotIntVal(slots+1, &tm0.tm_mon)) return errWrongType; tm0.tm_mon --; if (slotIntVal(slots+2, &tm0.tm_mday)) return errWrongType; if (slotIntVal(slots+3, &tm0.tm_hour)) return errWrongType; if (slotIntVal(slots+4, &tm0.tm_min)) return errWrongType; if (slotIntVal(slots+5, &tm0.tm_sec)) return errWrongType; if (slotIntVal(slots+6, &tm0.tm_wday)) return errWrongType; char format[1024]; if (slotStrVal(b, format, 1024)) return errWrongType; char buffer[1024]; if (strftime(buffer, 1024, format, &tm0) != 0) { int size = strlen(buffer); PyrString *strobj = newPyrStringN(g->gc, size, 0, true); memcpy(strobj->s, buffer, size); SetObject(a, strobj); } else { error("could not convert the date to string with the give format"); return errFailed; } return errNone; }
/*ARGSUSED*/ /* check is already made in p_illegal_current_op */ static int p_is_infix_op(value vp, type tp, value assoc, type ta, value name, type tn, value vv, type tv, value module, type tm) { opi *desc; int res; Prepare_Requests if (IsNil(tn)) { name.did = d_.nil; tn = tdict; } if (desc = _visible_anyfix_op(IS_INFIX_OP, name.did, module.did, tm, &res)) { Request_Unify_Integer(vp, tp, GetOpiPreced(desc)); Request_Unify_Atom(assoc, ta, didassoc[GetOpiAssoc(desc)]); Request_Unify_Atom(vv, tv, (res == LOCAL_PROP ? d_.local0 : d_.global0)); Return_Unify; } Fail_; }
uint64 LLBC_Variant::AsUInt64() const { if (IsNil()) { return 0; } else if (IsDict()) { return 0; } else if (IsStr()) { return LLBC_Str2UInt64(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return static_cast<uint64>(_holder.raw.doubleVal); } return _holder.raw.uint64Val; }
bool LLBC_Variant::AsBool() const { if (IsNil()) { return false; } else if (IsDict()) { return false; } else if (IsStr()) { LLBC_String trimedData(LLBC_Trim(_holder.str)); if (trimedData.length() != 4 && trimedData.length() != 5) { return (AsInt64() != 0 ? true : false); } LLBC_String lowerData(LLBC_ToLower(trimedData.c_str())); return (lowerData == "true" ? true : false); } return _holder.raw.uint64Val != 0; }