Esempio n. 1
0
VirtualMachine::VirtualMachine() :
    currentInstruction(0), stackBasePointer(0), stackCurrentPointer(0) {

    //Allocate memory for registers
    registers_ = new int64_t[vmNumRegisters];
    registerReference_ = new bool[vmNumRegisters];

    //Initialize all the registers
    for (unsigned int i = 0; i < vmNumRegisters; ++i) {
        registers_[i] = 0;
        registerReference_[i] = false;
    }

    auto charType = SmartPointer<VMEntryType>(new VMEntryType("char", 1, false));

    //Register all the primitive types
    registerEntry("char", charType);
    registerEntry("bool", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("bool", 1, false))));
    registerEntry("short", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("short", 2, false))));
    registerEntry("int", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("int", 4, false))));
    registerEntry("float32", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("float32", 4, false))));

    registerEntry("long", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("int", 8, false))));
    registerEntry("__fnptr",NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("__fnptr", charType))));
    registerEntry("string", NamespaceEntry(SmartPointer<VMEntryType>(new VMEntryType("string", charType))));

    stack_ = new uint8_t[vmStackIncrease];
    currentStackHeight_ = vmStackIncrease;
    gcStat_ = 0;
}
Esempio n. 2
0
/**
 * Convenience method.  Calls 6-arg registerEntry().
 */
void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
                                           TransliteratorEntry* adopted,
                                           UBool visible) {
    UnicodeString source, target, variant;
    UBool sawSource;
    TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
    // Only need to do this if ID.indexOf('-') < 0
    UnicodeString id;
    TransliteratorIDParser::STVtoID(source, target, variant, id);
    registerEntry(id, source, target, variant, adopted, visible);
}
Esempio n. 3
0
void TransliteratorRegistry::put(Transliterator* adoptedProto,
                                 UBool visible,
                                 UErrorCode& ec)
{
    TransliteratorEntry *entry = new TransliteratorEntry();
    if (entry == NULL) {
        ec = U_MEMORY_ALLOCATION_ERROR;
        return;
    }
    entry->adoptPrototype(adoptedProto);
    registerEntry(adoptedProto->getID(), entry, visible);
}
Esempio n. 4
0
/**
 * Convenience method.  Calls 6-arg registerEntry().
 */
void TransliteratorRegistry::registerEntry(const UnicodeString& source,
                                           const UnicodeString& target,
                                           const UnicodeString& variant,
                                           TransliteratorEntry* adopted,
                                           UBool visible) {
    UnicodeString ID;
    UnicodeString s(source);
    if (s.length() == 0) {
        s.setTo(TRUE, ANY, 3);
    }
    TransliteratorIDParser::STVtoID(source, target, variant, ID);
    registerEntry(ID, s, target, variant, adopted, visible);
}
Esempio n. 5
0
void TransliteratorRegistry::put(const UnicodeString& ID,
                                 Transliterator::Factory factory,
                                 Transliterator::Token context,
                                 UBool visible,
                                 UErrorCode& ec) {
    TransliteratorEntry *entry = new TransliteratorEntry();
    if (entry == NULL) {
        ec = U_MEMORY_ALLOCATION_ERROR;
        return;
    }
    entry->setFactory(factory, context);
    registerEntry(ID, entry, visible);
}
Esempio n. 6
0
void TransliteratorRegistry::put(const UnicodeString& ID,
                                 const UnicodeString& alias,
                                 UBool readonlyAliasAlias,
                                 UBool visible,
                                 UErrorCode& /*ec*/) {
    TransliteratorEntry *entry = new TransliteratorEntry();
    // Null pointer check
    if (entry != NULL) {
        entry->entryType = TransliteratorEntry::ALIAS;
        if (readonlyAliasAlias) {
            entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
        }
        else {
            entry->stringArg = alias;
        }
        registerEntry(ID, entry, visible);
    }
}
Esempio n. 7
0
/**
 * Attempt to find a source-target/variant in the static locale
 * resource store.  Do not perform fallback.  Return 0 on failure.
 *
 * On success, create a new entry object, register it in the dynamic
 * store, and return a pointer to it, but do not make it public --
 * just because someone requested something, we do not expand the
 * available ID list (or spec DAG).
 *
 * Caller does NOT own returned object.
 */
