Skip to content

Commit a375085

Browse files
committed
Partially revert 1ea5177
Turns out that enums are signed and there's no way to make them unsigned (until C23, maybe?) and the signed/not-signed comparisons are a bad idea.
1 parent 1ea5177 commit a375085

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ jobs:
4242
run: sudo apt update
4343
- name: Install Python
4444
run: sudo apt install --yes ${{matrix.PYTHON}}
45-
- name: Install TCC
46-
run: sudo apt install --yes tcc
4745
- name: Run interpreter tests
4846
run: ${{matrix.PYTHON}} scrapscript.py test
4947
- name: Run compiler tests
5048
run: ${{matrix.PYTHON}} compiler_tests.py
51-
- name: Run compiler tests with TCC
52-
run: CC=tcc ${{matrix.PYTHON}} compiler_tests.py
5349
build_docker_image:
5450
runs-on: ubuntu-latest
5551
permissions:

runtime.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,16 @@ struct object {};
3030
// The three low bits make up a primary tag, used to differentiate gc_obj
3131
// from immediate objects. All even tags map to SmallInt, which is
3232
// optimized by checking only the lowest bit for parity.
33-
enum {
34-
kSmallIntTagBits = 1,
35-
kPrimaryTagBits = 3,
36-
kImmediateTagBits = 5,
37-
kWordSize = sizeof(word),
38-
kBitsPerByte = 8,
39-
kBitsPerPointer = kBitsPerByte * kWordSize,
40-
};
33+
static const uword kSmallIntTagBits = 1;
34+
static const uword kPrimaryTagBits = 3;
35+
static const uword kImmediateTagBits = 5;
4136
static const uword kSmallIntTagMask = (1 << kSmallIntTagBits) - 1;
4237
static const uword kPrimaryTagMask = (1 << kPrimaryTagBits) - 1;
4338
static const uword kImmediateTagMask = (1 << kImmediateTagBits) - 1;
4439

45-
static const word kMaxSmallStringLength = kWordSize - 1;
40+
static const uword kWordSize = sizeof(word);
41+
static const uword kMaxSmallStringLength = kWordSize - 1;
42+
static const uword kBitsPerByte = 8;
4643

4744
static const uword kSmallIntTag = 0; // 0b****0
4845
static const uword kHeapObjectTag = 1; // 0b**001
@@ -74,7 +71,6 @@ static ALWAYS_INLINE uword small_string_length(struct object* obj) {
7471
}
7572
static ALWAYS_INLINE struct object* mksmallstring(const char* data,
7673
uword length) {
77-
assert(length >= 0);
7874
assert(length <= kMaxSmallStringLength);
7975
uword result = 0;
8076
for (word i = length - 1; i >= 0; i--) {
@@ -90,7 +86,6 @@ static ALWAYS_INLINE struct object* mksmallstring(const char* data,
9086
}
9187
static ALWAYS_INLINE char small_string_at(struct object* obj, uword index) {
9288
assert(is_small_string(obj));
93-
assert(index >= 0);
9489
assert(index < small_string_length(obj));
9590
// +1 for (length | tag) byte
9691
return ((uword)obj >> ((index + 1) * kBitsPerByte)) & 0xFF;
@@ -346,9 +341,8 @@ size_t trace_heap_object(struct gc_obj* obj, struct gc_heap* heap,
346341
return heap_object_size(obj);
347342
}
348343

349-
enum {
350-
kSmallIntBits = kBitsPerPointer - kSmallIntTagBits,
351-
};
344+
static const uword kBitsPerPointer = kBitsPerByte * kWordSize;
345+
static const word kSmallIntBits = kBitsPerPointer - kSmallIntTagBits;
352346
static const word kSmallIntMinValue = -(((word)1) << (kSmallIntBits - 1));
353347
static const word kSmallIntMaxValue = (((word)1) << (kSmallIntBits - 1)) - 1;
354348

0 commit comments

Comments
 (0)