summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/ContextManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/ContextManager.cpp')
-rw-r--r--Sencha-lang/ContextManager.cpp61
1 files changed, 15 insertions, 46 deletions
diff --git a/Sencha-lang/ContextManager.cpp b/Sencha-lang/ContextManager.cpp
index 3a753d9..56ae10f 100644
--- a/Sencha-lang/ContextManager.cpp
+++ b/Sencha-lang/ContextManager.cpp
@@ -8,69 +8,38 @@
#include "ContextManager.h"
ContextManager::ContextManager() {
+ contexts["global"] = new Context("global");
index = 0;
}
ContextManager::~ContextManager() {
}
-void ContextManager::register_function(std::string name, PointerToNativeFunction f)
-{
- registered_functions[name] = f;
-}
-
-SenchaObject ContextManager::execute_native_function(std::string name, std::vector<ASTExpression *> arguments)
-{
- SenchaObject result;
- if(registered_functions.count(name) == 1)
- result = registered_functions[name](arguments);
- return result;
-}
-
-ObjectIndex ContextManager::add_to_store(SenchaObject & object)
+Context * ContextManager::create_new_context()
{
+ Context * context = new Context("Zdzislaw" + to_string(index));
index++;
- object_store[index] = object;
-
- return index;
+ contexts[context->name] = context;
+ return context;
}
-SenchaObject ContextManager::get_from_store(ObjectIndex index)
+Context * ContextManager::get_context(std::string name)
{
- return object_store[index];
+ return contexts[name];
}
-void ContextManager::add(std::string name, SenchaObject object)
+Context * ContextManager::context(std::string name)
{
- interpreter_context[name] = add_to_store(object);
+ if(contexts.count(name) != 0) return contexts[name];
+ else return nullptr;
}
-void ContextManager::set(std::string name, SenchaObject object)
+void ContextManager::destroy_context(std::string name)
{
- if(interpreter_context[name] != 0)
- {
- object_store[interpreter_context[name]] = object;
- }
- else
+ auto iter = contexts.find(name);
+ if(iter != contexts.end())
{
- add(name, object);
-
+ delete (*iter);
+ contexts.erase(iter);
}
}
-
-SenchaObject ContextManager::get(std::string name)
-{
- return get_from_store(interpreter_context[name]);
-}
-
-std::string ContextManager::debug() {
- std::string debug_note = "";
-
- for( auto iter = this->interpreter_context.begin(); iter != this->interpreter_context.end(); iter++)
- {
- debug_note += "Context: " + to_string((*iter).second) + ": " + (*iter).first + " " + object_store[(*iter).second].repr() + "\n";
- }
- return debug_note;
-
-
- }