Skip to content

Commit

Permalink
XS: fix issue #62
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet authored and mkellner committed Nov 22, 2018
1 parent 1b0e80a commit 4e4874d
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions xs/sources/xsRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -2605,11 +2605,16 @@ void fxRunID(txMachine* the, txSlot* generator, txID id)
if (slot->kind == mxStack->kind) {
if (mxStack->kind == XS_INTEGER_KIND) {
#if __has_builtin(__builtin_add_overflow)
if (__builtin_add_overflow(slot->value.integer, mxStack->value.integer, &slot->value.integer)) {
variable = mxStack;
mxPushKind(XS_INTEGER_KIND);
if (__builtin_add_overflow(slot->value.integer, variable->value.integer, &mxStack->value.integer)) {
fxToNumber(the, slot);
fxToNumber(the, mxStack);
slot->value.number += mxStack->value.number;
fxToNumber(the, variable);
slot->value.number += variable->value.number;
}
else
slot->value.integer = mxStack->value.integer;
mxStack++;
#else
txInteger a = slot->value.integer;
txInteger b = mxStack->value.integer;
Expand Down Expand Up @@ -2662,13 +2667,27 @@ void fxRunID(txMachine* the, txSlot* generator, txID id)
if (slot->kind == mxStack->kind) {
if (slot->kind == XS_INTEGER_KIND) {
#if __has_builtin(__builtin_sub_overflow)
if (__builtin_sub_overflow(slot->value.integer, mxStack->value.integer, &slot->value.integer)) {
variable = mxStack;
mxPushKind(XS_INTEGER_KIND);
if (__builtin_sub_overflow(slot->value.integer, variable->value.integer, &mxStack->value.integer)) {
fxToNumber(the, slot);
fxToNumber(the, variable);
slot->value.number -= variable->value.number;
}
else
slot->value.integer = mxStack->value.integer;
mxStack++;
#else
txInteger a = slot->value.integer;
txInteger b = -mxStack->value.integer;
txInteger c = a + b;
if (((a ^ c) & (b ^ c)) < 0) {
fxToNumber(the, slot);
fxToNumber(the, mxStack);
slot->value.number -= mxStack->value.number;
}
#else
slot->value.integer -= mxStack->value.integer; // @@ overflow?
else
slot->value.integer = c;
#endif
}
else if (slot->kind == XS_NUMBER_KIND)
Expand Down

0 comments on commit 4e4874d

Please sign in to comment.