本文整理汇总了C++中VM类的典型用法代码示例。如果您正苦于以下问题:C++ VM类的具体用法?C++ VM怎么用?C++ VM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lg
Object* Thread::raise(STATE, GCToken gct, Exception* exc) {
utilities::thread::SpinLock::LockGuard lg(init_lock_);
Thread* self = this;
OnStack<2> os(state, self, exc);
VM* vm = self->vm_;
if(!vm) {
return cNil;
}
vm->register_raise(state, exc);
vm->wakeup(state, gct);
return exc;
}
示例2: main
int main(int argc, const char* argv[])
{
if (argc > 2)
{
// TODO(bob): Show usage, etc.
std::cout << "magpie [script]" << std::endl;
return 1;
}
VM vm;
if (argc == 1) return repl(vm);
bool success = vm.runProgram(String::create(argv[1]));
return success ? 0 : 1;
}
示例3: result
Vector<BasicBlockRange> ControlFlowProfiler::getBasicBlocksForSourceID(intptr_t sourceID, VM& vm) const
{
Vector<BasicBlockRange> result(0);
auto bucketFindResult = m_sourceIDBuckets.find(sourceID);
if (bucketFindResult == m_sourceIDBuckets.end())
return result;
const BlockLocationCache& cache = bucketFindResult->value;
for (const BasicBlockLocation* block : cache.values()) {
bool hasExecuted = block->hasExecuted();
const Vector<BasicBlockLocation::Gap>& blockRanges = block->getExecutedRanges();
for (BasicBlockLocation::Gap gap : blockRanges) {
BasicBlockRange range;
range.m_hasExecuted = hasExecuted;
range.m_startOffset = gap.first;
range.m_endOffset = gap.second;
result.append(range);
}
}
const Vector<std::tuple<bool, unsigned, unsigned>>& unexecutedFunctionRanges = vm.functionHasExecutedCache()->getFunctionRanges(sourceID);
for (const auto& functionRange : unexecutedFunctionRanges) {
BasicBlockRange range;
range.m_hasExecuted = std::get<0>(functionRange);
range.m_startOffset = static_cast<int>(std::get<1>(functionRange));
range.m_endOffset = static_cast<int>(std::get<2>(functionRange));
result.append(range);
}
return result;
}
示例4: if
void VirshGui::toggleVMStatus()
{
string vmname = ui->vmnameLabel->text().toStdString();
VM vm = vmlist[vmname];
try {
if (vm.getStatus() == VMStatus::shutoff) {
vm.start();
} else if (vm.getStatus() == VMStatus::running) {
vm.destroy();
}
} catch (ssh::SshException e) {
handleDisconnect();
}
refreshVmList();
}
示例5: setTimeLimit
void Watchdog::setTimeLimit(VM& vm, std::chrono::microseconds limit,
ShouldTerminateCallback callback, void* data1, void* data2)
{
bool wasEnabled = isEnabled();
if (!m_isStopped)
stopCountdown();
m_didFire = false; // Reset the watchdog.
m_limit = limit;
m_callback = callback;
m_callbackData1 = data1;
m_callbackData2 = data2;
// If this is the first time that timeout is being enabled, then any
// previously JIT compiled code will not have the needed polling checks.
// Hence, we need to flush all the pre-existing compiled code.
//
// However, if the timeout is already enabled, and we're just changing the
// timeout value, then any existing JITted code will have the appropriate
// polling checks. Hence, there is no need to re-do this flushing.
if (!wasEnabled) {
// And if we've previously compiled any functions, we need to revert
// them because they don't have the needed polling checks yet.
vm.releaseExecutableMemory();
}
startCountdownIfNeeded();
}
示例6: AddConsole
void AddConsole(VM &vm)
{
vm.setConsole(&con);
vm.sios.addSIO(&con);
vm.sios.addSIO(&sio1);
vm.sios.addSIO(&sio2);
vm.sios.addSIO(&sio3);
vm.sios.addSIO(&sio4);
vm.sios.addSIO(&sio5);
vm.sios.addSIO(&sio6);
vm.sios.addSIO(&sio7);
vm.sios.addSIO(&sio8);
vm.sios.addSIO(&mouse);
server.addClient(&sio1);
server.addClient(&sio2);
server.addClient(&sio3);
server.addClient(&sio4);
server.addClient(&sio5);
server.addClient(&sio6);
server.addClient(&sio7);
server.addClient(&sio8);
server.start();
}
示例7: os
Thread* Thread::wakeup(STATE, GCToken gct) {
init_lock_.lock();
Thread* self = this;
OnStack<1> os(state, self);
VM* vm = self->vm_;
if(alive() == cFalse || !vm) {
self->init_lock_.unlock();
return force_as<Thread>(Primitives::failure());
}
vm->wakeup(state, gct);
self->init_lock_.unlock();
return self;
}
示例8: switch
gc<ClassObject> AtomObject::getClass(VM& vm) const
{
switch (atom_)
{
case ATOM_FALSE:
case ATOM_TRUE:
return vm.getClass(CLASS_BOOL);
case ATOM_NOTHING: return vm.getClass(CLASS_NOTHING);
case ATOM_DONE: return vm.getClass(CLASS_DONE);
case ATOM_NO_METHOD:
ASSERT(false, "NO_METHOD shouldn't be in AtomObject.");
}
ASSERT(false, "Unexpected atom value.");
return NULL;
}
示例9: throw
string CViewRenderer::renderFile(const IRenderingContext * context, const string & sourceFile, CDT & data, bool ret) throw (CException)
{
boost::filesystem::path sourcePath(sourceFile);
if (!boost::filesystem::exists(sourcePath)) {
throw CException("View file \"" + sourceFile + "\" does not exist.");
}
string viewFile = getViewFile(sourceFile);
boost::filesystem::path viewPath(viewFile);
if (!boost::filesystem::exists(viewPath) || boost::filesystem::last_write_time(sourcePath) > boost::filesystem::last_write_time(viewPath)) {
if (generateViewFile(sourceFile, viewFile)) {
chmod(viewFile.c_str(), filePermission);
} else {
throw CException("Can't generate view file \"" + viewFile + "\" from source file \"" + sourceFile + "\".");
}
}
if (context != 0) {
return context->renderInternal(viewFile, data, ret);
}
stringstream os;
StreamOutputCollector outputCollector(os);
TDynamicTemplateCacheMap::const_iterator found = _templateCache.find(viewFile);
VMLoader * oLoader = 0;
if (found == _templateCache.end()) {
oLoader = new VMFileLoader(viewFile.c_str());
_templateCache[viewFile.c_str()] = boost::shared_ptr<VMLoader>(oLoader);
} else {
oLoader = found->second.get();
}
PROFILE_BEGIN("CViewRenderer::rendering template bytecode of \"" + viewFile + "\"")
UINT_32 iIP = 0;
VM * vm = Cws::app()->getTemplateEngine()->getVM();
const VMMemoryCore * pVMMemoryCore = oLoader->GetCore();
vm->Init(pVMMemoryCore, &outputCollector, 0);
vm->Run(pVMMemoryCore, &outputCollector, iIP, data, 0);
PROFILE_END()
if (ret) {
return os.str();
} else {
Cws::app()->getOutputStack().top()->echo(os.str());
return "";
}
}
示例10: main
int main(int argc, const char **argv)
{
// Usage information.
if (argc < 2)
{
cout<<"Usage: " <<argv[0] <<" <file>\n";
return 0;
}
char *buffer;
istream *f;
// If it's -, read from stdin.
if (strcmp(argv[1], "-") == 0)
{
std::stringstream *stream = new std::stringstream();
*stream << cin.rdbuf();
f = stream;
}
// Otherwise, just open the file.
else
{
f = new ifstream(argv[1]);
}
if (f->fail())
{
cout<<"Input error" <<endl;
delete f;
return 1;
}
// Determine the size.
f->seekg(0, ios::end);
int l = f->tellg();
f->seekg(0, ios::beg);
// Allocate a buffer.
buffer = new char[l];
// Read the data.
f->read(buffer, l);
delete f;
// Create a VM.
VM vm;
// Create a parser and let it parse
// the file for us.
Parser p(&vm);
p.parseBlob(buffer, l);
// And start the main loop!
vm.run();
return 0;
}
示例11: STARTDECL
STARTDECL(read_file) (VM &vm, Value &file) {
string buf;
auto l = LoadFile(file.sval()->strv(), &buf);
file.DECRT(vm);
if (l < 0) return Value();
auto s = vm.NewString(buf);
return Value(s);
}
示例12: addImports
void Module::addImports(VM& vm, ErrorReporter& reporter)
{
// Implicitly import core (unless we are core).
if (*name_ != "core")
{
vm.importModule(reporter, this, NULL, String::create("core"));
}
// Load all of the imports.
for (int i = 0; i < ast_->body()->expressions().count(); i++)
{
ImportExpr* import = ast_->body()->expressions()[i]->asImportExpr();
if (import == NULL) continue;
vm.importModule(reporter, this, import->pos(), import->name());
}
}
示例13: test_find_and_activate
void test_find_and_activate() {
Thread* cur = Thread::current(state);
Thread* thread = Thread::create(state);
thread->wakeup(state);
state->queue_thread(thread);
bool ret = state->find_and_activate_thread();
TS_ASSERT_EQUALS(true, ret);
TS_ASSERT_EQUALS(Qfalse, thread->queued());
TS_ASSERT_EQUALS(thread, Thread::current(state));
TS_ASSERT_EQUALS(Qtrue, cur->queued());
}
示例14: test_symbol
void test_symbol() {
mar->sstream.str(std::string("x\n4\nblah\n"));
Object* obj = mar->unmarshal();
TS_ASSERT(obj->symbol_p());
TS_ASSERT_EQUALS(obj, state->symbol("blah"));
}
示例15: test_activate_thread_sets_as_current
void test_activate_thread_sets_as_current() {
Thread* thread = Thread::create(state);
state->activate_thread(thread);
TS_ASSERT_EQUALS(thread, Thread::current(state));
}