Added scope structures.
Not yet used in exec.c.
This commit is contained in:
parent
ff68b756ef
commit
2d01b09ee9
19
src/include/scope.h
Normal file
19
src/include/scope.h
Normal 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
24
src/scope.c
Normal 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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user