Exemplo n.º 1
0
/*
 * This function contains the main interpreter loop. Java
 * ByteCode instructions are executed one at a time. Before
 * calling this function the core register should contain
 * the correct value.
 */
execute() {
    // initialise register values
    printf("Interpreter started\n");
    initCollector();
    thread = getRef(core, CORE_RUNNING);
    loadRegisters();   

    // used to mimic a time slice
    int maxSize = 50;
    int count = 0;
    
    // execute the next instruction, indefinitely
    void (*implementation)();
    int index;
    unsigned char bytecode;
    for (;;) {
        bytecode = code[pc];
        dbgCodes[dbgIndex++] = bytecode;
        if (dbgIndex == 50) { dbgIndex = 0; }
        //printf("0x%X\n", bytecode);
        implementation = distributor[bytecode];
        implementation();
        count++;

        // check if another thread needs to be scheduled
        if (thread == NULL || count >= maxSize) {
            if (thread != NULL) { saveRegisters(); }
            scheduleNextThread();
            //wakeSleepingThreads();
            count = 0;
        }
    }
}
Exemplo n.º 2
0
/////////////////////////////////////////////////////////////////////////////
// WMIBaseProvider::initialize
//
// ///////////////////////////////////////////////////////////////////////////
void WMIBaseProvider::initialize(bool bLocal)
{
	PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIBaseProvider::initialize()");

	initCollector(bLocal);

	PEG_METHOD_EXIT();
}
Exemplo n.º 3
0
/////////////////////////////////////////////////////////////////////////////
// WMIBaseProvider::setup
//
/////////////////////////////////////////////////////////////////////////////
void WMIBaseProvider::setup(const String & nameSpace,
							const String & userName,
							const String & password)
{
	m_sNamespace = nameSpace;
	m_sUserName = userName;
	m_sPassword = password;

	if (!m_bInitialized)	
	{
		initCollector();
	}

	if (m_bInitialized)
	{
		_collector->setNamespace(m_sNamespace);

		if (m_sUserName != String::EMPTY)
			_collector->setUserName(m_sUserName);
		
		if (m_sPassword != String::EMPTY)
			_collector->setPassword(m_sPassword);
	}
}
Exemplo n.º 4
0
/*
 * internal declare-attribute.  This one allows colonized values for
 *  names, so that you can declare xmlns:-type attributes
 */
static genxAttribute declareAttribute(genxWriter w, genxNamespace ns,
				      constUtf8 name, constUtf8 valuestr,
				      genxStatus * statusP)
{
  int high, low;
  genxAttribute * aa = (genxAttribute *) w->attributes.pointers;
  genxAttribute a;

  w->arec.ns = ns;
  w->arec.name = (utf8) name;

  if (ns)
    w->arec.atype = ATTR_PREFIXED;
  else if (strncmp((const char *) name, "xmlns", STRLEN_XMLNS_COLON - 1) == 0)
    w->arec.atype = ATTR_NSDECL;
  else
    w->arec.atype = ATTR_NAKED;

  if (ns && (ns->defaultDecl == w->xmlnsEquals))
  {
    w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE;
    goto busted;
  }

  /* attribute list has to be kept sorted per c14n rules */
  high = w->attributes.count; low = -1;
  while (high - low > 1)
  {
    int probe = (high + low) / 2;
    if (orderAttributes(&w->arec, aa[probe]) < 0)
      high = probe;
    else
      low = probe;
  }

  /* if it was already there */
  if (low != -1 && orderAttributes(&w->arec, aa[low]) == 0)
    return aa[low];

  /* not there, build it */
  a = (genxAttribute) allocate(w, sizeof(struct genxAttribute_rec));
  if (a == NULL)
  {
    w->status = GENX_ALLOC_FAILED;
    goto busted;
  }

  a->writer = w;
  a->ns = ns;
  a->provided = False;
  a->atype = w->arec.atype;

  if ((a->name = copy(w, name)) == NULL)
  {
    w->status = GENX_ALLOC_FAILED;
    goto busted;
  }

  if ((w->status = initCollector(w, &a->value)) != GENX_SUCCESS)
    goto busted;

  if (valuestr)
    if ((w->status = collectString(w, &a->value, valuestr)) != GENX_SUCCESS)
      goto busted;
  
  w->status = listInsert(&w->attributes, a, high);
  if (w->status != GENX_SUCCESS)
    goto busted;
  
  *statusP = GENX_SUCCESS;
  return a;

busted:
  *statusP = w->status;
  return NULL;
}
Exemplo n.º 5
0
/*
 * Construct a new genxWriter
 */
