diff --git a/src/include/memory.h b/src/include/memory.h index 0de55cf..76c4c6d 100644 --- a/src/include/memory.h +++ b/src/include/memory.h @@ -9,7 +9,7 @@ class Memory { public: bool contains(string identifier); bool contains_top(string identifier); - void add_scope(void); + void add_scope(ScopeType type); void remove_scope(void); EvalResult get(string identifier); diff --git a/src/include/types.h b/src/include/types.h index 8f7a36e..4049630 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -162,9 +162,12 @@ struct ParseReturn { */ using EvalResult = variant; +enum class ScopeType { Block, Function, For }; + struct Scope { unordered_map vars; int depth; + ScopeType type; }; #endif \ No newline at end of file diff --git a/src/interpreter.cpp b/src/interpreter.cpp index aa2e7d5..b3353d9 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -84,7 +84,7 @@ EvalResult eval(Node &ast, Memory &memory) { return {}; } break; case NodeType::For: { - memory.add_scope(); + memory.add_scope(ScopeType::For); eval(node.children[0], memory); @@ -101,7 +101,7 @@ EvalResult eval(Node &ast, Memory &memory) { return {}; } break; case NodeType::Bloc: { - memory.add_scope(); + memory.add_scope(ScopeType::Block); eval(node.children[0], memory); memory.remove_scope(); return {}; diff --git a/src/memory.cpp b/src/memory.cpp index b20ae52..c89c485 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -21,10 +21,11 @@ bool Memory::contains_top(string identifier) { return top.vars.contains(identifier); } -void Memory::add_scope(void) { +void Memory::add_scope(ScopeType type) { Scope& top = scopes.back(); scopes.emplace_back(); scopes.back().depth = top.depth + 1; + scopes.back().type = type; } void Memory::remove_scope(void) {