<commit_before>#include <stdlib.h>
#include <stdarg.h>

#include <kernel/tty.h>
#include <kernel/vga.h>
#include <kernel/system.h>     // TODO - move readline out of here

#include <primitives.h>
#include <forth/resources.h>
#include <stack_machine/common.h>
#include <stack_machine/context.h>
#include <stack_machine/entry.h>
#include <stack_machine/error.h>

#include <util/history.h>
#include <collections/hashtable.h>
#include <collections/stack.h>
#include <collections/list.h>

#include <stack_machine/common.h>


void prompt(context_t *ctx)
{
    if (ctx->state == SMUDGE)
    {
        terminal_writestring("|  ");
    }
    else if (ctx->state == OK || ctx->state == SMUDGE_OK)
    {
        terminal_setcolor(0x0F);
        terminal_writestring("  ok");
        terminal_setcolor(0x07);
        for (int i = 0, n = stack_size(ctx->ds); i < n; i++)
            terminal_putchar('.');

        terminal_putchar('\n');
        ctx->state = NONE;
    }
    terminal_flush();
}

state_t interpret(context_t *ctx, char *in);

context_t *init_context()
{
    context_t *ctx = malloc(sizeof(context_t));
    assert(ctx != NULL);

    ctx->mem = calloc(0, sizeof(byte_t) * 16384);
    assert(ctx->mem != NULL);

    ctx->dp = ctx->mem;
    ctx->ip = ctx->mem;

    ctx->tib = malloc(sizeof(inbuf_t));
    ctx->tib->buffer = malloc(READLINE_BUFSIZ);

    ctx->base = DEFAULT_BASE;
    ctx->echo = DEFAULT_ECHO;
    ctx->state = OK;
    ctx->ds = malloc(sizeof(stack_t));
    stack_init(ctx->ds, free);

    ctx->rs = malloc(sizeof(stack_t));
    stack_init(ctx->rs, free);

    ctx->exe_tok = malloc(sizeof(hashtable_t));
    hashtable_init(ctx->exe_tok, BUCKETS, entry_hash, entry_match, free);

    // primitives
    init_arithmetic_words(ctx);
    init_bit_logic_words(ctx);
    init_comparison_words(ctx);
    init_io_words(ctx);
    init_misc_words(ctx);
    init_stack_manipulation_words(ctx);
    init_memory_words(ctx);

    // bootstrap forth system proper
    char *buf = &system_forth;
    char *saveptr;
    char *line = strtok_r(buf, "\n", &saveptr);

    while (line != NULL)
    {
        interpret(ctx, line);
        line = strtok_r(NULL, "\n", &saveptr);
    }

    return ctx;
}

void mem_stress_test()
{
    void *x;
    int i = 1;
    while (true)
    {
        x = malloc(1024);
        printf("allocated %d bytes at: 0x%x\n", i * 1024, x);
        assert(x != NULL);
        i++;
    }
}
<commit_msg>Fix warnings<commit_after>#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include <kernel/tty.h>
#include <kernel/vga.h>
#include <kernel/system.h>     // TODO - move readline out of here

#include <primitives.h>
#include <forth/resources.h>
#include <stack_machine/common.h>
#include <stack_machine/context.h>
#include <stack_machine/entry.h>
#include <stack_machine/error.h>

#include <util/history.h>
#include <collections/hashtable.h>
#include <collections/stack.h>
#include <collections/list.h>

#include <stack_machine/common.h>


void prompt(context_t *ctx)
{
    if (ctx->state == SMUDGE)
    {
        terminal_writestring("|  ");
    }
    else if (ctx->state == OK || ctx->state == SMUDGE_OK)
    {
        terminal_setcolor(0x0F);
        terminal_writestring("  ok");
        terminal_setcolor(0x07);
        for (int i = 0, n = stack_size(ctx->ds); i < n; i++)
            terminal_putchar('.');

        terminal_putchar('\n');
        ctx->state = NONE;
    }
    terminal_flush();
}

state_t interpret(context_t *ctx, char *in);

context_t *init_context()
{
    context_t *ctx = malloc(sizeof(context_t));
    assert(ctx != NULL);

    ctx->mem = calloc(0, sizeof(byte_t) * 16384);
    assert(ctx->mem != NULL);

    ctx->dp = ctx->mem;
    ctx->ip = ctx->mem;

    ctx->tib = malloc(sizeof(inbuf_t));
    ctx->tib->buffer = malloc(READLINE_BUFSIZ);

    ctx->base = DEFAULT_BASE;
    ctx->echo = DEFAULT_ECHO;
    ctx->state = OK;
    ctx->ds = malloc(sizeof(stack_t));
    stack_init(ctx->ds, free);

    ctx->rs = malloc(sizeof(stack_t));
    stack_init(ctx->rs, free);

    ctx->exe_tok = malloc(sizeof(hashtable_t));
    hashtable_init(ctx->exe_tok, BUCKETS, entry_hash, entry_match, free);

    // primitives
    init_arithmetic_words(ctx);
    init_bit_logic_words(ctx);
    init_comparison_words(ctx);
    init_io_words(ctx);
    init_misc_words(ctx);
    init_stack_manipulation_words(ctx);
    init_memory_words(ctx);

    // bootstrap forth system proper
    char *buf = (char*) &system_forth;
    char *saveptr;
    char *line = strtok_r(buf, "\n", &saveptr);

    while (line != NULL)
    {
        interpret(ctx, line);
        line = strtok_r(NULL, "\n", &saveptr);
    }

    return ctx;
}

void mem_stress_test()
{
    void *x;
    int i = 1;
    while (true)
    {
        x = malloc(1024);
        printf("allocated %d bytes at: 0x%x\n", i * 1024, x);
        assert(x != NULL);
        i++;
    }
}

{'fraction_non_alphanumeric': 0.15903960599220193, 'fraction_numerical': 0.009029345372460496, 'mean_word_length': 2.995081967213115, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 82, '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': '3720303', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1770, 'n_words': 346}