mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
The following structures are now more independant: - Toy_Array - Toy_Stack - Toy_Bucket - Toy_String I reworked a lot of the memory allocation, so now there are more direct calls to malloc() or realloc(), rather than relying on the macros from toy_memory.h. I've also split toy_memory into proper array and bucket files, because it makes more sense this way, rather than having them both jammed into one file. This means the eventual hashtable structure can also stand on its own. Toy_Array is a new wrapper around raw array pointers, and all of the structures have their metadata embedded into their allocated memory now, using variable length array members. A lot of 'capacity' and 'count' variables were changed to 'size_t' types, but this doesn't seem to be a problem anywhere. If the workflow fails, then I'll leave it for tonight - I'm too tired, and I don't want to overdo myself.
44 lines
886 B
C
44 lines
886 B
C
#pragma once
|
|
|
|
#include "toy_common.h"
|
|
|
|
#include "toy_stack.h"
|
|
|
|
typedef struct Toy_VM {
|
|
//hold the raw bytecode
|
|
unsigned char* bc;
|
|
int bcSize;
|
|
|
|
//raw instructions to be executed
|
|
unsigned char* routine;
|
|
int routineSize;
|
|
|
|
int paramCount;
|
|
int jumpsCount;
|
|
int dataCount;
|
|
int subsCount;
|
|
|
|
int paramAddr;
|
|
int codeAddr;
|
|
int jumpsAddr;
|
|
int dataAddr;
|
|
int subsAddr;
|
|
|
|
int routineCounter;
|
|
|
|
//heap - block-level key/value pairs
|
|
//TODO: needs string util for identifiers
|
|
|
|
//stack - immediate-level values only
|
|
Toy_Stack* stack;
|
|
} Toy_VM;
|
|
|
|
TOY_API void Toy_bindVM(Toy_VM* vm, unsigned char* bytecode, int bytecodeSize); //process the version data
|
|
TOY_API void Toy_bindVMToRoutine(Toy_VM* vm, unsigned char* routine); //process the routine only
|
|
|
|
TOY_API void Toy_runVM(Toy_VM* vm);
|
|
TOY_API void Toy_freeVM(Toy_VM* vm);
|
|
TOY_API void Toy_resetVM(Toy_VM* vm);
|
|
|
|
//TODO: inject extra data
|