Files
Toy/source/toy_stack.h
Kayne Ruse 3148a56ce0 Added simple assignment, read more
I was coding earlier this week, but my brain was so foggy I ended up not
knowing what I was doing. After a few days break, I've cleaned up the
mess, which took hours.

Changes:
* Variables can be assigned
* Added new value types as placeholders
* Added 'compare' and 'assign' to the AST
* Added duplicate opcode
* Added functions to copy and free values
* Max name length is 255 chars
* Compound assigns are squeezed into one word

To be completed:

* Tests for this commit's changes
* Compound assignments
* Variable access
2024-10-25 22:48:24 +11:00

36 lines
953 B
C

#pragma once
#include "toy_common.h"
#include "toy_value.h"
typedef struct Toy_Stack { //32 | 64 BITNESS
unsigned int capacity; //4 | 4
unsigned int count; //4 | 4
Toy_Value data[]; //- | -
} Toy_Stack; //8 | 8
TOY_API Toy_Stack* Toy_allocateStack();
TOY_API void Toy_freeStack(Toy_Stack* stack);
TOY_API void Toy_pushStack(Toy_Stack** stackHandle, Toy_Value value);
TOY_API Toy_Value Toy_peekStack(Toy_Stack** stackHandle);
TOY_API Toy_Value Toy_popStack(Toy_Stack** stackHandle);
//some useful sizes, could be swapped out as needed
#ifndef TOY_STACK_INITIAL_CAPACITY
#define TOY_STACK_INITIAL_CAPACITY 8
#endif
#ifndef TOY_STACK_EXPANSION_RATE
#define TOY_STACK_EXPANSION_RATE 2
#endif
#ifndef TOY_STACK_CONTRACTION_RATE
#define TOY_STACK_CONTRACTION_RATE (1 / 4)
#endif
//prevent an infinite expansion, limited to 1MB
#ifndef TOY_STACK_OVERFLOW
#define TOY_STACK_OVERFLOW (1024 * 1024 / sizeof(Toy_Value))
#endif