<commit_before>#include <stdlib.h>
#include <time.h>
#include <errno.h>

#include "vm.h"
#include "instns/instn.h"
#include "bytecode.h"


void debug_vm(vm_t* vm, vm_debug_data_t* debug_data)
{
    instn_t instn;

    while (1)
    {
        if (!vm->procedures)
        {
            int n_events = vm_fire_events(vm);
            if (n_events < 0)
            {
                break;
            }
            if (n_events == 0)
            {
                continue;
            }
        }

        proc_t* proc = vm_current_procedure(vm);
        if (!proc)
        {
            continue;
        }

        if (vm_decode_instn(vm, proc, &instn) < 0)
        {
            break;
        }

        if (vm_exec_instn(vm, &instn) < 0)
        {
            break;
        }

        vm->instns++;
        vm->instns_since_last_cleanup++;

        if (vm->instns_since_last_cleanup % VM_CLEANUP_PERIOD_INSTNS == 0)
        {
            cleanup_vm(vm);
        }
    }

    cleanup_vm(vm);
}
<commit_msg>debugger repl skeleton<commit_after>#include <stdlib.h>
#include <time.h>
#include <errno.h>

#include "vm.h"
#include "instns/instn.h"
#include "bytecode.h"


#define F_RUNNING   0x1

typedef struct _dbg_state_t
{
    vm_t* vm;
    vm_debug_data_t* data;
    unsigned flags;
}
dbg_state_t;


static void print_init_message(dbg_state_t* state);
static char* read_command();
static int exec_command(char* cmdline, dbg_state_t* state);


void debug_vm(vm_t* vm, vm_debug_data_t* debug_data)
{
    dbg_state_t state;
    state.vm = vm;
    state.data = debug_data;
    state.flags = 0;

    print_init_message(&state);
    while (1)
    {
        char* cmd = read_command();
        if (!cmd)
        {
            break;
        }

        if (exec_command(cmd, &state) < 0)
        {
            break;
        }
    }

    cleanup_vm(vm);
}


static void print_init_message(dbg_state_t* state)
{
    printf("BVGZ VM Debugger\n");
    printf("Code: %u bytes | Mem: %u bytes\n",
        state->vm->codesz, state->vm->memsz);
    printf("Code lines: %u\n", state->data->n_code_lines);
    printf("Mem symbols: %u\n", state->data->n_mem_lines);
    printf("Labels: %u\n", state->data->n_labels);
    printf("Files: %u\n", state->data->n_files);
}


static char* read_command()
{
    return NULL;
}


static int exec_command(char* cmdline, dbg_state_t* state)
{
    return -1;
}

{'fraction_non_alphanumeric': 0.1342281879194631, 'fraction_numerical': 0.0050335570469798654, 'mean_word_length': 2.045977011494253, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3547660', 'n_tokens_mistral': 901, 'n_tokens_neox': 868, 'n_words': 169}