fixes, performance check

This commit is contained in:
ProgramSnail 2024-11-09 23:32:09 +03:00
parent 0ba3c33af5
commit 34675f0cb7
5 changed files with 40 additions and 8 deletions

View file

@ -45,6 +45,7 @@ struct State {
void **sp; // stack pointer
struct Frame *fp; // function frame pointer
bytefile *bf;
int current_line;
bool is_closure_call;

0
byterun/lamac Normal file
View file

17
byterun/performance_check.sh Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
dune build > /dev/null
echo "Interpreter:"
time echo '0' | lamac -i ../performance/Sort.lama > /dev/null
echo "Stack Machine:"
time echo '0' | lamac -s ../performance/Sort.lama > /dev/null
lamac -b ../performance/Sort.lama > /dev/null
echo "Byterun:"
time ./byterun.exe Sort.bc > /dev/null
rm Sort.*

View file

@ -344,16 +344,18 @@ void run(bytefile *bf, int argc, char **argv) {
}
case 8: // ARRAY %d
Barray((aint *)s.sp, ip_read_int(&s.ip));
s_push_i(&s, Barray_patt(s_pop(&s), BOX(ip_read_int(&s.ip))));
break;
case 9: // FAIL %d %d
Bmatch_failure(s_pop(&s), argv[0], ip_read_int(&s.ip),
ip_read_int(&s.ip));
case 9: { // FAIL %d %d
int line = ip_read_int(&s.ip); // ??
int col = ip_read_int(&s.ip); // ??
Bmatch_failure(s_pop(&s), argv[0], BOX(line), BOX(col));
break;
}
case 10: // LINE %d
ip_read_int(&s.ip);
s.current_line = ip_read_int(&s.ip);
// maybe some metainfo should be collected
break;
@ -413,11 +415,22 @@ void run(bytefile *bf, int argc, char **argv) {
}
case 4: { // CALL Barray %d
size_t n = ip_read_int(&s.ip);
size_t elem_count = ip_read_int(&s.ip);
if (elem_count < 0) {
failure("ARRAY: elements count should be >= 0");
}
void **buffer = calloc(elem_count, sizeof(void *));
for (size_t i = 0; i < elem_count; ++i) {
buffer[elem_count - i - 1] = s_pop(&s);
}
void *array =
Barray((aint *)s.sp, n); // NOTE: not shure if elems should be added
s_popn(&s, n);
Barray((aint *)buffer, BOX(elem_count)); // NOTE: not shure if elems should be added
// s_popn(&s, elem_count);
s_push(&s, array);
free(buffer);
break;
}

View file

@ -30,6 +30,7 @@ static void alloc_state(bytefile *bf, struct State* s) {
s->is_closure_call = false;
s->ip = bf->code_ptr;
s->call_ip = NULL;
s->current_line = 0;
for (size_t i = 0; i < STACK_SIZE; ++i) {
s->stack[i] = NULL;