genxWriter genxNew(void * (* alloc)(void * userData, int bytes),
		   void (* dealloc)(void * userData, void * data),
		   void * userData)
{
  genxWriter w;
  genxNamespace xml;

  if (alloc)
    w = (genxWriter) (*alloc)(userData, sizeof(struct genxWriter_rec));
  else
    w = (genxWriter) malloc(sizeof(struct genxWriter_rec));

  if (w == NULL)
    return NULL;

  w->status = GENX_SUCCESS;
  w->alloc = alloc;
  w->dealloc = dealloc;
  w->userData = userData;
  w->sequence = SEQUENCE_NO_DOC;

  if (initPlist(w, &w->namespaces) != GENX_SUCCESS ||
      initPlist(w, &w->elements) != GENX_SUCCESS ||
      initPlist(w, &w->attributes) != GENX_SUCCESS ||
      initPlist(w, &w->prefixes) != GENX_SUCCESS ||
      initPlist(w, &w->stack) != GENX_SUCCESS)
    return NULL;

  if ((w->status = initCollector(w, &w->arec.value)) != GENX_SUCCESS)
    return NULL;

  if ((w->empty = copy(w, (utf8) "")) == NULL)
  {
    w->status = GENX_ALLOC_FAILED;
    return NULL;
  }

  w->xmlnsEquals = declareAttribute(w, NULL, (utf8) "xmlns", NULL, &w->status);
  if (w->xmlnsEquals == NULL || w->status != GENX_SUCCESS)
    return NULL;
  w->defaultNsDeclared = False;

  w->nextPrefix = 1;

  genxSetCharProps(w->xmlChars);

  w->etext[GENX_SUCCESS] = "Success";
  w->etext[GENX_BAD_UTF8] = "Bad UTF8";
  w->etext[GENX_NON_XML_CHARACTER] = "Non XML Character";
  w->etext[GENX_BAD_NAME] = "Bad NAME";
  w->etext[GENX_ALLOC_FAILED] = "Memory allocation failed";
  w->etext[GENX_BAD_NAMESPACE_NAME] = "Bad namespace name";
  w->etext[GENX_INTERNAL_ERROR] = "Internal error";
  w->etext[GENX_DUPLICATE_PREFIX] = "Duplicate prefix";
  w->etext[GENX_SEQUENCE_ERROR] = "Call out of sequence";
  w->etext[GENX_NO_START_TAG] = "No Start-tag for EndElement call";
  w->etext[GENX_IO_ERROR] = "I/O error";
  w->etext[GENX_MISSING_VALUE] = "Missing attribute value";
  w->etext[GENX_MALFORMED_COMMENT] = "Malformed comment body";
  w->etext[GENX_MALFORMED_PI] = "?> in PI";
  w->etext[GENX_XML_PI_TARGET] = "Target of PI matches [xX][mM][lL]";
  w->etext[GENX_DUPLICATE_ATTRIBUTE] =
    "Same attribute specified more than once";
  w->etext[GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE] =
    "Attribute cannot be in default namespace";
  w->etext[GENX_DUPLICATE_NAMESPACE] =
    "Declared namespace twice with different prefixes on one element.";
  w->etext[GENX_BAD_DEFAULT_DECLARATION] =
    "Declared a default namespace on an element which is in no namespace";

  /* the xml: namespace is pre-wired */
  xml = genxDeclareNamespace(w, (utf8) "http://www.w3.org/XML/1998/namespace",
			     (utf8) "xml", &w->status);
  if (xml == NULL)
    return NULL;
  xml->declCount = 1;
  xml->declaration = xml->defaultDecl;

  return w;
}