Added scope structures.

Not yet used in exec.c.
This commit is contained in:
Jacob Signorovitch 2025-04-26 09:45:46 -04:00
parent ff68b756ef
commit 2d01b09ee9
2 changed files with 43 additions and 0 deletions

19
src/include/scope.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef SCOPE_H
#define SCOPE_H
#include "htab.h"
// Represents the reverse linked tree of scope.
typedef struct SCOPE_T {
HTab* here;
struct SCOPE_T* inherit;
} Scope;
// Create a new `Scope`.
Scope* scope_init(HTab* here, Scope* inherit);
// Destroy all linked `Scope`s this inherits from.
void scope_destroy(Scope* scope);
// Destroy the current `Scope` only.
void scope_destroy_psv(Scope *scope);
#endif

24
src/scope.c Normal file
View File

@ -0,0 +1,24 @@
#include "include/scope.h"
#include "include/htab.h"
#include <stdlib.h>
Scope* scope_init(HTab* here, Scope* inherit) {
Scope* scope = malloc(sizeof(Scope));
scope->here = here;
scope->inherit = inherit;
return scope;
}
void scope_destroy(Scope* scope) {
htab_destroy(scope->here);
if (scope->inherit != NULL) scope_destroy(scope->inherit);
free(scope);
}
void scope_destroy_psv(Scope* scope) {
htab_destroy(scope->here);
scope->inherit = NULL;
free(scope);
}