Пример #1
0
int registerSymbol(ParserTable& table, ident_t symbol, int new_id)
{
   if (symbol.compare("||")) {
      return _registerSymbol(table, "|", new_id);
   }
   else if (symbol.compare("&|")) {
      return _registerSymbol(table, "||", new_id);
   }
   else if (symbol.compare("-->")) {
      return _registerSymbol(table, "->", new_id);
   }
   else return _registerSymbol(table, symbol, new_id);
}
Пример #2
0
bool VMTapeParser :: writeObject(TapeWriter& writer, int state, ident_t token)
{
   if (token.compare(".")) {
      writer.writeCommand(POP_TAPE_MESSAGE_ID);
   }
   else {
      switch (state) {
         case dfaInteger:
            writer.writeCommand(PUSHN_TAPE_MESSAGE_ID, token);
            break;
         case dfaReal:
            writer.writeCommand(PUSHR_TAPE_MESSAGE_ID, token);
            break;
         case dfaLong:
            writer.writeCommand(PUSHL_TAPE_MESSAGE_ID, token);
            break;
         case dfaQuote:
            writer.writeCommand(PUSHS_TAPE_MESSAGE_ID, token);
            break;
         case dfaFullIdentifier:
            writer.writeCallCommand(token);
            break;
         case dfaIdentifier:
            writeSubject(writer, token);
            break;
         default:
            return false;
      }
   }
   return true;
}
Пример #3
0
void ECodesAssembler :: fixJump(ident_t label, MemoryWriter& writer, LabelInfo& info)
{
   _Memory* code = writer.Memory();

   Map<ident_t, int>::Iterator it = info.fwdJumps.start();
   while (!it.Eof()) {
      if (label.compare(it.key())) {
         (*code)[*it] = writer.Position() - *it - 4;
      }
      it++;
   }
}
Пример #4
0
ref_t resolveMessage(_Module* module, ident_t method)
{
   int paramCount = 0;
   ref_t actionRef = 0;
   ref_t flags = 0;

   if (method.startsWith("params#")) {
      flags |= VARIADIC_MESSAGE;

      method = method.c_str() + getlength("params#");
   }
   if (method.startsWith("prop#")) {
      flags |= PROPERTY_MESSAGE;

      method = method.c_str() + getlength("prop#");
   }
   if (method.startsWith("#invoke")) {
      flags |= SPECIAL_MESSAGE;
   }
   if (method.startsWith("#private&")) {
      flags |= STATIC_MESSAGE;

      method = method.c_str() + getlength("#private&");
   }
   if (method.compare("#init")) {
      flags |= SPECIAL_MESSAGE;
   }

   IdentifierString actionName;
   int paramIndex = method.find('[', -1);
   if (paramIndex != -1) {
      actionName.copy(method, paramIndex);

      IdentifierString countStr(method + paramIndex + 1, getlength(method) - paramIndex - 2);
      paramCount = countStr.ident().toInt();
   }
   else actionName.copy(method);

   //if (actionName.compare("dispatch")) {
   //   actionRef = DISPATCH_MESSAGE_ID;
   //}
   //else if (actionName.compare("#new")) {
   //   actionRef = NEWOBJECT_MESSAGE_ID;
   //}
   ///*else */if (actionName.compare("#init")) {
   //   actionRef = INIT_MESSAGE_ID;
   //}
   //else {
   //   if (method.find("set&") != NOTFOUND_POS) {
   //      actionName.cut(0, 4);
   //      flags = PROPSET_MESSAGE;
   //   }
   //   else if (method.startsWith("#cast<") && paramCount > 0) {
   //      flags = SPECIAL_MESSAGE;
   //   }
   ////   else if (actionName.compare("set")) {
   ////      flags = PROPSET_MESSAGE;
   ////   }

      ref_t signature = 0;
      size_t index = actionName.ident().find('<');
      if (index != NOTFOUND_POS) {
         ref_t references[ARG_COUNT];
         size_t end = actionName.ident().find('>');
         size_t len = 0;
         size_t i = index + 1;
         while (i < end) {
            size_t j = actionName.ident().find(i, ',', end);

            IdentifierString temp(actionName.c_str() + i, j-i);
            references[len++] = module->mapReference(temp, true);

            i = j + 1;
         }

         signature = module->mapSignature(references, len, true);

         actionName.truncate(index);
      }

      actionRef = module->mapAction(actionName, signature, true);
      if (actionRef == 0) {
         printLine("Unknown subject ", actionName);

         return 0;
      }
   //}

   return encodeMessage(actionRef, paramCount, flags);
}