Files
Toy/source/toy_scope.h
Kayne Ruse 9fe6d6b218 WIP bad approach, read more
I build a self-referential system, then tried to copy only parts. I need
to step back and adjust my approach.

'Toy_private_deepCopyValue' and 'Toy_private_deepCopyScope' need to be
ripped out, and I need to simply accept there will be only one instance
of 'Toy_Bucket' that isn't freed until the top-level VM is.

I need an hour's break before I'll tackle this again.

See #163
2025-02-18 13:06:15 +11:00

31 lines
1.2 KiB
C

#pragma once
#include "toy_common.h"
#include "toy_bucket.h"
#include "toy_value.h"
#include "toy_string.h"
#include "toy_table.h"
//wraps Toy_Table, restricting keys to name strings, and handles scopes as a linked list
typedef struct Toy_Scope {
struct Toy_Scope* next;
Toy_Table* table;
unsigned int refCount;
} Toy_Scope;
//handle deep scopes - the scope is stored in the bucket, not the table
TOY_API Toy_Scope* Toy_pushScope(Toy_Bucket** bucketHandle, Toy_Scope* scope);
TOY_API Toy_Scope* Toy_popScope(Toy_Scope* scope);
TOY_API Toy_Scope* Toy_private_pushDummyScope(Toy_Bucket** bucketHandle, Toy_Scope* scope); //doesn't delcare a table for storage
TOY_API Toy_Scope* Toy_private_deepCopyScope(Toy_Bucket** scopeBucketHandle, Toy_Bucket** literalBucketHandle, Toy_Scope* scope);
//manage the contents
TOY_API void Toy_declareScope(Toy_Scope* scope, Toy_String* key, Toy_Value value);
TOY_API void Toy_assignScope(Toy_Scope* scope, Toy_String* key, Toy_Value value);
TOY_API Toy_Value* Toy_accessScopeAsPointer(Toy_Scope* scope, Toy_String* key);
TOY_API bool Toy_isDeclaredScope(Toy_Scope* scope, Toy_String* key);
//TODO: delcare with a custom table (game engine entities)