2012-12-08 19:59:05 +00:00
|
|
|
/*
|
|
|
|
* Context.h
|
|
|
|
*
|
|
|
|
* Created on: Dec 7, 2012
|
|
|
|
* Author: attero
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONTEXT_H_
|
|
|
|
#define CONTEXT_H_
|
|
|
|
#include <map>
|
2012-12-10 10:45:09 +00:00
|
|
|
#include <vector>
|
2012-12-08 19:59:05 +00:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2012-12-10 10:45:09 +00:00
|
|
|
#include "AST/SenchaObject.h"
|
|
|
|
#include "AST/ASTExpression.h"
|
|
|
|
|
2012-12-08 19:59:05 +00:00
|
|
|
|
|
|
|
typedef unsigned long ObjectIndex;
|
|
|
|
typedef unsigned long FunctionIndex;
|
|
|
|
|
|
|
|
class Context {
|
|
|
|
public:
|
|
|
|
Context();
|
|
|
|
typedef unsigned long ObjectIndex;
|
|
|
|
ObjectIndex index;
|
|
|
|
|
|
|
|
std::map<ObjectIndex, SenchaObject> object_store;
|
|
|
|
ObjectIndex add_to_store(SenchaObject & object);
|
|
|
|
SenchaObject get_from_store(ObjectIndex index);
|
|
|
|
|
2012-12-10 10:45:09 +00:00
|
|
|
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);
|
|
|
|
|
2012-12-08 19:59:05 +00:00
|
|
|
//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;
|
2012-12-09 10:29:08 +00:00
|
|
|
std::map<FunctionIndex , ExecutionContext *> function_contexts;
|
2012-12-08 19:59:05 +00:00
|
|
|
virtual ~Context();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CONTEXT_H_ */
|