Keywords 'break' and 'continue' are working, untested

See #152
This commit is contained in:
2024-12-30 09:50:51 +11:00
parent 6d25beea03
commit b84a70cc34
7 changed files with 252 additions and 32 deletions

View File

@@ -3,6 +3,29 @@
#include "toy_common.h"
#include "toy_ast.h"
//the 'escapes' are lists of data used for processing the 'break' and 'continue' keywords, and can be safely ignored
typedef struct Toy_private_EscapeEntry_t {
unsigned int addr; //the address to write *to*
unsigned int depth; //the current depth
} Toy_private_EscapeEntry_t;
typedef struct Toy_private_EscapeArray {
unsigned int capacity;
unsigned int count;
Toy_private_EscapeEntry_t data[];
} Toy_private_EscapeArray;
//not needed at runtime, so they can be bigger
#ifndef TOY_ESCAPE_INITIAL_CAPACITY
#define TOY_ESCAPE_INITIAL_CAPACITY 32
#endif
#ifndef TOY_ESCAPE_EXPANSION_RATE
#define TOY_ESCAPE_EXPANSION_RATE 4
#endif
TOY_API void* Toy_private_resizeEscapeArray(Toy_private_EscapeArray* ptr, unsigned int capacity);
//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?)
@@ -25,8 +48,11 @@ typedef struct Toy_Routine {
unsigned int subsCapacity;
unsigned int subsCount;
unsigned int currentScopeDepth;
Toy_private_EscapeArray* breakEscapes;
Toy_private_EscapeArray* continueEscapes;
bool panic; //any issues found at this point are compilation errors
} Toy_Routine;
TOY_API void* Toy_compileRoutine(Toy_Ast* ast);