void Interpreter::ReadScript(const std::vector<ScriptToken *> &s, Script *script) {
+ std::map<string, int> labels;
int size(0);
for (vector<ScriptToken *>::const_iterator i(s.begin()), end(s.end()); i != end; ++i) {
- if ((*i)->GetType() != ScriptToken::COMMAND) {
+ if ((*i)->GetType() == ScriptToken::LABEL) {
+ if (labels.count((*i)->Label())) {
+ throw Error("duplicate label " + (*i)->Label());
+ } else {
+ labels[(*i)->Label()] = size;
+ }
+ } else if ((*i)->GetType() != ScriptToken::COMMAND) {
throw Error("unexpected script token");
}
++size;
unsigned char *text(reinterpret_cast<unsigned char *>(alloc.Alloc(size)));
int cursor(0);
for (vector<ScriptToken *>::const_iterator i(s.begin()), end(s.end()); i != end; ++i) {
+ if ((*i)->GetType() == ScriptToken::LABEL) {
+ continue;
+ }
if ((*i)->GetType() != ScriptToken::COMMAND) {
throw Error("unexpected script token");
}
if (t.GetType() != ScriptToken::IDENTIFIER) {
throw Error("expected identifier for address");
}
- if (source.IsDefined(t.GetIdentifier())) {
- const ParsedDefinition &def(GetDefinition(t.GetIdentifier()));
- void *addr(GetObject(def.type, t.GetIdentifier()));
+ if (source.IsDefined(t.Identifier())) {
+ const ParsedDefinition &def(GetDefinition(t.Identifier()));
+ void *addr(GetObject(def.type, t.Identifier()));
*reinterpret_cast<void **>(dest) = addr;
} else {
throw Error("postponing values in scripts not implemented");
void Interpreter::ReadScriptInteger(const ScriptToken &t, unsigned char *dest) {
if (t.GetType() == ScriptToken::IDENTIFIER) {
- if (source.IsDefined(t.GetIdentifier())) {
- void *num(GetObject(TypeDescription::GetTypeId("Number"), t.GetIdentifier()));
+ if (source.IsDefined(t.Identifier())) {
+ void *num(GetObject(TypeDescription::GetTypeId("Number"), t.Identifier()));
*reinterpret_cast<int *>(dest) = *reinterpret_cast<int *>(num);
} else {
throw Error("postponing values in scripts not implemented");
void Interpreter::ReadScriptVector(const ScriptToken &t, unsigned char *dest) {
if (t.GetType() == ScriptToken::IDENTIFIER) {
- if (source.IsDefined(t.GetIdentifier())) {
- void *vec(GetObject(TypeDescription::GetTypeId("Vector"), t.GetIdentifier()));
+ if (source.IsDefined(t.Identifier())) {
+ void *vec(GetObject(TypeDescription::GetTypeId("Vector"), t.Identifier()));
*reinterpret_cast<Vector<int> *>(dest) = *reinterpret_cast<Vector<int> *>(vec);
} else {
throw Error("postponing values in scripts not implemented");