| 200 | } |
| 201 | |
| 202 | txNumber fxToNumber(txMachine* the, txSlot* theSlot) |
| 203 | { |
| 204 | again: |
| 205 | switch (theSlot->kind) { |
| 206 | case XS_UNDEFINED_KIND: |
| 207 | theSlot->kind = XS_NUMBER_KIND; |
| 208 | theSlot->value.number = C_NAN; |
| 209 | break; |
| 210 | case XS_NULL_KIND: |
| 211 | theSlot->kind = XS_NUMBER_KIND; |
| 212 | theSlot->value.number = 0; |
| 213 | break; |
| 214 | case XS_BOOLEAN_KIND: |
| 215 | theSlot->kind = XS_NUMBER_KIND; |
| 216 | if (theSlot->value.boolean == 0) |
| 217 | theSlot->value.number = 0; |
| 218 | else |
| 219 | theSlot->value.number = 1; |
| 220 | break; |
| 221 | case XS_INTEGER_KIND: |
| 222 | theSlot->kind = XS_NUMBER_KIND; |
| 223 | theSlot->value.number = theSlot->value.integer; |
| 224 | mxFloatingPointOp("integer to number"); |
| 225 | break; |
| 226 | case XS_NUMBER_KIND: |
| 227 | break; |
| 228 | case XS_STRING_KIND: |
| 229 | case XS_STRING_X_KIND: |
| 230 | theSlot->kind = XS_NUMBER_KIND; |
| 231 | theSlot->value.number = fxStringToNumber(the, theSlot->value.string, 1); |
| 232 | mxMeterOne(); |
| 233 | break; |
| 234 | case XS_SYMBOL_KIND: |
| 235 | mxTypeError("cannot coerce symbol to number"); |
| 236 | break; |
| 237 | case XS_REFERENCE_KIND: |
| 238 | fxToPrimitive(the, theSlot, XS_NUMBER_HINT); |
| 239 | goto again; |
| 240 | default: |
| 241 | mxTypeError("cannot coerce to number"); |
| 242 | break; |
| 243 | } |
| 244 | return theSlot->value.number; |
| 245 | } |
| 246 | |
| 247 | void fxString(txMachine* the, txSlot* theSlot, txString theValue) |
| 248 | { |
no test coverage detected