parent
bbb2cb471e
commit
011ed937fe
|
@ -195,6 +195,14 @@ void deleteEnv(struct Environment* e)
|
||||||
if (e->outer) {
|
if (e->outer) {
|
||||||
deleteEnv(e->outer);
|
deleteEnv(e->outer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < e->structCount; i++) {
|
||||||
|
free(e->structDefs[i].name);
|
||||||
|
for (int j = 0; j < e->structDefs[i].fieldCount; j++) {
|
||||||
|
free(e->structDefs[j].names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e->strings) {
|
if (e->strings) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (e->strings[i]) {
|
while (e->strings[i]) {
|
||||||
|
@ -208,6 +216,7 @@ void deleteEnv(struct Environment* e)
|
||||||
free(e->objects);
|
free(e->objects);
|
||||||
e->objects = NULL;
|
e->objects = NULL;
|
||||||
}
|
}
|
||||||
|
free(e->structDefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct symFunc {
|
struct symFunc {
|
||||||
|
|
|
@ -541,8 +541,8 @@ void cleanObject(Object* target)
|
||||||
break;
|
break;
|
||||||
case TYPE_ERROR:
|
case TYPE_ERROR:
|
||||||
#ifndef SIMPLE_ERRORS
|
#ifndef SIMPLE_ERRORS
|
||||||
//free(target->error->context);
|
free(target->error->context);
|
||||||
//free(target->error);
|
free(target->error);
|
||||||
target->error = NULL;
|
target->error = NULL;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -70,9 +70,9 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StructDef def;
|
struct StructDef def;
|
||||||
//def.name = name;
|
|
||||||
def.name = malloc(sizeof(char) * (strlen(name) + 1));
|
def.name = malloc(sizeof(char) * (strlen(name) + 1));
|
||||||
strcpy(def.name, name);
|
strcpy(def.name, name);
|
||||||
|
|
||||||
def.fieldCount = listLength(fields);
|
def.fieldCount = listLength(fields);
|
||||||
def.names = malloc(sizeof(char*) * def.fieldCount);
|
def.names = malloc(sizeof(char*) * def.fieldCount);
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ
|
||||||
}
|
}
|
||||||
|
|
||||||
env->structDefs[env->structCount] = def;
|
env->structDefs[env->structCount] = def;
|
||||||
//printStructDef(&env->structDefs[env->structCount]);
|
|
||||||
env->structCount += 1;
|
env->structCount += 1;
|
||||||
if (env->structCount == env->structCapacity) {
|
if (env->structCount == env->structCapacity) {
|
||||||
struct StructDef* prev = env->structDefs;
|
struct StructDef* prev = env->structDefs;
|
||||||
|
@ -96,8 +95,6 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ
|
||||||
env->structCapacity *= 2;
|
env->structCapacity *= 2;
|
||||||
env->structDefs = malloc(sizeof(struct StructDef) * env->structCapacity);
|
env->structDefs = malloc(sizeof(struct StructDef) * env->structCapacity);
|
||||||
printf("Can malloc\n");
|
printf("Can malloc\n");
|
||||||
//memcpy(env->structDefs, prev, sizeof(struct StructDef) * prevCapacity);
|
|
||||||
//printf("Can memcpy\n");
|
|
||||||
for (int i = 0; i < prevCapacity; i++) {
|
for (int i = 0; i < prevCapacity; i++) {
|
||||||
env->structDefs[i] = prev[i];
|
env->structDefs[i] = prev[i];
|
||||||
}
|
}
|
||||||
|
@ -319,7 +316,6 @@ Object evalList(const Object* obj, struct Environment* env)
|
||||||
cleanObject(&builtIn);
|
cleanObject(&builtIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//struct StructDef *def = NULL;
|
|
||||||
int def = -1;
|
int def = -1;
|
||||||
if (first_form->type == TYPE_SYMBOL) {
|
if (first_form->type == TYPE_SYMBOL) {
|
||||||
struct Environment* outerEnv = env;
|
struct Environment* outerEnv = env;
|
||||||
|
@ -423,7 +419,7 @@ Object reduce(const Object listInitial, const Object func, struct Environment* e
|
||||||
//Object oldTotal = total;
|
//Object oldTotal = total;
|
||||||
total = eval(&funcList, env);
|
total = eval(&funcList, env);
|
||||||
//cleanObject(&oldTotal);
|
//cleanObject(&oldTotal);
|
||||||
//cleanObject(&funcList);
|
cleanObject(&funcList);
|
||||||
//cleanObject(¤t);
|
//cleanObject(¤t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue