| 147 | } |
| 148 | |
| 149 | txInteger fxToInteger(txMachine* the, txSlot* theSlot) |
| 150 | { |
| 151 | #if mxOptimize |
| 152 | if (XS_INTEGER_KIND == theSlot->kind) |
| 153 | return theSlot->value.integer; // this is the case over 90% of the time, so avoid the switch |
| 154 | #endif |
| 155 | |
| 156 | again: |
| 157 | switch (theSlot->kind) { |
| 158 | case XS_UNDEFINED_KIND: |
| 159 | case XS_NULL_KIND: |
| 160 | theSlot->kind = XS_INTEGER_KIND; |
| 161 | theSlot->value.integer = 0; |
| 162 | break; |
| 163 | case XS_BOOLEAN_KIND: |
| 164 | theSlot->kind = XS_INTEGER_KIND; |
| 165 | if (theSlot->value.boolean == 0) |
| 166 | theSlot->value.integer = 0; |
| 167 | else |
| 168 | theSlot->value.integer = 1; |
| 169 | break; |
| 170 | case XS_INTEGER_KIND: |
| 171 | break; |
| 172 | case XS_NUMBER_KIND: |
| 173 | theSlot->kind = XS_INTEGER_KIND; |
| 174 | theSlot->value.integer = fxNumberToInteger(theSlot->value.number); |
| 175 | mxFloatingPointOp("number to integer"); |
| 176 | break; |
| 177 | case XS_STRING_KIND: |
| 178 | case XS_STRING_X_KIND: |
| 179 | theSlot->kind = XS_NUMBER_KIND; |
| 180 | theSlot->value.number = fxStringToNumber(the, theSlot->value.string, 1); |
| 181 | mxMeterOne(); |
| 182 | goto again; |
| 183 | case XS_SYMBOL_KIND: |
| 184 | mxTypeError("cannot coerce symbol to integer"); |
| 185 | break; |
| 186 | case XS_REFERENCE_KIND: |
| 187 | fxToPrimitive(the, theSlot, XS_NUMBER_HINT); |
| 188 | goto again; |
| 189 | default: |
| 190 | mxTypeError("cannot coerce to integer"); |
| 191 | break; |
| 192 | } |
| 193 | return theSlot->value.integer; |
| 194 | } |
| 195 | |
| 196 | void fxNumber(txMachine* the, txSlot* theSlot, txNumber theValue) |
| 197 | { |
no test coverage detected