Delete bytecode codegen, starting from scratch
This commit is contained in:
80
main.cpp
80
main.cpp
@@ -169,88 +169,10 @@ want to export all the symbols, we can namespace them optionally.
|
||||
#include "typechecking.cpp"
|
||||
|
||||
#include "c_language_codegen.cpp"
|
||||
#include "intermediate_representation.cpp"
|
||||
// #include "bytecode_interpreter.cpp"
|
||||
// #include "bytecode_codegen.cpp"
|
||||
|
||||
template<class T, S64 bucket_size>
|
||||
struct Simple_Bucket_Array{
|
||||
struct Bucket{ Bucket *next; T data[bucket_size]; S64 len; };
|
||||
Bucket *first;
|
||||
Bucket *last ;
|
||||
|
||||
void grow(Allocator *allocator){
|
||||
if(!first){
|
||||
Bucket *bucket = exp_alloc_type(allocator, Bucket);
|
||||
bucket->next = 0; bucket->len = 0;
|
||||
first = last = bucket;
|
||||
}
|
||||
|
||||
if(last->len >= bucket_size){
|
||||
Bucket *bucket = exp_alloc_type(allocator, Bucket);
|
||||
bucket->next = 0; bucket->len = 0;
|
||||
last = last->next = bucket;
|
||||
}
|
||||
}
|
||||
|
||||
void add(Allocator *allocator, T item){
|
||||
grow(allocator);
|
||||
last->data[last->len++] = item;
|
||||
}
|
||||
|
||||
struct Iter{
|
||||
Simple_Bucket_Array *ref;
|
||||
Bucket *bucket;
|
||||
T *it;
|
||||
S64 iter_i;
|
||||
S64 i;
|
||||
|
||||
force_inline void next(){
|
||||
if(iter_i >= bucket->len){
|
||||
if(bucket->next){
|
||||
bucket = bucket->next;
|
||||
iter_i = 0;
|
||||
}
|
||||
else{
|
||||
it = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
it = bucket->data + iter_i++;
|
||||
i += 1;
|
||||
}
|
||||
force_inline B32 should_continue(){ return it != 0; }
|
||||
};
|
||||
|
||||
force_inline Iter iter(){
|
||||
if(!this->first || this->first->len == 0) return {};
|
||||
return {this, this->first, this->first->data, 1};
|
||||
}
|
||||
};
|
||||
|
||||
function void
|
||||
test_bucket_arrays(){
|
||||
Scratch scratch;
|
||||
Simple_Bucket_Array<int, 4> a = {};
|
||||
for(int i = 0; i < 32; i++)
|
||||
a.add(scratch, i);
|
||||
|
||||
For_It(a){
|
||||
assert(*it.it == it.i);
|
||||
}
|
||||
|
||||
for(auto i = a.iter(); i.should_continue(); i.next()){
|
||||
assert(*i.it == i.i);
|
||||
}
|
||||
|
||||
int total_i = 0;
|
||||
for(auto bucket = a.first; bucket; bucket=bucket->next){
|
||||
for(int i = 0; i < bucket->len; i++){
|
||||
assert(bucket->data[i] == total_i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argument_count, char **arguments){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user