From 4c2afd779d5d24a294758cba9584a73f1d788316 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Fri, 28 Sep 2018 09:59:04 -0400 Subject: [PATCH] Replaced create_environment with constructor --- src/main.cpp | 2 +- src/operations/node.cpp | 2 +- src/shell.cpp | 2 +- src/variables/environment.cpp | 5 ----- src/variables/environment.hpp | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c685853..2a851ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/operations/node.cpp b/src/operations/node.cpp index 8b04673..a0ea5d5 100644 --- a/src/operations/node.cpp +++ b/src/operations/node.cpp @@ -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))); diff --git a/src/shell.cpp b/src/shell.cpp index 6c8bb3f..f5de742 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -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> "); diff --git a/src/variables/environment.cpp b/src/variables/environment.cpp index ecb6768..0fb7c94 100644 --- a/src/variables/environment.cpp +++ b/src/variables/environment.cpp @@ -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) { diff --git a/src/variables/environment.hpp b/src/variables/environment.hpp index aa0ea46..c06a5f6 100644 --- a/src/variables/environment.hpp +++ b/src/variables/environment.hpp @@ -6,10 +6,10 @@ struct Environment { std::vector 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);