Archived
1
0
Fork 0

Replaced create_environment with constructor

This commit is contained in:
Brandon Rozek 2018-09-28 09:59:04 -04:00
parent f84b631124
commit 4c2afd779d
5 changed files with 4 additions and 9 deletions

View file

@ -35,7 +35,7 @@ void interpret_file(char* fileName) {
// Interpret the AST
// print_tree(result, 0); // For debugging
struct Environment* env = create_environment();
struct Environment* env = new Environment();
eval_statement(result, env);
delete_environment(env);
delete_tree(result);

View file

@ -136,7 +136,7 @@ struct Value* eval_expression(struct Node* node, struct Environment* env) {
case CALLFUNC:
check_num_nodes(node, 2, "cannot have more than two nodes for a function call.");
tempNode = get_expression(get_value(find_variable(env, node->children[0]->id)));
local_env = create_environment();
local_env = new Environment();
add_variable(local_env,
make_variable(tempNode->children[0]->id, // Get the name of the variable needed for the lambda expression
eval_expression(node->children[1], env)));

View file

@ -48,7 +48,7 @@ void start_shell() {
printf("Welcome to SLOTH Version 0.0.1\n");
printf("Press CTRL+C to Exit\n");
struct Environment* env = create_environment();
struct Environment* env = new Environment();
while (1) {
// Read line from user and input it into the history
char* input = readline("sloth> ");

View file

@ -4,11 +4,6 @@
#include "environment.hpp"
#include "variable.hpp"
struct Environment* create_environment(void) {
struct Environment* env = new Environment();
return env;
}
struct Variable* find_variable(struct Environment* env, std::string id) {
auto result = std::find_if(env->vars.begin(), env->vars.end(),
[id](const Variable* element) {

View file

@ -6,10 +6,10 @@
struct Environment {
std::vector<struct Variable*> vars;
Environment() { }
};
// Variable Lookup Functions
struct Environment* create_environment(void);
void delete_environment(struct Environment* env);
struct Variable* find_variable(struct Environment* env, std::string id);
void add_variable(struct Environment* env, struct Variable* var);