static QChar safeRead( PyrSlot *slot ) { if (GetTag(slot) == tagChar) return QChar( slotRawChar(slot) ); else return QChar(); }
int prFilePutChar(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b; PyrFile *pfile; FILE *file; char z; a = g->sp - 1; b = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; if (NotChar(b)) return errWrongType; z = slotRawChar(b); SC_IOStream<FILE*> scio(file); scio.writeInt8(z); return errNone; }
static int prSerialPort_Put(struct VMGlobals *g, int numArgsPushed) { PyrSlot *args = g->sp - 1; PyrSlot* self = args+0; SerialPort* port = (SerialPort*)getSerialPort(self); if (port == 0) return errFailed; PyrSlot* src = args+1; int val; if (IsChar(src)) { val = slotRawChar(src); } else { int err = slotIntVal(src, &val); if (err) return err; } bool res = port->put(val & 0xFF); SetBool(self, res); return errNone; }
static QChar read( PyrSlot *slot ) { return QChar( slotRawChar(slot) ); }
int prFileWrite(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *ptr; PyrFile *pfile; FILE *file; PyrObject *obj; char chr; a = g->sp - 1; b = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; switch (GetTag(b)) { case tagInt : { SC_IOStream<FILE*> scio(file); scio.writeInt32_be(slotRawInt(b)); break; } case tagSym : fwrite(slotRawSymbol(b)->name, sizeof(char), slotRawSymbol(b)->length, file); break; case tagChar : chr = slotRawChar(b); fwrite(&chr, sizeof(char), 1, file); break; case tagNil : case tagFalse : case tagTrue : case tagPtr : return errWrongType; case tagObj : { // writes the indexable part of any non obj_slot format object obj = slotRawObject(b); if (!isKindOf(obj, class_rawarray) || isKindOf(obj, class_symbolarray)) return errWrongType; if (obj->size) { ptr = obj->slots; int elemSize = gFormatElemSize[obj->obj_format]; int numElems = obj->size; #if BYTE_ORDER != BIG_ENDIAN switch (elemSize) { case 1: fwrite(ptr, elemSize, numElems, file); break; case 2: { char *ptr = slotRawString(b)->s; char *ptrend = ptr + numElems*2; for (; ptr < ptrend; ptr+=2) { fputc(ptr[1], file); fputc(ptr[0], file); } break; } case 4: { char *ptr = slotRawString(b)->s; char *ptrend = ptr + numElems*4; for (; ptr < ptrend; ptr+=4) { fputc(ptr[3], file); fputc(ptr[2], file); fputc(ptr[1], file); fputc(ptr[0], file); } break; } case 8: { char *ptr = slotRawString(b)->s; char *ptrend = ptr + numElems*8; for (; ptr < ptrend; ptr+=8) { fputc(ptr[7], file); fputc(ptr[6], file); fputc(ptr[5], file); fputc(ptr[4], file); fputc(ptr[3], file); fputc(ptr[2], file); fputc(ptr[1], file); fputc(ptr[0], file); } break; } } #else fwrite(ptr, elemSize, numElems, file); #endif } break; } default : // double { SC_IOStream<FILE*> scio(file); scio.writeDouble_be(slotRawFloat(b)); break; } } return errNone; }
static int addMsgSlotWithTags(big_scpacket *packet, PyrSlot *slot) { switch (GetTag(slot)) { case tagInt : packet->addtag('i'); packet->addi(slotRawInt(slot)); break; case tagSym : packet->addtag('s'); packet->adds(slotRawSymbol(slot)->name); break; case tagObj : if (isKindOf(slotRawObject(slot), class_string)) { PyrString *stringObj = slotRawString(slot); packet->addtag('s'); packet->adds(stringObj->s, stringObj->size); } else if (isKindOf(slotRawObject(slot), class_int8array)) { PyrInt8Array *arrayObj = slotRawInt8Array(slot); packet->addtag('b'); packet->addb(arrayObj->b, arrayObj->size); } else if (isKindOf(slotRawObject(slot), class_array)) { PyrObject *arrayObj = slotRawObject(slot); if (arrayObj->size) { packet->addtag('b'); big_scpacket packet2; if (arrayObj->size > 1 && isKindOfSlot(arrayObj->slots+1, class_array)) { makeSynthBundle(&packet2, arrayObj->slots, arrayObj->size, true); } else { int error = makeSynthMsgWithTags(&packet2, arrayObj->slots, arrayObj->size); if (error != errNone) return error; } packet->addb((uint8*)packet2.data(), packet2.size()); } else { packet->addtag('i'); packet->addi(0); } } break; case tagTrue : packet->addtag('i'); packet->addi(1); break; case tagChar : packet->addtag(slotRawChar(slot)); break; case tagFalse : case tagNil : case tagPtr : packet->addtag('i'); packet->addi(0); break; default : if (gUseDoubles) { packet->addtag('d'); packet->addd(slotRawFloat(slot)); } else { packet->addtag('f'); packet->addf(slotRawFloat(slot)); } break; } return errNone; }