diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index f8d49be..2735792 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -116,7 +116,8 @@ #method bitAt: index { - "## index 1 - least significant bit" + "## index is 1-based" + ^(self bitShift: (index - 1) negated) bitAnd: 1. } diff --git a/stix/kernel/test-005.st b/stix/kernel/test-005.st index 39672ab..12f554c 100644 --- a/stix/kernel/test-005.st +++ b/stix/kernel/test-005.st @@ -378,7 +378,7 @@ PROCESS TESTING ((-2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump. ((2r1000000000000000000000000000100000000000000000000000000000000000000000000000 bitShift: 13) printStringRadix: 2) dump. -((-2r1111 bitAt: 6) printStringRadix: 2) dump. +((-2r10 bitAt: 1) printStringRadix: 2) dump. " FFI isNil dump. diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c index 722e0e0..db03745 100644 --- a/stix/lib/bigint.c +++ b/stix/lib/bigint.c @@ -1592,6 +1592,23 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) { if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) { + stix_ooi_t v1, v2, v3; + + v1 = STIX_OOP_TO_SMOOI(x); + v2 = STIX_OOP_TO_SMOOI(y); + + if (v2 <= 0) return STIX_SMOOI_TO_OOP(0); + if (v1 >= 0) + { + if (v2 >= XXXXXXXXXX) return STIX_SMOOI_TO_OOP(0); + v3 = ((stix_oow_t)v1 >> (v2 - 1)) & 1; + } + else + { + if (v2 >= XXXXXXXXXX) return STIX_SMOOI_TO_OOP(-1); + v3 = ((~(stix_oow_t)-v1 + 1) >> (v2 - 1)) & 1; + } + return STIX_SMOOI_TO_OOP(v3); } else { diff --git a/stix/lib/exec.c b/stix/lib/exec.c index b177d49..9a32b14 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1208,7 +1208,7 @@ static int prim_integer_bitat (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 2); + STIX_ASSERT (nargs == 1); rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); arg = ACTIVE_STACK_GET(stix, stix->sp); diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h index 9eb3ead..697ffea 100644 --- a/stix/lib/stix-cmn.h +++ b/stix/lib/stix-cmn.h @@ -58,11 +58,6 @@ #endif -#if STIX_SIZEOF___INT128_T > 0 -# undef STIX_SIZEOF___INT128_T -# define STIX_SIZEOF___INT128_T 0 -#endif - /* ========================================================================= * PRIMITIVE TYPE DEFINTIONS * ========================================================================= */