56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
|
/*
|
||
|
* Context.h
|
||
|
*
|
||
|
* Created on: Dec 7, 2012
|
||
|
* Author: attero
|
||
|
*/
|
||
|
|
||
|
#ifndef CONTEXT_H_
|
||
|
#define CONTEXT_H_
|
||
|
#include <map>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <iostream>
|
||
|
#include "Elements/SenchaObject.h"
|
||
|
#include "AST/ASTExpression.h"
|
||
|
|
||
|
|
||
|
typedef unsigned long ObjectIndex;
|
||
|
typedef unsigned long FunctionIndex;
|
||
|
|
||
|
class ContextManager {
|
||
|
public:
|
||
|
ContextManager();
|
||
|
typedef unsigned long ObjectIndex;
|
||
|
ObjectIndex index;
|
||
|
|
||
|
std::map<ObjectIndex, SenchaObject> object_store;
|
||
|
ObjectIndex add_to_store(SenchaObject & object);
|
||
|
SenchaObject get_from_store(ObjectIndex index);
|
||
|
|
||
|
typedef SenchaObject (*PointerToNativeFunction)(std::vector<ASTExpression *>);
|
||
|
|
||
|
std::map<std::string, PointerToNativeFunction> registered_functions;
|
||
|
|
||
|
void register_function(std::string name, PointerToNativeFunction f);
|
||
|
|
||
|
SenchaObject execute_native_function(std::string name, std::vector<ASTExpression *> arguments);
|
||
|
|
||
|
//Overload it to use contexts
|
||
|
void add(std::string name, SenchaObject object);
|
||
|
void set(std::string name, SenchaObject object);
|
||
|
SenchaObject get(std::string name);
|
||
|
typedef std::map<std::string, ObjectIndex> ExecutionContext;
|
||
|
ExecutionContext interpreter_context;
|
||
|
|
||
|
std::string debug() ;
|
||
|
|
||
|
|
||
|
|
||
|
ExecutionContext global_context;
|
||
|
std::map<FunctionIndex , ExecutionContext *> function_contexts;
|
||
|
virtual ~ContextManager();
|
||
|
};
|
||
|
|
||
|
#endif /* CONTEXT_H_ */
|