std::string PeekString(Machine& machine, int n) { Data d = machine.stack.Peek(n); if (d == nullptr) { throw std::exception("Stack underflow"); } if (d->IsVariable()) { std::string name; d->GetVariable(name); machine.GetVariable(name, d); // Fall through in case it's a field } if (d->IsField()) { std::string tag; d->GetField(tag); std::string value = machine.registers.input.GetFieldValue(tag); return value; } if (d->IsString() == false) { throw std::exception("Argument not a string"); } std::string s; d->GetString(s); return s; }
Data Peek(Machine& machine, int n) { Data d = machine.stack.Peek(n); if (d == nullptr) { throw std::exception("Stack underflow"); } if (d->IsVariable()) { std::string name; d->GetVariable(name); machine.GetVariable(name, d); } return d; }
std::vector<Data> PeekArray(Machine& machine, int n) { Data d = machine.stack.Pop(); if (d == nullptr) { throw std::exception("Stack underflow"); } if (d->IsVariable()) { std::string name; d->GetVariable(name); machine.GetVariable(name, d); } if (d->IsArray() == false) { throw std::exception("Argument not an array"); } return std::move(((Array *)d.get())->items); }
int PeekInt(Machine& machine, int pos) { Data d = machine.stack.Peek(pos); if (d == nullptr) { throw std::exception("Stack underflow"); } if (d->IsVariable()) { std::string name; d->GetVariable(name); machine.GetVariable(name, d); } if (d->IsInt() == false) { throw std::exception("Argument not a int"); } int n; d->GetInt(n); return n; }