Files
Toy/source/toy_routine.h
Kayne Ruse 14653a303f Added 'Toy_String' to 'Toy_Value' structure, read more
To help with storing strings within tables, I've replaced the unused
'_padding' member of 'Toy_String' with 'cachedHash', which is set to
zero on string allocation.

The hash of a string isn't generated and stored until it's actually
needed, as the rope pattern means not every string needs a hash -
hopefully this will save unnecessarily wasted time.

When a hash of a string is needed, the hashing function first checks to
see if that string already has one, and if so, returns it. Again, less
time wasted.

When generating a new string hash, the hashing function takes the
string's type into account, as node-based strings first need their
contents assembled into a simple char buffer.

Other changes include:

* Changed 'TOY_VALUE_TO_*' to 'TOY_VALUE_FROM_*'
* Changed 'TOY_VALUE_IS_EQUAL' to 'TOY_VALUES_ARE_EQUAL'
* Added a missing '#pragma once' to 'toy_print.h'
2024-10-07 17:35:31 +11:00

31 lines
825 B
C

#pragma once
#include "toy_common.h"
#include "toy_ast.h"
//internal structure that holds the individual parts of a compiled routine
typedef struct Toy_Routine {
unsigned char* param; //c-string params in sequence (could be moved below the jump table?)
unsigned int paramCapacity;
unsigned int paramCount;
unsigned char* code; //the instruction set
unsigned int codeCapacity;
unsigned int codeCount;
unsigned int* jumps; //each 'jump' is the starting address of an element within 'data'
unsigned int jumpsCapacity;
unsigned int jumpsCount;
unsigned char* data; //{type,val} tuples of data
unsigned int dataCapacity;
unsigned int dataCount;
unsigned char* subs; //subroutines, recursively
unsigned int subsCapacity;
unsigned int subsCount;
} Toy_Routine;
TOY_API void* Toy_compileRoutine(Toy_Ast* ast);