public static StandardObject lookupVariableType(Symbol variablename) {
    { StandardObject entry = ((((KeyValueList)(Stella.$LOCALVARIABLETYPETABLE$.get())) != null) ? ((StandardObject)(KeyValueList.lookupVariableTable(((KeyValueList)(Stella.$LOCALVARIABLETYPETABLE$.get())), variablename))) : ((StandardObject)(null)));
      StandardObject type = null;

      if (entry == null) {
        if (variablename == Stella.SYM_STELLA_NULL) {
          return (Stella.SGT_STELLA_UNKNOWN);
        }
        type = Symbol.lookupGlobalVariableType(variablename);
        Symbol.registerReferenceToGlobalVariable(variablename);
      }
      else {
        if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(entry), Stella.SGT_STELLA_KEY_VALUE_LIST)) {
          { KeyValueList entry000 = ((KeyValueList)(entry));

            type = ((StandardObject)(entry000.lookup(Stella.KWD_TYPE)));
          }
        }
        else {
          type = entry;
        }
      }
      if (type == null) {
        { Object old$PrintreadablyP$000 = Stella.$PRINTREADABLYp$.get();

          try {
            Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
            Stella.signalTranslationError();
            if (!(Stella.suppressWarningsP())) {
              Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
              {
                Stella.STANDARD_ERROR.nativeStream.println();
                Stella.STANDARD_ERROR.nativeStream.println(" Undeclared variable `" + Stella_Object.deUglifyParseTree(variablename) + "'.");
              }
;
            }

          } finally {
            Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$000);
          }
        }
        return (Stella.SGT_STELLA_UNKNOWN);
      }
      if (type == Stella.SGT_STELLA_UNINITIALIZED) {
        { Object old$PrintreadablyP$001 = Stella.$PRINTREADABLYp$.get();

          try {
            Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
            Stella.signalTranslationError();
            if (!(Stella.suppressWarningsP())) {
              Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
              {
                Stella.STANDARD_ERROR.nativeStream.println();
                Stella.STANDARD_ERROR.nativeStream.println(" Reference to defined but uninitialized variable `" + Stella_Object.deUglifyParseTree(variablename) + "'.");
              }
;
            }

          } finally {
            Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$001);
          }
        }
        return (Stella.SGT_STELLA_UNKNOWN);
      }
      return (type);
    }
  }