initial commit

This commit is contained in:
klein panic
2025-02-14 18:02:53 -05:00
commit fecabb81a7
10 changed files with 1729 additions and 0 deletions

27
include/vm.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef VM_H
#define VM_H
#include <stddef.h>
// Increase registers and memory sizes for advanced programs.
#define NUM_REGISTERS 16 // Number of general-purpose registers.
#define STACK_SIZE 512 // Maximum stack size.
#define PROGRAM_SIZE 2048 // Maximum program size (number of ints).
// VM structure definition.
typedef struct VM {
int registers[NUM_REGISTERS]; // General purpose registers.
int stack[STACK_SIZE]; // Stack memory.
int sp; // Stack pointer (index of next free slot).
int program[PROGRAM_SIZE]; // Bytecode program memory.
size_t program_size; // Number of ints in the loaded program.
size_t pc; // Program counter.
} VM;
// Function prototypes for the VM.
void init_vm(VM *vm);
int load_program(VM *vm, const int *program, size_t size);
void run_vm(VM *vm);
#endif // VM_H