<commit_before>/**
  @file slvm.h
  @brief TODO: Describe this file
  $Revision$
  $HeadURL$
  */
#ifndef SLVM_H
#define SLVM_H

#include <stdint.h>

/* Choose a width for val_t that matches the pointer size of the target
 * architecture. Defaults to simply a long but can be overridden for specific
 * cases */
#if defined(_16BIT_)
    typedef int16_t val_t;
#elif defined(_32BIT_)
    typedef int32_t val_t;
#elif defined(_64BIT_)
    typedef int64_t val_t;
#else
    /* hope for the best? */
    typedef long val_t;
#endif

/**
    The number of bits of the flags field dedicated to holding the size of the
    bytecode vector.
*/
#define CODE_SZ_BITS ((sizeof(val_t) * 8) - 8u)

/**
    This type represents a pointer to a function handler for executing a word.
    For built-in words this typically points to the C function that implements
    the word. For compiled words, this typically points to the docolon function.

    @param code This is a pointer to the next bytecode instruction to execute.
                For built-in words this pointer is 0.
 */
typedef void (*codeword_t)(val_t* code);

/** A collection of flags describing attributes of the word. */
typedef union {
    /** The value of all flag bits combined */
    val_t value;
    /** Accessors for individual flag fields */
    struct {
        /** Flag if this word should be hidden from the interpreter */
        val_t hidden   : 1;
        /** flag if this word should be executed at compile time */
        val_t immed    : 1;
        /** Pads the flags to 8-bits */
        val_t padding  : 6;
        /** The length of the bytecode section of the word */
        val_t codesize : CODE_SZ_BITS;
    } attr;
} flags_t;

/**
    This structure contains all of the relevant attributes of a word definition
*/
typedef struct word_t {
    /** Pointer to the next most recently defined word in the dictionary. */
    struct word_t const* link;
    /** A collection of flags describing attributes of the word. */
    flags_t flags;
    /** Pointer to the null terminated string that holds the name of the word. */
    char const* name;
    /**
     * Pointer to the execution handler for this word. For words defined in C
     * This points to the implementation function. For words defined in
     * bytecode this will point to the docolon function. */
    codeword_t codeword;
    /**
     * A pointer to the list of instructions that make up this word. For words
     * defined in C this will be 0u (NULL). */
    val_t* code;
} word_t;

/** Execute a built-in word directly */
#define EXEC(word) (word).codeword((word).code)

/** The maximum number of entries that can be on the argument stack */
#ifndef ARG_STACK_SIZE
#define ARG_STACK_SIZE 32
#endif

/**
 * Define a built-in word that executes native code */
#define defcode(name_str,c_name,immed,prev)    \
    static void c_name##_code(val_t* code);    \
    static word_t const c_name = {             \
        prev,                                  \
        {.attr = { 0, immed, 0, 0 }},          \
        name_str,                              \<commit_msg>Added a typedef for dictionary definitions<commit_after>/**
  @file slvm.h
  @brief TODO: Describe this file
  $Revision$
  $HeadURL$
  */
#ifndef SLVM_H
#define SLVM_H

#include <stdint.h>

/* Choose a width for val_t that matches the pointer size of the target
 * architecture. Defaults to simply a long but can be overridden for specific
 * cases */
#if defined(_16BIT_)
    typedef int16_t val_t;
#elif defined(_32BIT_)
    typedef int32_t val_t;
#elif defined(_64BIT_)
    typedef int64_t val_t;
#else
    /* hope for the best? */
    typedef long val_t;
#endif

/**
    The number of bits of the flags field dedicated to holding the size of the
    bytecode vector.
*/
#define CODE_SZ_BITS ((sizeof(val_t) * 8) - 8u)

/**
    This type represents a pointer to a function handler for executing a word.
    For built-in words this typically points to the C function that implements
    the word. For compiled words, this typically points to the docolon function.

    @param code This is a pointer to the next bytecode instruction to execute.
                For built-in words this pointer is 0.
 */
typedef void (*codeword_t)(val_t* code);

/** A collection of flags describing attributes of the word. */
typedef union {
    /** The value of all flag bits combined */
    val_t value;
    /** Accessors for individual flag fields */
    struct {
        /** Flag if this word should be hidden from the interpreter */
        val_t hidden   : 1;
        /** flag if this word should be executed at compile time */
        val_t immed    : 1;
        /** Pads the flags to 8-bits */
        val_t padding  : 6;
        /** The length of the bytecode section of the word */
        val_t codesize : CODE_SZ_BITS;
    } attr;
} flags_t;

/**
    This structure contains all of the relevant attributes of a word definition
*/
typedef struct word_t {
    /** Pointer to the next most recently defined word in the dictionary. */
    struct word_t const* link;
    /** A collection of flags describing attributes of the word. */
    flags_t flags;
    /** Pointer to the null terminated string that holds the name of the word. */
    char const* name;
    /**
     * Pointer to the execution handler for this word. For words defined in C
     * This points to the implementation function. For words defined in
     * bytecode this will point to the docolon function. */
    codeword_t codeword;
    /**
     * A pointer to the list of instructions that make up this word. For words
     * defined in C this will be 0u (NULL). */
    val_t* code;
} word_t;

/** This structure defines a dictionary of defined words. */
typedef struct dict_t {
    /** Pointer to the previously loaded dictionary */
    struct dict_t* link;
    /** Pointer to the most recently defined word in this dictionary */
    word_t* words;
} dict_t;

/** Execute a built-in word directly */
#define EXEC(word) (word).codeword((word).code)

/** The maximum number of entries that can be on the argument stack */
#ifndef ARG_STACK_SIZE
#define ARG_STACK_SIZE 32
#endif

/**
 * Define a built-in word that executes native code */
#define defcode(name_str,c_name,immed,prev)    \
    static void c_name##_code(val_t* code);    \
    static word_t const c_name = {             \
        prev,                                  \
        {.attr = { 0, immed, 0, 0 }},          \
        name_str,                              \
{'fraction_non_alphanumeric': 0.08279370952821462, 'fraction_numerical': 0.0077089115016959605, 'mean_word_length': 2.4708400214018194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1259519', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1823, 'n_words': 816}