Remove redundant files

This commit is contained in:
Roman Venediktov 2024-07-05 15:00:21 +02:00
parent e74b092f3a
commit deef68d031
12 changed files with 4 additions and 459 deletions

View file

@ -14,44 +14,14 @@ TEST_FLAGS=$(COMMON_FLAGS) -DDEBUG_VERSION
UNIT_TESTS_FLAGS=$(TEST_FLAGS)
INVARIANTS_CHECK_FLAGS=$(TEST_FLAGS) -DFULL_INVARIANT_CHECKS
all: gc64.o runtime64.o printf.o
ar rc runtime.a runtime64.o gc64.o printf.o
all32: gc.o runtime.o
ar rc runtime.a runtime.o gc.o
NEGATIVE_TESTS=$(sort $(basename $(notdir $(wildcard negative_scenarios/*_neg.c))))
$(NEGATIVE_TESTS): %: negative_scenarios/%.c
@echo "Running test $@"
@$(CC) -o $@.o $(COMMON_FLAGS) negative_scenarios/$@.c gc.c
@./$@.o 2> negative_scenarios/$@.err || diff negative_scenarios/$@.err negative_scenarios/expected/$@.err
negative_tests: $(NEGATIVE_TESTS)
unit_tests.o: gc.c gc.h runtime.c runtime.h runtime_common.h virt_stack.c virt_stack.h test_main.c test_util.s
$(CC) -o unit_tests.o $(UNIT_TESTS_FLAGS) gc.c virt_stack.c runtime.c test_main.c test_util.s
invariants_check.o: gc.c gc.h runtime.c runtime.h runtime_common.h virt_stack.c virt_stack.h test_main.c test_util.s
$(CC) -o invariants_check.o $(INVARIANTS_CHECK_FLAGS) gc.c virt_stack.c runtime.c test_main.c test_util.s
invariants_check_debug_print.o: gc.c gc.h runtime.c runtime.h runtime_common.h virt_stack.c virt_stack.h test_main.c test_util.s
$(CC) -o invariants_check_debug_print.o $(INVARIANTS_CHECK_FLAGS) -DDEBUG_PRINT gc.c virt_stack.c runtime.c test_main.c test_util.s
virt_stack.o: virt_stack.h virt_stack.c
$(CC) $(PROD_FLAGS) -c virt_stack.c
all: gc.o runtime.o printf.o
ar rc runtime.a runtime.o gc.o printf.o
gc.o: gc.c gc.h
$(CC) -m32 $(PROD_FLAGS) -c gc.c
gc64.o: gc.c gc.h
$(CC) $(PROD_FLAGS) -c gc.c -o gc64.o
$(CC) $(PROD_FLAGS) -c gc.c -o gc.o
runtime.o: runtime.c runtime.h
$(CC) -m32 $(PROD_FLAGS) -c runtime.c
runtime64.o: runtime.c runtime.h
$(CC) $(PROD_FLAGS) -c runtime.c -o runtime64.o
$(CC) $(PROD_FLAGS) -c runtime.c -o runtime.o
printf.o: printf.S
$(CC) $(PROD_FLAGS) -x assembler-with-cpp -c -g printf.S -o printf.o

View file

@ -1,19 +0,0 @@
### TODO list
- [x] Fix heap&stack&extra_roots dump
- [x] Remove extra and dead code
- [x] Debug print -> DEBUG_PRINT mode
- [x] Check `mmap`/`remap`/...
- [x] Check: `__gc_stack_bot`: same issue as `__gc_stack_top`?
- [x] Check: Can we get rid of `__gc_init` (as an assembly (implement in C instead))? (answer: if we make main in which every Lama file is compiled set `__gc_stack_bottom` to current `ebp` then yes, otherwise we need access to registers)
- [x] Check: runtime tags: should always the last bit be 1? (Answer: not really, however, we still need to distinguish between 5 different options (because unboxed values should have its own value to be returned from `LkindOf`))
- [x] Fix warnings in ML code
- [x] TODO: debug flag doesn't compile
- [x] Sexp: move the tag to be `contents[0]` instead of the word in sexp header; i.e. get rid of sexp as separate data structure
- [x] Run Lama compiler on Lama
- [ ] Add more stress tests (for graph-like structures) to `stdlib/regression` and unit tests
- [ ] Magic constants
- [ ] Normal documentation: a-la doxygen
- [ ] Think: normal debug mode
- [ ] Fix warnings in C code
- [ ] Modes (like FULL_INVARIANTS) -> separate files

View file

@ -1,2 +0,0 @@
ERROR: pop_extra_root: extra_roots are empty
: Success

View file

@ -1,2 +0,0 @@
ERROR: push_extra_roots: extra_roots_pool overflow
: Success

View file

@ -1,2 +0,0 @@
ERROR: pop_extra_root: stack invariant violation
: Success

View file

@ -1,5 +0,0 @@
#include "../gc.h"
#include <stddef.h>
int main () { pop_extra_root((void **)NULL); }

View file

@ -1,7 +0,0 @@
#include "../gc.h"
#include <stddef.h>
int main () {
for (size_t i = 0; i < MAX_EXTRA_ROOTS_NUMBER + 1; ++i) { push_extra_root(NULL); }
}

View file

@ -1,6 +0,0 @@
#include "../gc.h"
int main () {
push_extra_root(NULL);
pop_extra_root((void **)239);
}

View file

@ -1,275 +0,0 @@
#include "gc.h"
#include "runtime_common.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef DEBUG_VERSION
// function from runtime that maps string to int value
extern int LtagHash (char *s);
extern void *Bsexp (int n, ...);
extern void *Barray (int bn, ...);
extern void *Bstring (void *);
extern void *Bclosure (int bn, void *entry, ...);
extern size_t __gc_stack_top, __gc_stack_bottom;
void test_correct_structure_sizes (void) {
// something like induction base
assert((array_size(0) == get_header_size(ARRAY)));
assert((string_size(0) == get_header_size(STRING) + 1)); // +1 is because of '\0'
assert((sexp_size(0) == get_header_size(SEXP) + MEMBER_SIZE));
assert((closure_size(0) == get_header_size(CLOSURE)));
// just check correctness for some small sizes
for (int k = 1; k < 20; ++k) {
assert((array_size(k) == get_header_size(ARRAY) + MEMBER_SIZE * k));
assert((string_size(k) == get_header_size(STRING) + k + 1));
assert((sexp_size(k) == get_header_size(SEXP) + MEMBER_SIZE * (k + 1)));
assert((closure_size(k) == get_header_size(CLOSURE) + MEMBER_SIZE * k));
}
}
void no_gc_tests (void) { test_correct_structure_sizes(); }
// unfortunately there is no generic function pointer that can hold pointer to function with arbitrary signature
extern size_t call_runtime_function (void *virt_stack_pointer, void *function_pointer,
size_t num_args, ...);
# include "virt_stack.h"
virt_stack *init_test () {
__init();
virt_stack *st = vstack_create();
vstack_init(st);
__gc_stack_bottom = (size_t)vstack_top(st);
return st;
}
void cleanup_test (virt_stack *st) {
vstack_destruct(st);
__shutdown();
}
void force_gc_cycle (virt_stack *st) {
__gc_stack_top = (size_t)vstack_top(st) - 4;
gc_alloc(0);
__gc_stack_top = 0;
}
void test_simple_string_alloc (void) {
virt_stack *st = init_test();
for (int i = 0; i < 5; ++i) { vstack_push(st, BOX(i)); }
vstack_push(st, call_runtime_function(vstack_top(st) - 4, Bstring, 1, "abc"));
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_simple_array_alloc (void) {
virt_stack *st = init_test();
// allocate array [ BOX(1) ] and push it onto the stack
vstack_push(st, call_runtime_function(vstack_top(st) - 4, Barray, 2, BOX(1), BOX(1)));
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_simple_sexp_alloc (void) {
virt_stack *st = init_test();
// allocate sexp with one boxed field and push it onto the stack
// calling runtime function Bsexp(BOX(2), BOX(1), LtagHash("test"))
vstack_push(
st, call_runtime_function(vstack_top(st) - 4, Bsexp, 3, BOX(2), BOX(1), LtagHash("test")));
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_simple_closure_alloc (void) {
virt_stack *st = init_test();
// allocate closure with boxed captured value and push it onto the stack
vstack_push(st, call_runtime_function(vstack_top(st) - 4, Bclosure, 3, BOX(1), NULL, BOX(1)));
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_single_object_allocation_with_collection_virtual_stack (void) {
virt_stack *st = init_test();
vstack_push(st,
call_runtime_function(
vstack_top(st) - 4, Bstring, 1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_garbage_is_reclaimed (void) {
virt_stack *st = init_test();
call_runtime_function(vstack_top(st) - 4, Bstring, 1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
force_gc_cycle(st);
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 0));
cleanup_test(st);
}
void test_alive_are_not_reclaimed (void) {
virt_stack *st = init_test();
vstack_push(st,
call_runtime_function(
vstack_top(st) - 4, Bstring, 1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
force_gc_cycle(st);
const int N = 10;
int ids[N];
size_t alive = objects_snapshot(ids, N);
assert((alive == 1));
cleanup_test(st);
}
void test_small_tree_compaction (void) {
virt_stack *st = init_test();
// this one will increase heap size
call_runtime_function(vstack_top(st) - 4, Bstring, 1, "aaaaaaaaaaaaaaaaaaaaaa");
vstack_push(st, call_runtime_function(vstack_top(st) - 4, Bstring, 1, "left-s"));
vstack_push(st, call_runtime_function(vstack_top(st) - 4, Bstring, 1, "right-s"));
vstack_push(st,
call_runtime_function(vstack_top(st) - 4,
Bsexp,
4,
BOX(3),
vstack_kth_from_start(st, 0),
vstack_kth_from_start(st, 1),
LtagHash("tree")));
force_gc_cycle(st);
const int SZ = 10;
int ids[SZ];
size_t alive = objects_snapshot(ids, SZ);
assert((alive == 3));
// check that order is indeed preserved
for (int i = 0; i < alive - 1; ++i) { assert((ids[i] < ids[i + 1])); }
cleanup_test(st);
}
extern size_t cur_id;
size_t generate_random_obj_forest (virt_stack *st, int cnt, int seed) {
srand(seed);
int cur_sz = 0;
size_t alive = 0;
while (cnt) {
--cnt;
if (cur_sz == 0) {
vstack_push(st, BOX(1));
++cur_sz;
continue;
}
size_t pos[2] = {rand() % vstack_size(st), rand() % vstack_size(st)};
size_t field[2];
for (int t = 0; t < 2; ++t) { field[t] = vstack_kth_from_start(st, pos[t]); }
size_t obj;
if (rand() % 2) {
obj = call_runtime_function(
vstack_top(st) - 4, Bsexp, 4, BOX(3), field[0], field[1], LtagHash("test"));
} else {
obj = BOX(1);
}
// whether object is stored on stack
if (rand() % 2 != 0) {
vstack_push(st, obj);
if ((obj & 1) == 0) { ++alive; }
}
++cur_sz;
}
force_gc_cycle(st);
return alive;
}
void run_stress_test_random_obj_forest (int seed) {
virt_stack *st = init_test();
const int SZ = 100000;
size_t expectedAlive = generate_random_obj_forest(st, SZ, seed);
int ids[SZ];
size_t alive = objects_snapshot(ids, SZ);
assert(alive == expectedAlive);
// check that order is indeed preserved
for (int i = 0; i < alive - 1; ++i) { assert((ids[i] < ids[i + 1])); }
cleanup_test(st);
}
#endif
#include <time.h>
int main (int argc, char **argv) {
#ifdef DEBUG_VERSION
no_gc_tests();
test_simple_string_alloc();
test_simple_array_alloc();
test_simple_sexp_alloc();
test_simple_closure_alloc();
test_single_object_allocation_with_collection_virtual_stack();
test_garbage_is_reclaimed();
test_alive_are_not_reclaimed();
test_small_tree_compaction();
time_t start, end;
double diff;
time(&start);
// stress test
for (int s = 0; s < 100; ++s) { run_stress_test_random_obj_forest(s); }
time(&end);
diff = difftime(end, start);
printf("Stress tests took %.2lf seconds to complete\n", diff);
#endif
}

View file

@ -1,40 +0,0 @@
# this is equivalent C-signature for this function
# size_t call_runtime_function(void *stack, void *func_ptr, int num_args, ...)
.globl call_runtime_function
.type call_runtime_function, @function
call_runtime_function:
pushl %ebp
movl %esp, %ebp
# store old stack pointer
movl %esp, %edi
# move esp to point to the virtual stack
movl 8(%ebp), %esp
# push arguments onto the stack
movl 16(%ebp), %ecx # num_args
test %ecx, %ecx
jz f_call # in case function doesn't have any parameters
leal 16(%ebp), %eax # pointer to value BEFORE first argument
leal (%eax,%ecx,4), %edx # pointer to last argument (right-to-left)
push_args_loop:
pushl (%edx)
subl $4, %edx
subl $1, %ecx
jnz push_args_loop
# call the function
f_call:
movl 12(%ebp), %eax
call *%eax
# restore the old stack pointer
movl %edi, %esp
# pop the old frame pointer and return
popl %ebp # epilogue
ret

View file

@ -1,34 +0,0 @@
#include "virt_stack.h"
#include <malloc.h>
virt_stack *vstack_create () { return malloc(sizeof(virt_stack)); }
void vstack_destruct (virt_stack *st) { free(st); }
void vstack_init (virt_stack *st) {
st->cur = RUNTIME_VSTACK_SIZE;
st->buf[st->cur] = 0;
}
void vstack_push (virt_stack *st, size_t value) {
if (st->cur == 0) { assert(0); }
--st->cur;
st->buf[st->cur] = value;
}
size_t vstack_pop (virt_stack *st) {
if (st->cur == RUNTIME_VSTACK_SIZE) { assert(0); }
size_t value = st->buf[st->cur];
++st->cur;
return value;
}
void *vstack_top (virt_stack *st) { return st->buf + st->cur; }
size_t vstack_size (virt_stack *st) { return RUNTIME_VSTACK_SIZE - st->cur; }
size_t vstack_kth_from_start (virt_stack *st, size_t k) {
assert(vstack_size(st) > k);
return st->buf[RUNTIME_VSTACK_SIZE - 1 - k];
}

View file

@ -1,33 +0,0 @@
//
// Created by egor on 24.04.23.
//
#ifndef LAMA_RUNTIME_VIRT_STACK_H
#define LAMA_RUNTIME_VIRT_STACK_H
#define RUNTIME_VSTACK_SIZE 100000
#include <assert.h>
#include <stddef.h>
struct {
size_t buf[RUNTIME_VSTACK_SIZE + 1];
size_t cur;
} typedef virt_stack;
virt_stack *vstack_create ();
void vstack_destruct (virt_stack *st);
void vstack_init (virt_stack *st);
void vstack_push (virt_stack *st, size_t value);
size_t vstack_pop (virt_stack *st);
void *vstack_top (virt_stack *st);
size_t vstack_size (virt_stack *st);
size_t vstack_kth_from_start (virt_stack *st, size_t k);
#endif //LAMA_RUNTIME_VIRT_STACK_H