96 lines
1.4 KiB
C
96 lines
1.4 KiB
C
|
|
#include <debug.h>
|
|
|
|
#include <avl/avl.h>
|
|
|
|
#include <defines/W.h>
|
|
#include <defines/X.h>
|
|
#include <defines/Y.h>
|
|
#include <defines/Z.h>
|
|
|
|
#include <string/new.h>
|
|
#include <string/free.h>
|
|
|
|
#include "variable/new.h"
|
|
#include "variable/compare.h"
|
|
#include "variable/free.h"
|
|
|
|
#include "struct.h"
|
|
#include "new.h"
|
|
|
|
struct scope* new_scope()
|
|
{
|
|
ENTER;
|
|
|
|
struct scope* this = smalloc(sizeof(*this));
|
|
|
|
this->tree = avl_alloc_tree(
|
|
/* comparator: */ compare_variables,
|
|
/* free-er: */ free_variable);
|
|
|
|
// add W:
|
|
{
|
|
struct string* w = new_string("w");
|
|
|
|
void* ptr = avl_insert(this->tree, new_variable(w, W));
|
|
|
|
assert(ptr);
|
|
|
|
free_string(w);
|
|
}
|
|
|
|
// add X:
|
|
{
|
|
struct string* x = new_string("x");
|
|
|
|
void* ptr = avl_insert(this->tree, new_variable(x, X));
|
|
|
|
assert(ptr);
|
|
|
|
free_string(x);
|
|
}
|
|
|
|
// add Y:
|
|
{
|
|
struct string* y = new_string("y");
|
|
|
|
void* ptr = avl_insert(this->tree, new_variable(y, Y));
|
|
|
|
assert(ptr);
|
|
|
|
free_string(y);
|
|
}
|
|
|
|
// add Z:
|
|
{
|
|
struct string* z = new_string("z");
|
|
|
|
void* ptr = avl_insert(this->tree, new_variable(z, Z));
|
|
|
|
assert(ptr);
|
|
|
|
free_string(z);
|
|
}
|
|
|
|
EXIT;
|
|
return this;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|