Пример #1
0
void ECodesAssembler :: readMessage(TokenInfo& token, int& verbId, IdentifierString& subject, int& paramCount)
{
   verbId = mapVerb(token.value);
   if (verbId == 0) {
      if (token.check("dispatch")) {
         verbId = DISPATCH_MESSAGE_ID;
      }
      else verbId = EVAL_MESSAGE_ID;
   }

   token.read();
   while (token.value[0] == '&') {
      subject.append(token.value);

      token.read();
      subject.append(token.value);
      token.read();
      if (token.value[0] == '$') {
         subject.append(token.value);
         token.read();
      }
   }
   if (token.value[0] == '[') {
      paramCount = token.readInteger(constants);
   }
   else token.raiseErr("Invalid operand (%d)");

   token.read("]", "Invalid operand (%d)");
}
Пример #2
0
void ECodesAssembler :: compileMCommand(ByteCode code, TokenInfo& token, MemoryWriter& writer, _Module* binary)
{
   ident_t word = token.read();
   if (token.terminal.state == dfaInteger || constants.exist(word)) {
      int m = 0;
      if(token.getInteger(m, constants)) {
         writeCommand(ByteCommand(code, m), writer);
      }
      else token.raiseErr("Invalid number (%d)\n");
   }
   else if (word.compare("subject")) {
      token.read(":", "Invalid operand (%d)");
      token.read();

      int paramCount = 0; // NOTE: paramCount might be not equal to stackCount (the actual stack size) in the case if variables are used for virtual methods
      int stackCount = 0;
      int verbId = mapVerb(token.value);
      if (verbId == 0) {
         verbId = EVAL_MESSAGE_ID;
      }

      IdentifierString subject;
      token.read();
      bool first = true;
      while(token.value[0] == '&') {
         if (first) {
            first = false;
         }
         else subject.append(token.value);

         token.read();
         subject.append(token.value);
         token.read();
      }
      if (token.value[0] == '[') {
         paramCount = token.readInteger(constants);
      }
      else token.raiseErr("Invalid operand (%d)");

      token.read("]", "Invalid operand (%d)");

      ref_t subj = binary->mapSubject(subject, false);

      writeCommand(ByteCommand(code, encodeMessage(subj, verbId, paramCount)), writer);
   }
   else throw AssemblerException("Invalid operand (%d)\n", token.terminal.row);
}