void fxDebugID(txMachine* the, txError theError, txString theFormat, txID theID) { char aBuffer[16]; txString aString = aBuffer; txSlot* aSymbol; aSymbol = fxGetSymbol(the, theID); if (aSymbol) aString = aSymbol->value.symbol.string; else if (theID != XS_NO_ID) fxIntegerToString(theID, aBuffer, sizeof(aBuffer)); else c_strcpy(aBuffer, "?"); fxDebug(the, theError, theFormat, aString); }
txString fxToString(txMachine* the, txSlot* theSlot) { char aBuffer[256]; again: switch (theSlot->kind) { case XS_UNDEFINED_KIND: fxCopyStringC(the, theSlot, "undefined"); break; case XS_NULL_KIND: fxCopyStringC(the, theSlot, "null"); break; case XS_BOOLEAN_KIND: if (theSlot->value.boolean == 0) fxCopyStringC(the, theSlot, "false"); else fxCopyStringC(the, theSlot, "true"); break; case XS_INTEGER_KIND: fxCopyStringC(the, theSlot, fxIntegerToString(the->dtoa, theSlot->value.integer, aBuffer, sizeof(aBuffer))); break; case XS_NUMBER_KIND: fxCopyStringC(the, theSlot, fxNumberToString(the->dtoa, theSlot->value.number, aBuffer, sizeof(aBuffer), 0, 0)); break; case XS_SYMBOL_KIND: mxTypeError("Cannot coerce symbol to string"); break; case XS_STRING_KIND: case XS_STRING_X_KIND: break; case XS_REFERENCE_KIND: fxToPrimitive(the, theSlot, XS_STRING_HINT); goto again; default: mxTypeError("Cannot coerce to string"); break; } return theSlot->value.string; }
void fxIDToString(txMachine* the, txInteger id, txString theBuffer, txSize theSize) { if (id < 0) { id &= 0x7FFF; if (id < the->keyCount) { txSlot* key = the->keyArray[id]; if (key) { if ((key->kind == XS_KEY_KIND) || (key->kind == XS_KEY_X_KIND)) snprintf(theBuffer, theSize, "%s", key->value.key.string); else if ((key->kind == XS_STRING_KIND) || (key->kind == XS_STRING_X_KIND)) snprintf(theBuffer, theSize, "[%s]", key->value.string); else c_strcpy(theBuffer, ""); } else c_strcpy(theBuffer, ""); } else c_strcpy(theBuffer, "?"); } else fxIntegerToString(the->dtoa, id, theBuffer, theSize); }
void fxIDToSlot(txMachine* the, txInteger id, txSlot* slot) { if (id < 0) { txSlot* key = fxGetKey(the, (txID)id); if (key && (key->flag & XS_DONT_ENUM_FLAG)) { if (key->kind == XS_KEY_KIND) { slot->kind = XS_STRING_KIND; slot->value.string = key->value.key.string; } else { slot->kind = XS_STRING_X_KIND; slot->value.string = key->value.key.string; } } else { slot->kind = XS_SYMBOL_KIND; slot->value.ID = (txID)id; } } else { char buffer[16]; fxCopyStringC(the, slot, fxIntegerToString(the->dtoa, id, buffer, sizeof(buffer))); } }
void fxSerializeJSONInteger(txMachine* the, txJSONSerializer* theSerializer, txInteger theInteger) { char aBuffer[256]; fxIntegerToString(theInteger, aBuffer, sizeof(aBuffer)); fxSerializeJSONChars(the, theSerializer, aBuffer); }