4 * Created on: Aug 26, 2012
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
11 #include "ParsedSource.h"
12 #include "TypeDescription.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/Color.h"
15 #include "../graphics/ComplexAnimation.h"
44 struct MenuProperties;
45 class SimpleAnimation;
59 class Error: public std::runtime_error {
61 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
65 explicit Interpreter(const ParsedSource &source) : source(source) { }
68 Interpreter(const Interpreter &);
69 Interpreter &operator =(const Interpreter &);
73 void *GetObject(int typeId, const std::string &name);
75 static void CreateTypeDescriptions();
76 struct ParsedDefinition {
77 ParsedDefinition(const Definition *dfn, int type, int id)
78 : dfn(dfn), type(type), id(id) { }
79 const Definition *dfn;
83 struct PostponedDefinition {
84 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType, bool inlined)
85 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType), inlined(inlined) { }
88 std::ptrdiff_t offset;
89 const char *identifier;
94 const std::set<std::string> &ExportedIdentifiers() const { return source.Exports(); }
95 const ParsedDefinition &GetDefinition(const std::string &identifier) const;
96 const std::map<std::string, SDL_Surface *> &Images() const { return imageCache; }
97 const std::vector<PostponedDefinition> &PostponedDefinitions() const { return postponedDefinitions; }
98 const std::map<int, std::vector<void *> > &Values() const { return values; }
101 void ReadDefinition(const Definition &);
102 void ReadLiteral(const Definition &);
103 void ReadObject(const Definition &);
105 void ReadLiteral(int typeId, int id, char *dest, const Literal &);
106 void *GetObject(int typeId, const Value &value);
107 void ReadObject(int typeId, int id, char *dest, const PropertyList &);
109 SDL_Surface *GetImage(const std::string &);
111 bool CanLink(const Value &) const;
112 void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined);
115 const ParsedSource &source;
117 std::map<std::string, ParsedDefinition> parsedDefinitions;
118 std::vector<PostponedDefinition> postponedDefinitions;
119 std::map<std::string, SDL_Surface *> imageCache;
120 std::map<int, std::vector<void *> > values;
126 #endif /* LOADER_INTERPRETER_H_ */