Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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;
 }