TransliteratorEntry* TransliteratorRegistry::findInStaticStore(const TransliteratorSpec& src,
                                                 const TransliteratorSpec& trg,
                                                 const UnicodeString& variant) {
    TransliteratorEntry* entry = 0;
    if (src.isLocale()) {
        entry = findInBundle(src, trg, variant, UTRANS_FORWARD);
    } else if (trg.isLocale()) {
        entry = findInBundle(trg, src, variant, UTRANS_REVERSE);
    }

    // If we found an entry, store it in the Hashtable for next
    // time.
    if (entry != 0) {
        registerEntry(src.getTop(), trg.getTop(), variant, entry, FALSE);
    }

    return entry;
}
Esempio n. 8
0
SmartPointer<VMEntryType> VirtualMachine::findType(std::string const& name) {

    NamespaceEntry entry;

    //If the namespace entry is not found in the namespace
    if (!VM::NamespaceEntry::searchNamespace(namespace_, name, entry)) {

        VM_PRINTF_LOG("Type %s not found, inspecting to check if array\n", name.c_str());

        //If it starts with 'array(' try to generate it from existing types
        char const* prefix = "array(";

        if (strncmp(prefix, name.c_str(), strlen(prefix)) == 0) {

            std::string subtypeName = name.substr(strlen(prefix), name.size() - strlen(prefix) - 1);

            VM_PRINTF_LOG("Generating subtype %s\n", subtypeName.c_str());

            SmartPointer<VMEntryType> subtype = findType(subtypeName);

            if (subtype.get() == nullptr) {
                VM_PRINTF_FATAL("Cannot create array of invalid subtype %s\n", subtypeName.c_str());
                return nullptr;
            }

            SmartPointer<VMEntryType> entryType = SmartPointer<VMEntryType>(new VMEntryType(name, subtype));
            registerEntry(name, entryType);
            VM_PRINTF_LOG("Generating new type %s\n", name.c_str());
            return entryType;
        } else {
            VM_PRINTF_LOG("Prefix of %s does not match with array(\n", name.c_str());
            return nullptr;
        }
    }

    //If the entry in the namespace specified is not a type then return null
    if (entry.getType() != Type) {
        VM_PRINTF_LOG("Error searched type %s (%i)\n", name.c_str(), entry.getType());
        return nullptr;
    }

    return entry.getTypeReference();
}
Esempio n. 9
0
void TransliteratorRegistry::put(const UnicodeString& ID,
                                 const UnicodeString& resourceName,
                                 UTransDirection dir,
                                 UBool readonlyResourceAlias,
                                 UBool visible,
                                 UErrorCode& ec) {
    TransliteratorEntry *entry = new TransliteratorEntry();
    if (entry == NULL) {
        ec = U_MEMORY_ALLOCATION_ERROR;
        return;
    }
    entry->entryType = (dir == UTRANS_FORWARD) ? TransliteratorEntry::RULES_FORWARD
        : TransliteratorEntry::RULES_REVERSE;
    if (readonlyResourceAlias) {
        entry->stringArg.setTo(TRUE, resourceName.getBuffer(), -1);
    }
    else {
        entry->stringArg = resourceName;
    }
    registerEntry(ID, entry, visible);
}
Esempio n. 10
0
StyleOptionsPage::StyleOptionsPage(ZLDialogContent &dialogTab, ZLPaintContext &context) {
	const ZLResource &styleResource = ZLResource::resource(KEY_STYLE);

	myComboEntry = new ComboOptionEntry(*this, styleResource[KEY_BASE].value());
	myComboEntry->addValue(myComboEntry->initialValue());

	ZLTextStyleCollection &collection = ZLTextStyleCollection::Instance();
	ZLTextKind styles[] = { REGULAR, TITLE, SECTION_TITLE, SUBTITLE, H1, H2, H3, H4, H5, H6, CONTENTS_TABLE_ENTRY, LIBRARY_ENTRY, ANNOTATION, EPIGRAPH, AUTHOR, DATEKIND, POEM_TITLE, STANZA, VERSE, CITE, INTERNAL_HYPERLINK, EXTERNAL_HYPERLINK, BOOK_HYPERLINK, FOOTNOTE, ITALIC, EMPHASIS, BOLD, STRONG, DEFINITION, DEFINITION_DESCRIPTION, PREFORMATTED, CODE };
	const int STYLES_NUMBER = sizeof(styles) / sizeof(ZLTextKind);
	for (int i = 0; i < STYLES_NUMBER; ++i) {
		const ZLTextStyleDecoration *decoration = collection.decoration(styles[i]);
		if (decoration != 0) {
			myComboEntry->addValue(styleResource[decoration->name()].value());
		}
	}
	dialogTab.addOption(ZLResourceKey("optionsFor"), myComboEntry);

	{
		const std::string &name = myComboEntry->initialValue();
		FBTextStyle &baseStyle = FBTextStyle::Instance();

		registerEntry(dialogTab,
			KEY_FONTFAMILY, new ZLFontFamilyOptionEntry(baseStyle.FontFamilyOption, context),
			name
		);

		registerEntry(dialogTab,
			KEY_FONTSIZE, new ZLSimpleSpinOptionEntry(baseStyle.FontSizeOption, 2),
			name
		);

		registerEntry(dialogTab,
			KEY_BOLD, new ZLSimpleBooleanOptionEntry(baseStyle.BoldOption),
			name
		);

		registerEntry(dialogTab,
			KEY_ITALIC, new ZLSimpleBooleanOptionEntry(baseStyle.ItalicOption),
			name
		);

		registerEntry(dialogTab,
			KEY_AUTOHYPHENATIONS, new ZLSimpleBooleanOptionEntry(collection.AutoHyphenationOption),
			name
		);
	}

	for (int i = 0; i < STYLES_NUMBER; ++i) {
		ZLTextStyleDecoration *decoration = collection.decoration(styles[i]);
		if (decoration != 0) {
			const std::string &name = styleResource[decoration->name()].value();

			registerEntry(dialogTab,
				KEY_FONTFAMILY, new ZLTextFontFamilyWithBaseOptionEntry(decoration->FontFamilyOption, dialogTab.resource(KEY_FONTFAMILY), context),
				name
			);

			registerEntry(dialogTab,
				KEY_FONTSIZEDIFFERENCE, new ZLSimpleSpinOptionEntry(decoration->FontSizeDeltaOption, 2),
				name
			);

			registerEntry(dialogTab,
				KEY_BOLD, new ZLSimpleBoolean3OptionEntry(decoration->BoldOption),
				name
			);

			registerEntry(dialogTab,
				KEY_ITALIC, new ZLSimpleBoolean3OptionEntry(decoration->ItalicOption),
				name
			);

			registerEntry(dialogTab,
				KEY_ALLOWHYPHENATIONS, new ZLSimpleBoolean3OptionEntry(decoration->AllowHyphenationsOption),
				name
			);
		}
	}

	myComboEntry->onValueSelected(0);
	myComboEntry->setActive(false);
}
Esempio n. 11
0
StyleOptionsPage::StyleOptionsPage(ZLDialogContent &dialogTab, ZLPaintContext &context) {
  myComboEntry = new ComboOptionEntry(*this, "Options For", "Base");
  myComboEntry->addValue(myComboEntry->initialValue());

  TextStyleCollection &collection = TextStyleCollection::instance();
  const int STYLES_NUMBER = 32;
  TextKind styles[STYLES_NUMBER] = { REGULAR, TITLE, SECTION_TITLE, SUBTITLE, H1, H2, H3, H4, H5, H6, CONTENTS_TABLE_ENTRY, RECENT_BOOK_LIST, LIBRARY_AUTHOR_ENTRY, LIBRARY_BOOK_ENTRY, ANNOTATION, EPIGRAPH, AUTHOR, DATE, POEM_TITLE, STANZA, VERSE, CITE, HYPERLINK, FOOTNOTE, ITALIC, EMPHASIS, BOLD, STRONG, DEFINITION, DEFINITION_DESCRIPTION, PREFORMATTED, CODE };
  for (int i = 0; i < STYLES_NUMBER; ++i) {
    const TextStyleDecoration *decoration = collection.decoration(styles[i]);
    if (decoration != 0) {
      myComboEntry->addValue(decoration->name());
    }
  }
  dialogTab.addOption(myComboEntry);

  {
    const std::string &name = myComboEntry->initialValue();
    BaseTextStyle &baseStyle = collection.baseStyle();

    registerEntries(dialogTab,
      new FontFamilyOptionEntry(baseStyle.FontFamilyOption, context, false),
      new ZLSimpleBooleanOptionEntry(BOLD_STRING, baseStyle.BoldOption),
      name
    );

    registerEntries(dialogTab,
      new ZLSimpleSpinOptionEntry("Size", baseStyle.FontSizeOption, 2),
      new ZLSimpleBooleanOptionEntry(ITALIC_STRING, baseStyle.ItalicOption),
      name
    );

    registerEntry(dialogTab,
      new ZLSimpleBooleanOptionEntry("Auto Hyphenations", baseStyle.AutoHyphenationOption),
      name
    );
  }

  for (int i = 0; i < STYLES_NUMBER; ++i) {
    TextStyleDecoration *decoration = collection.decoration(styles[i]);
    if (decoration != 0) {
      const std::string &name = decoration->name();

      registerEntries(dialogTab,
        new FontFamilyOptionEntry(decoration->FontFamilyOption, context, true),
        new ZLSimpleBoolean3OptionEntry(BOLD_STRING, decoration->BoldOption),
        name
      );

      registerEntries(dialogTab,
        new ZLSimpleSpinOptionEntry("Size Difference", decoration->FontSizeDeltaOption, 2),
        new ZLSimpleBoolean3OptionEntry(ITALIC_STRING, decoration->ItalicOption),
        name
      );

      registerEntries(dialogTab,
        new ZLSimpleBoolean3OptionEntry("Allow Hyphenations", decoration->AllowHyphenationsOption),
        0,
        name
      );
    }
  }

  myComboEntry->onValueChange(myComboEntry->initialValue());
}