Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / ASTInterpreter.h
diff options
context:
space:
mode:
Commit051eb93c188c15e3798018165991b0563bdbaa7f (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-22 21:54:07 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-24 19:43:48 +0300
Files6b25fc5883f44d484f8b65021176b6f8ed5306f0 /JSImpl/src/ASTInterpreter.h
IPL-051eb93c188c15e3798018165991b0563bdbaa7f.tar
IPL-051eb93c188c15e3798018165991b0563bdbaa7f.tar.gz
IPL-051eb93c188c15e3798018165991b0563bdbaa7f.zip
Parent11380dc5c1acaa957430c4e00cc04bfc1478248f (diff)
Enhanced tree interpreter
- Added "proper" C++ like variable scoping - Added operator < - Added ++ and --
1 files changed, 17 insertions, 7 deletions
-rw-r--r--JSImpl/src/ASTInterpreter.h24
diff --git a/JSImpl/src/ASTInterpreter.h b/JSImpl/src/ASTInterpreter.h
index 1ffecde..4d5b46f 100644
--- a/JSImpl/src/ASTInterpreter.h
+++ b/JSImpl/src/ASTInterpreter.h
@@ -11,10 +11,10 @@ public:
ASTInterpreter();
~ASTInterpreter();
- typedef double value_type;
- typedef std::stack<value_type> ValueStack;
+ typedef double value_type;
+ typedef IPLStack<value_type> ValueStack;
- ValueStack Run(Expression* program);
+ ValueStack Run(Expression* program);
virtual void Visit(LiteralNull* e) override;
virtual void Visit(LiteralUndefined* e) override;
@@ -36,9 +36,19 @@ public:
virtual void Visit(FunctionDeclaration* e) override;
virtual void Visit(TopStatements* e) override;
virtual void Visit(EmptyExpression* e) override;
+
+ value_type& ModifyVariable(const IPLString& name);
private:
- void RunExpression(const ExpressionPtr& e);
- bool EvalToBool(const ExpressionPtr& e);
- ValueStack m_Evaluation;
- std::unordered_map<std::string, ValueStack> m_Variables;
+ void RunExpression(const ExpressionPtr& e);
+ bool EvalToBool(const ExpressionPtr& e);
+
+ void EnterScope();
+ void LeaveScope();
+ friend struct VariableScope;
+
+ ValueStack m_Evaluation;
+ IPLUnorderedMap<IPLString, ValueStack> m_Variables;
+
+ typedef IPLVector<IPLString> Scope;
+ IPLStack<Scope> m_Scopes;
};