Bitvectors - #35
Bitvectors#35
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new BitVector/BitVectorIterator native class to ListTalk (VM + public C API), along with runtime registration, build integration, and coverage via language-level and C API tests.
Changes:
- Introduces
BitVectorandBitVectorIteratorimplementations with conversion, slicing, bitwise ops, shifting/rotation, and rank/select utilities. - Registers the new native classes in the base environment and exposes the public C API via new headers/umbrella include.
- Adds extensive ListTalk tests and a new C API test for uint8-array endian conversions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/eval-objects.lt | Adds ListTalk-level behavioral tests for BitVector and BitVectorIterator. |
| tests/c_api_test.c | Adds a C API test validating LE/BE packed uint8_t[] conversions. |
| src/vm/base_env/base_env.c | Registers BitVector and BitVectorIterator as native classes in the base environment. |
| src/classes/BitVector.c | New native implementation of BitVector/BitVectorIterator plus public C API helpers. |
| meson.build | Adds src/classes/BitVector.c to the VM library build sources. |
| ListTalk/ListTalk.h | Exposes BitVector via the umbrella public header. |
| ListTalk/classes/BitVector.h | New public header for BitVector C API declarations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| {"BitVector", <_BitVector_class}, | ||
| {"BitVectorIterator", <_BitVectorIterator_class}, |
There was a problem hiding this comment.
Added the missing #include <ListTalk/classes/BitVector.h> in commit Add missing BitVector.h include in base_env.c.
Co-authored-by: adh <44205+adh@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/classes/BitVector.c:370
- BitVector class>>fromUnsignedInteger:size: relies on Integer>>toBytes: for the byte-aligned overflow check. For sizes that are a multiple of 8, overflow will raise Integer's generic "Integer does not fit requested byte count" instead of the BitVector-specific overflow message used for partial-byte sizes (line 368). Consider doing an explicit bit-width overflow validation so this API consistently reports a BitVector-specific error.
byte_length = byte_length_for_bits(size);
bytes = LT_ByteVector_from_value(LT_SEND(
integer,
"toBytes:",
LT_Number_smallinteger_from_size(
byte_length,
"BitVector size out of bounds"
)
));
src/classes/BitVector.c:425
- BitVector class>>fromInteger:size: depends on Integer>>toTwosComplement: for overflow at whole-byte sizes. If the integer doesn't fit in the requested byte count, the error message will come from Integer ("Integer does not fit requested two's-complement byte count") rather than the BitVector-specific "Integer does not fit requested BitVector size" used for partial-byte sizes below. Consider validating the value against the requested bit width to keep error reporting consistent at the BitVector API level.
byte_length = byte_length_for_bits(size);
bytes = LT_ByteVector_from_value(LT_SEND(
integer,
"toTwosComplement:",
LT_Number_smallinteger_from_size(
byte_length,
"BitVector size out of bounds"
)
));
src/classes/BitVector.c:1144
- BitVector>>any?/all?/none? currently counts all set bits for every call via bitvector_predicate, even though these predicates can short-circuit. For large BitVectors, this turns O(1) best-case queries into always-O(n). Consider implementing each predicate with early exit (e.g., any? returns true on first set bit; all? returns false on first unset bit; none? returns false on first set bit).
static LT_Value bitvector_predicate(LT_BitVector* bitvector, int kind){
size_t count = 0;
size_t i;
for (i = 0; i < bitvector->length; i++){
count += (size_t)LT_BitVector_at(bitvector, i);
}
if (kind == 0){
return count != 0 ? LT_TRUE : LT_FALSE;
}
if (kind == 1){
return count == bitvector->length ? LT_TRUE : LT_FALSE;
}
return count == 0 ? LT_TRUE : LT_FALSE;
No description provided.