summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Context.h
blob: 873de02cb76fda35afd1b0da9b16a5bb0c91401f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Context.h
 *
 *  Created on: Dec 7, 2012
 *      Author: attero
 */

#ifndef CONTEXT_H_
#define CONTEXT_H_
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include "AST/SenchaObject.h"
#include "AST/ASTExpression.h"


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);

	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 ~Context();
};

#endif /* CONTEXT_H_ */