Example #1
0
int test1() {
  try {
    live();
  } catch (int i) {
    live();
  }
  return 1;
}
Example #2
0
/* given current board, make next board position */
void nextBoard(char** thisB, char** nextB) {
  int i;
  int j;
  int counter; // count of live cells as board updates
  int neighbors; // count of living neighbors for one cell
 
 /* for every cell */
  for (j = 0; j < height; j++) {
      for (i = 0; i < width; i++) {
	  /* reset neighbor count */
	  neighbors = 0;

	  /* count live neighbot cells */
	  neighbors = live(thisB[check(0, i - 1)][check(1, j + 1)]) +
	    live(thisB[check(0, i)][check(1, j + 1)]) +
	    live(thisB[check(0, i + 1)][check(1, j + 1)]) +
	    live(thisB[check(0, i - 1)][check(1, j)]) +
	    live(thisB[check(0, i + 1)][check(1, j)]) +
	    live(thisB[check(0, i - 1)][check(1, j - 1)]) +
	    live(thisB[check(0, i)][check(1, j - 1)]) +
	    live(thisB[check(0, i + 1)][check(1, j - 1)]);

	  /* determines state of the new cell */
	  if ((neighbors == 3) || ((neighbors ==2) && (thisB[i][j] == '@'))) {
	      nextB[i][j] = '@';
	      counter++;
	    }
	  else
	  nextB[i][j] = '.';
	}
    }
  /* if there are live cells, print board */
  if (counter != 0)
    printBoard(nextB);
}
Example #3
0
/// @throws AbortError, BackupReadError, BackupWriteError, GetRangesError
void DirectSearch::searchExact(Mem::Random &ram, const Number::Untyped &value, Async::AbortableProgress &progress) {
	if (mStatus == DirectStatus::Started) {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].filterEqual(lock, value, progress);
		}
	}
	else {
		Mem::Live live(ram);
		Mem::SingleBlockEnum block(live, Number::maxSize, NULL);
		mBackup = boost::none;
		mStatus = DirectStatus::Started;
		progress.start(block.totalSize());
		while (block.next()) {
			if (mType) {
				mLocLists[mType.get()].appendEqual(block, value);
			}
			else {
				for (size_t type = 0; type < Number::Type::count; ++type) {
					mLocLists[type].appendEqual(block, value);
				}
			}
			progress.set(block.doneSize());
			progress.check();
		}
	}
}
Example #4
0
int fish::initclock()
{
    timer=new QTimer(this);
    connect(this->timer, SIGNAL(timeout()), this, SLOT(live()));
    timer->start(60000);
    return 0;
}
Example #5
0
 void setPlayBackRate(double playbackRate) {
     if (live()) {
         _ui.logTree->setStyleSheet(
             QString("QTreeWidget{%1}").arg(LiveStyle));
     }
     _playbackRate = playbackRate;
 }
Example #6
0
 void setLive() {
     if (!live()) {
         _ui.logTree->setStyleSheet(
             QString("QTreeWidget{%1}").arg(NonLiveStyle));
         _playbackRate = boost::none;
     }
 }
void LifeComponent::onLive()
{
	FLAT_ASSERT(!m_spawning && !m_despawning);

	m_spawning = true;

	disableComponent<movement::MovementComponent>();
	disableComponent<behavior::BehaviorComponent>();
	
	live();
	
	const LifeComponentTemplate* lifeComponentTemplate = getTemplate();
	const flat::lua::SharedLuaReference<LUA_TFUNCTION>& spawnFunc = lifeComponentTemplate->getSpawnFunc();
	if (!spawnFunc.isEmpty())
	{
		lua_State* L = spawnFunc.getLuaState();
		{
			FLAT_LUA_EXPECT_STACK_GROWTH(L, 0);
			spawnFunc.push(L);
			m_spawnDespawnThread.set(L, -1);
			lua_pop(L, 1);
			m_spawnDespawnThread.start(m_owner);
		}
	}

	checkSpawnDespawnThreadFinished();
}
Example #8
0
/// @throws AbortError, GetRangesError
void DirectSearch::searchComp(Mem::Random &ram, Comparison::t comp, Async::AbortableProgress &progress) {
	assert(mStatus != DirectStatus::NotStarted);
	if (mStatus == DirectStatus::SavedBackup) {
		Mem::Live live(ram);
		Mem::Backup backup(mBackup.get());
		mBackup = boost::none;
		mStatus = DirectStatus::Started;
		Mem::DoubleBlockEnum blocks(backup, live, Number::maxSize);
		progress.start(blocks.totalSize());
		while (blocks.next()) {
			if (mType) {
				mLocLists[mType.get()].appendComp(blocks, comp);
			}
			else {
				for (size_t type = 0; type < Number::Type::count; ++type) {
					mLocLists[type].appendComp(blocks, comp);
				}
			}
			progress.set(blocks.doneSize());
			progress.check();
		}
	}
	else {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].filterComp(lock, comp, progress);
		}
	}
}
int     AddMonth ( int year , int month , int day )
{
        if ( month == 12 ) { month = 1; year ++; }
        else month ++;
        
        if ( live ( year , month , day ) && !Win [year] [month] [day] ) return 1;
        else return 0;
}
Example #10
0
// Remove dead instructions by doing a traditional liveness analysis.
// instructions that mutate memory, physical registers, or status flags
// are considered useful. All branches are considered useful.
//
// Given SSA, there's a faster sparse version of this algorithm that marks
// useful instructions in one pass, then transitively marks pure instructions
// that define inputs to useful instructions. However it requires a mapping
// from vreg numbers to the instruction that defines them, and a way to address
// individual instructions.
//
// We could remove useless branches by computing the post-dominator tree and
// RDF(b) for each block; then a branch is only useful if it controls whether
// or not a useful block executes, and useless branches can be forwarded to
// the nearest useful post-dominator.
void removeDeadCode(Vunit& unit) {
  auto blocks = sortBlocks(unit);
  jit::vector<LiveSet> livein(unit.blocks.size());
  LiveSet live(unit.next_vr);
  auto pass = [&](bool mutate) {
    bool changed = false;
    for (auto blockIt = blocks.end(); blockIt != blocks.begin();) {
      auto b = *--blockIt;
      auto& block = unit.blocks[b];
      live.reset();
      for (auto s : succs(block)) {
        if (!livein[s].empty()) {
          live |= livein[s];
        }
      }
      for (auto i = block.code.end(); i != block.code.begin();) {
        auto& inst = *--i;
        auto useful = effectful(inst);
        visitDefs(unit, inst, [&](Vreg r) {
          if (r.isPhys() || live.test(r)) {
            useful = true;
            live.reset(r);
          }
        });
        if (useful) {
          visitUses(unit, inst, [&](Vreg r) {
            live.set(r);
          });
        } else if (mutate) {
          inst = nop{};
          changed = true;
        }
      }
      if (mutate) {
        assert(live == livein[b]);
      } else {
        if (live != livein[b]) {
          livein[b] = live;
          changed = true;
        }
      }
    }
    return changed;
  };
  // analyze until livein reaches a fixed point
  while (pass(false)) {}
  // nop-out useless instructions
  if (pass(true)) {
    for (auto b : blocks) {
      auto& code = unit.blocks[b].code;
      auto end = std::remove_if(code.begin(), code.end(), [&](Vinstr& inst) {
        return inst.op == Vinstr::nop;
      });
      code.erase(end, code.end());
    }
    printUnit(kVasmDCELevel, "after vasm-dead", unit);
  }
}
Example #11
0
// Compute lifetime intervals and use positions of all intervals by walking
// the code bottom-up once. Loops aren't handled yet.
void Vxls::buildIntervals() {
  livein.resize(unit.blocks.size());
  intervals.resize(unit.next_vr);
  for (auto blockIt = blocks.end(); blockIt != blocks.begin();) {
    auto vlabel = *--blockIt;
    auto& block = unit.blocks[vlabel];
    LiveSet live(unit.next_vr);
    for (auto s : succs(block)) {
      if (!livein[s].empty()) live |= livein[s];
    }
    auto& block_range = block_ranges[vlabel];
    forEach(live, [&](Vreg vr) {
      intervals[vr]->add(block_range);
    });
    auto pos = block_range.end;
    for (auto i = block.code.end(); i != block.code.begin();) {
      auto& inst = *--i;
      pos -= 2;
      DefVisitor dv(live, *this, pos);
      visit(inst, dv);
      RegSet implicit_uses, implicit_defs;
      getEffects(abi, inst, implicit_uses, implicit_defs);
      implicit_defs.forEach([&](Vreg r) {
        dv.def(r);
      });
      UseVisitor uv(live, *this, {block_range.start, pos});
      visit(inst, uv);
      implicit_uses.forEach([&](Vreg r) {
        uv.use(r);
      });
    }
    livein[vlabel] = live;
  }
  for (auto& c : unit.cpool) {
    auto ivl = intervals[c.second];
    if (ivl) {
      ivl->ranges.back().start = 0;
      ivl->cns = true;
      ivl->val = c.first;
    }
  }
  // Each interval's range and use list is backwards; reverse them now.
  for (auto ivl : intervals) {
    if (!ivl) continue;
    assert(!ivl->ranges.empty()); // no empty intervals
    std::reverse(ivl->uses.begin(), ivl->uses.end());
    std::reverse(ivl->ranges.begin(), ivl->ranges.end());
  }
  if (dumpIREnabled(kRegAllocLevel)) {
    print("after building intervals");
  }
  // todo: t4764262 this should check each root, not just position 0.
  for (DEBUG_ONLY auto ivl : intervals) {
    // only constants and physical registers can be live at entry.
    assert(!ivl || ivl->cns || ivl->vreg.isPhys() || ivl->start() > 0);
  }
  assert(check(unit));
}
Example #12
0
void test6() {
  struct S {
    ~S() { }
    S(int i) { }
  };
  live(),
    S            // expected-warning {{will never be executed}}
      (halt());
}
int     AddDay ( int year, int month , int day )
{
        if ( Sepecial ( year ) && month == 2 && day == 28 ) day ++;
        else if ( day == Limit [month] ) { day = 1; month ++; if ( month == 13 ) { month = 1; year ++; } }
        else day ++;
        
        if ( live ( year , month , day ) && !Win [year] [month] [day] ) return 1;
        else return 0;
}
Example #14
0
void test2() {
  try {
    live();
  } catch (int i) {
    live();
  }
  try {
    liveti();
  } catch (int i) {
    live();
  }
  try {
    livetip();
  } catch (int i) {
    live();
  }
  throw 1;
  dead();       // expected-warning {{will never be executed}}
}
Example #15
0
// Remove dead instructions by doing a traditional liveness analysis.
// instructions that mutate memory, physical registers, or status flags
// are considered useful. All branches are considered useful.
//
// Given SSA, there's a faster sparse version of this algorithm that marks
// useful instructions in one pass, then transitively marks pure instructions
// that define inputs to useful instructions. However it requires a mapping
// from vreg numbers to the instruction that defines them, and a way to address
// individual instructions.
//
// We could remove useless branches by computing the post-dominator tree and
// RDF(b) for each block; then a branch is only useful if it controls whether
// or not a useful block executes, and useless branches can be forwarded to
// the nearest useful post-dominator.
void removeDeadCode(Vunit& unit) {
  Timer timer(Timer::vasm_dce);
  auto blocks = sortBlocks(unit);
  jit::vector<LiveSet> livein(unit.blocks.size());
  LiveSet live(unit.next_vr);

  auto pass = [&](bool mutate) {
    bool changed = false;
    for (auto blockIt = blocks.end(); blockIt != blocks.begin();) {
      auto b = *--blockIt;
      auto& block = unit.blocks[b];
      live.reset();
      for (auto s : succs(block)) {
        if (!livein[s].empty()) {
          live |= livein[s];
        }
      }
      for (auto i = block.code.end(); i != block.code.begin();) {
        auto& inst = *--i;
        auto useful = effectful(inst);
        visitDefs(unit, inst, [&](Vreg r) {
          if (r.isPhys() || live.test(r)) {
            useful = true;
            live.reset(r);
          }
        });
        if (useful) {
          visitUses(unit, inst, [&](Vreg r) {
            live.set(r);
          });
        } else if (mutate) {
          inst = nop{};
          changed = true;
        }
      }
      if (mutate) {
        assertx(live == livein[b]);
      } else {
        if (live != livein[b]) {
          livein[b] = live;
          changed = true;
        }
      }
    }
    return changed;
  };

  // analyze until livein reaches a fixed point
  while (pass(false)) {}
  auto const changed = pass(true);
  removeTrivialNops(unit);
  if (changed) {
    printUnit(kVasmDCELevel, "after vasm-dead", unit);
  }
}
Example #16
0
/// @throws AbortError, BackupReadError, BackupWriteError, GetRangesError
Mem::Backup DirectSearch::backup(Mem::Random &ram, Async::AbortableProgress &progress) {
	Mem::Live live(ram);
	std::auto_ptr<Mem::BackupData> data(new Mem::BackupData());
	Mem::SingleBlockEnum block(live, 1, data.get());
	progress.start(block.totalSize());
	while (block.next()) {
		progress.set(block.doneSize());
		progress.check();
	}
	return Mem::Backup(data);
}
main ()
{
        init ();
        scanf ( "%d" , &n );
        for ( i = 0; i < n ; i ++ ) {
                scanf ( "%d %d %d" , &year , &month , &day );
                if ( live ( year , month , day ) && Win [year] [month] [day] )
                        printf ( "YES\n" );
                else printf ( "NO\n" );
        }
}
Example #18
0
void test3() {
  halt()
    --;         // expected-warning {{will never be executed}}
  // FIXME: The unreachable part is just the '?', but really all of this
  // code is unreachable and shouldn't be separately reported.
  halt()        // expected-warning {{will never be executed}}
    ? 
    dead() : dead();
  live(),
    float       // expected-warning {{will never be executed}}
      (halt());
}
static int IdlePageGameOfLifeHandler(struct IdleInfo *Info)
{
  
    StopAllDisplayTimers(); // Think we'll do this when we change pages???
    SetupOneSecondTimer(Info->IdleModeTimerId,
	                     ONE_SECOND,
	                      NO_REPEAT,
	                      BarCode,
	                      NO_MSG_OPTIONS);
    live(Info->buffer);
    StartOneSecondTimer(Info->IdleModeTimerId);
    return IDLE_UPDATE_FULL_SCREEN;
}
Example #20
0
void Entity::render()
{
    myPhysicStrategy.render(getContext());
    myAnimationStrategy.render(getContext());
    myDrawingStrategy.render(getContext());
    myWriteStrategy.render(getContext());
    mySoundStrategy.render(getContext());

    // particles
    live(getContext());

    if(!getContext().getParticleContext().isAlive())
        die(getContext());
}
void    init ()
{
        int     y , m , d;
        AddDay ( 2001 , 11 , 2 );
        for ( y = 2001 ; y >= 1900; y -- )
                for ( m = 12; m > 0; m -- )
                        for ( d = 31; d > 0; d -- ) {
                                if ( !live ( y , m , d ) ) continue;
                                if ( y == 2001 && m == 11 && d == 4 )
                                        Win [y] [m] [d] = 0;
                                else if ( AddDay ( y , m , d ) || AddMonth ( y , m , d ) ) Win [y] [m] [d] = 1;
                                else Win [y] [m] [d] = 0;

                        }
        
}
Example #22
0
/// @throws AbortError, GetRangesError
void PtrSearch::search(Mem::Random &random, const void *address, Async::AbortableProgress &progress) {
	assert(mStatus != PtrStatus::NotStarted);
	if (mStatus == PtrStatus::HasFirstAddress) {
		mStatus = PtrStatus::Started;
		Mem::Backup backup(mBackup.get());
		mBackup = boost::none;
		ptrdiff_t diff = ptrDiff(address, mFirstAddress);
		Mem::Live live(random);
		Mem::DoubleBlockEnum blocks(backup, live, sizeof(void *));
		progress.start(blocks.totalSize());
		while (blocks.next()) {
			mLocList.append(blocks, mFirstAddress, diff);
			progress.set(blocks.doneSize());
			progress.check();
		}
	}
	else {
		Mem::Random::Lock lock(random);
		mLocList.filter(lock, address, progress);
	}
}
Example #23
0
/// @throws AbortError, BackupReadError, BackupWriteError, GetRangesError
void DirectSearch::saveState(Mem::Random &ram, Async::AbortableProgress &progress) {
	if (mStatus == DirectStatus::Started) {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].refresh(lock, progress);
		}
	}
	else {
		Mem::Live live(ram);
		std::auto_ptr<Mem::BackupData> data(new Mem::BackupData());
		Mem::SingleBlockEnum block(live, 1, data.get());
		mBackup = boost::none;
		mStatus = DirectStatus::NotStarted;
		progress.start(block.totalSize());
		while (block.next()) {
			progress.set(block.doneSize());
			progress.check();
		}
		mBackup = Mem::Backup(data);
		mStatus = DirectStatus::SavedBackup;
	}
}
void dash_dynamic_test(const char* ip, int port, const char* file, int width, int height)
{
    std::shared_ptr<dash_playlist_t> live(new dash_playlist_t());
    live->mpd = dash_mpd_create(DASH_DYNAMIC, dash_mpd_onsegment, live.get());
    live->name = "live";
    live->width = width;
    live->height = height;
    live->adapation_audio = live->adapation_video = -1;

    aio_worker_init(4);
	http_server_t* http = http_server_create(ip, port);
	http_server_set_handler(http, http_server_route, live.get());
	http_server_addroute("/live/", dash_server_onlive);
	http_server_addroute("/vod/", dash_server_onvod);

    // live worker
    dash_live_worker(file, live.get());
    
	http_server_destroy(http);
    aio_worker_clean(4);

    dash_mpd_destroy(live->mpd);
}
void test2() {
  int i;
  switch (live()) {
  case 1:
    halt(),
      dead();   // expected-warning {{will never be executed}}

  case 2:
    live(), halt(),
      dead();   // expected-warning {{will never be executed}}

  case 3:
  live()
    +           // expected-warning {{will never be executed}}
    halt();
  dead();

  case 4:
  a4:
    live(),
      halt();
    goto a4;    // expected-warning {{will never be executed}}

  case 5:
    goto a5;
  c5:
    dead();     // expected-warning {{will never be executed}}
    goto b5;
  a5:
    live(),
      halt();
  b5:
    goto c5;

  case 6:
    if (live())
      goto e6;
    live(),
      halt();
  d6:
    dead();     // expected-warning {{will never be executed}}
    goto b6;
  c6:
    dead();
    goto b6;
  e6:
    live(),
      halt();
  b6:
    goto c6;
  case 7:
    halt()
      +
      dead();   // expected-warning {{will never be executed}}
    -           // expected-warning {{will never be executed}}
      halt();
  case 8:
    i
      +=        // expected-warning {{will never be executed}}
      halt();
  case 9:
    halt()
      ?         // expected-warning {{will never be executed}}
      dead() : dead();
  case 10:
    (           // expected-warning {{will never be executed}}
      float)halt();
  case 11: {
    int a[5];
    live(),
      a[halt()
        ];      // expected-warning {{will never be executed}}
  }
  }
}
Example #26
0
 // basic printf
 void _printf()
    {
    printf("%11llu %11llu %11llu %11llu", (long long unsigned int)_allocated, (long long unsigned int)_freed, (long long unsigned int)_maxLive, (long long unsigned int)live());
    }
Example #27
0
void
murder(void)
{
	int n;

	for (n = 0;
	    !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE ||
	        n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL ||
	        n == HALBERD) && testbit(inven, n)) && n < NUMOFOBJECTS;
	    n++);
	if (n == NUMOFOBJECTS) {
		puts("You don't have suitable weapons to kill.");
	} else {
		printf("Your %s should do the trick.\n", objsht[n]);
		while (wordtype[++wordnumber] == ADJS)
			; /* nothing */
		switch (wordvalue[wordnumber]) {
		case NORMGOD:
			if (testbit(location[position].objects, BATHGOD)) {
				puts("The goddess's head slices off.  Her corpse floats in the water.");
				clearbit(location[position].objects, BATHGOD);
				setbit(location[position].objects, DEADGOD);
				power += 5;
				notes[JINXED]++;
			} else if (testbit(location[position].objects, NORMGOD)) {
				puts("The goddess pleads but you strike her mercilessly.  Her broken body lies in a\npool of blood.");
				clearbit(location[position].objects, NORMGOD);
				setbit(location[position].objects, DEADGOD);
				power += 5;
				notes[JINXED]++;
				if (wintime)
					live();
			} else
				puts("I dont see her anywhere.");
			break;
		case TIMER:
			if (testbit(location[position].objects, TIMER)) {
				puts("The old man offers no resistance.");
				clearbit(location[position].objects, TIMER);
				setbit(location[position].objects, DEADTIME);
				power++;
				notes[JINXED]++;
			} else
				puts("Who?");
			break;
		case NATIVE:
			if (testbit(location[position].objects, NATIVE)) {
				puts("The girl screams as you cut her body to shreds.  She is dead.");
				clearbit(location[position].objects, NATIVE);
				setbit(location[position].objects, DEADNATIVE);
				power += 5;
				notes[JINXED]++;
			} else
				puts("What girl?");
			break;
		case MAN:
			if (testbit(location[position].objects, MAN)) {
				puts("You strike him to the ground, and he coughs up blood.");
				puts("Your fantasy is over.");
				die(0);
			}
		case -1:
			puts("Kill what?");
			break;

		default:
			if (wordtype[wordnumber] != NOUNS)
				puts("Kill what?");
			else
				printf("You can't kill the %s!\n",
				    objsht[wordvalue[wordnumber]]);
		}
	}
}
Example #28
0
    bool run()
    {
        for (unsigned i = m_graph.m_variableAccessData.size(); i--;) {
            VariableAccessData* variable = &m_graph.m_variableAccessData[i];
            if (!variable->isRoot())
                continue;
            variable->clearVotes();
        }
        
        // Identify the set of variables that are always subject to the same structure
        // checks. For now, only consider monomorphic structure checks (one structure).
        
        for (BlockIndex blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
            BasicBlock* block = m_graph.m_blocks[blockIndex].get();
            if (!block)
                continue;
            for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
                NodeIndex nodeIndex = block->at(indexInBlock);
                Node& node = m_graph[nodeIndex];
                if (!node.shouldGenerate())
                    continue;
                switch (node.op()) {
                case CheckStructure: {
                    Node& child = m_graph[node.child1()];
                    if (child.op() != GetLocal)
                        break;
                    VariableAccessData* variable = child.variableAccessData();
                    variable->vote(VoteStructureCheck);
                    if (variable->isCaptured() || variable->structureCheckHoistingFailed())
                        break;
                    if (!isCellSpeculation(variable->prediction()))
                        break;
                    noticeStructureCheck(variable, node.structureSet());
                    break;
                }
                    
                case ForwardCheckStructure:
                case ForwardStructureTransitionWatchpoint:
                    // We currently rely on the fact that we're the only ones who would
                    // insert this node.
                    ASSERT_NOT_REACHED();
                    break;
                    
                case GetByOffset:
                case PutByOffset:
                case PutStructure:
                case StructureTransitionWatchpoint:
                case AllocatePropertyStorage:
                case ReallocatePropertyStorage:
                case GetPropertyStorage:
                case GetByVal:
                case PutByVal:
                case PutByValAlias:
                case GetArrayLength:
                case CheckArray:
                case GetIndexedPropertyStorage:
                case Phantom:
                    // Don't count these uses.
                    break;
                    
                default:
                    m_graph.vote(node, VoteOther);
                    break;
                }
            }
        }
        
        // Disable structure hoisting on variables that appear to mostly be used in
        // contexts where it doesn't make sense.
        
        for (unsigned i = m_graph.m_variableAccessData.size(); i--;) {
            VariableAccessData* variable = &m_graph.m_variableAccessData[i];
            if (!variable->isRoot())
                continue;
            if (variable->voteRatio() >= Options::structureCheckVoteRatioForHoisting())
                continue;
            HashMap<VariableAccessData*, CheckData>::iterator iter = m_map.find(variable);
            if (iter == m_map.end())
                continue;
#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
            dataLog("Zeroing the structure to hoist for %s because the ratio is %lf.\n",
                    m_graph.nameOfVariableAccessData(variable), variable->voteRatio());
#endif
            iter->second.m_structure = 0;
        }

        // Identify the set of variables that are live across a structure clobber.
        
        Operands<VariableAccessData*> live(
            m_graph.m_blocks[0]->variablesAtTail.numberOfArguments(),
            m_graph.m_blocks[0]->variablesAtTail.numberOfLocals());
        for (BlockIndex blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
            BasicBlock* block = m_graph.m_blocks[blockIndex].get();
            if (!block)
                continue;
            ASSERT(live.numberOfArguments() == block->variablesAtTail.numberOfArguments());
            ASSERT(live.numberOfLocals() == block->variablesAtTail.numberOfLocals());
            for (unsigned i = live.size(); i--;) {
                NodeIndex indexAtTail = block->variablesAtTail[i];
                VariableAccessData* variable;
                if (indexAtTail == NoNode)
                    variable = 0;
                else
                    variable = m_graph[indexAtTail].variableAccessData();
                live[i] = variable;
            }
            for (unsigned indexInBlock = block->size(); indexInBlock--;) {
                NodeIndex nodeIndex = block->at(indexInBlock);
                Node& node = m_graph[nodeIndex];
                if (!node.shouldGenerate())
                    continue;
                switch (node.op()) {
                case GetLocal:
                case Flush:
                    // This is a birth.
                    live.operand(node.local()) = node.variableAccessData();
                    break;
                    
                case SetLocal:
                case SetArgument:
                    ASSERT(live.operand(node.local())); // Must be live.
                    ASSERT(live.operand(node.local()) == node.variableAccessData()); // Must have the variable we expected.
                    // This is a death.
                    live.operand(node.local()) = 0;
                    break;
                    
                // Use the CFA's notion of what clobbers the world.
                case ValueAdd:
                    if (m_graph.addShouldSpeculateInteger(node))
                        break;
                    if (Node::shouldSpeculateNumber(m_graph[node.child1()], m_graph[node.child2()]))
                        break;
                    clobber(live);
                    break;
                    
                case CompareLess:
                case CompareLessEq:
                case CompareGreater:
                case CompareGreaterEq:
                case CompareEq: {
                    Node& left = m_graph[node.child1()];
                    Node& right = m_graph[node.child2()];
                    if (Node::shouldSpeculateInteger(left, right))
                        break;
                    if (Node::shouldSpeculateNumber(left, right))
                        break;
                    if (node.op() == CompareEq) {
                        if ((m_graph.isConstant(node.child1().index())
                             && m_graph.valueOfJSConstant(node.child1().index()).isNull())
                            || (m_graph.isConstant(node.child2().index())
                                && m_graph.valueOfJSConstant(node.child2().index()).isNull()))
                            break;
                        
                        if (Node::shouldSpeculateFinalObject(left, right))
                            break;
                        if (Node::shouldSpeculateArray(left, right))
                            break;
                        if (left.shouldSpeculateFinalObject() && right.shouldSpeculateFinalObjectOrOther())
                            break;
                        if (right.shouldSpeculateFinalObject() && left.shouldSpeculateFinalObjectOrOther())
                            break;
                        if (left.shouldSpeculateArray() && right.shouldSpeculateArrayOrOther())
                            break;
                        if (right.shouldSpeculateArray() && left.shouldSpeculateArrayOrOther())
                            break;
                    }
                    clobber(live);
                    break;
                }
                    
                case GetByVal:
                case PutByVal:
                case PutByValAlias:
                    if (m_graph.byValIsPure(node))
                        break;
                    clobber(live);
                    break;
                    
                case GetMyArgumentsLengthSafe:
                case GetMyArgumentByValSafe:
                case GetById:
                case GetByIdFlush:
                case PutStructure:
                case PhantomPutStructure:
                case PutById:
                case PutByIdDirect:
                case Call:
                case Construct:
                case Resolve:
                case ResolveBase:
                case ResolveBaseStrictPut:
                case ResolveGlobal:
                    clobber(live);
                    break;
                    
                default:
                    ASSERT(node.op() != Phi);
                    break;
                }
            }
        }
        
        bool changed = false;

#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
        for (HashMap<VariableAccessData*, CheckData>::iterator it = m_map.begin();
             it != m_map.end(); ++it) {
            if (!it->second.m_structure) {
                dataLog("Not hoisting checks for %s because of heuristics.\n", m_graph.nameOfVariableAccessData(it->first));
                continue;
            }
            if (it->second.m_isClobbered && !it->second.m_structure->transitionWatchpointSetIsStillValid()) {
                dataLog("Not hoisting checks for %s because the structure is clobbered and has an invalid watchpoint set.\n", m_graph.nameOfVariableAccessData(it->first));
                continue;
            }
            dataLog("Hoisting checks for %s\n", m_graph.nameOfVariableAccessData(it->first));
        }
#endif // DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
        
        // Make changes:
        // 1) If a variable's live range does not span a clobber, then inject structure
        //    checks before the SetLocal.
        // 2) If a variable's live range spans a clobber but is watchpointable, then
        //    inject structure checks before the SetLocal and replace all other structure
        //    checks on that variable with structure transition watchpoints.
        
        InsertionSet<NodeIndex> insertionSet;
        for (BlockIndex blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
            BasicBlock* block = m_graph.m_blocks[blockIndex].get();
            if (!block)
                continue;
            for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
                NodeIndex nodeIndex = block->at(indexInBlock);
                Node& node = m_graph[nodeIndex];
                // Be careful not to use 'node' after appending to the graph. In those switch
                // cases where we need to append, we first carefully extract everything we need
                // from the node, before doing any appending.
                if (!node.shouldGenerate())
                    continue;
                switch (node.op()) {
                case SetArgument: {
                    ASSERT(!blockIndex);
                    // Insert a GetLocal and a CheckStructure immediately following this
                    // SetArgument, if the variable was a candidate for structure hoisting.
                    // If the basic block previously only had the SetArgument as its
                    // variable-at-tail, then replace it with this GetLocal.
                    VariableAccessData* variable = node.variableAccessData();
                    HashMap<VariableAccessData*, CheckData>::iterator iter = m_map.find(variable);
                    if (iter == m_map.end())
                        break;
                    if (!iter->second.m_structure)
                        break;
                    if (iter->second.m_isClobbered && !iter->second.m_structure->transitionWatchpointSetIsStillValid())
                        break;
                    
                    node.ref();

                    CodeOrigin codeOrigin = node.codeOrigin;
                    
                    Node getLocal(GetLocal, codeOrigin, OpInfo(variable), nodeIndex);
                    getLocal.predict(variable->prediction());
                    getLocal.ref();
                    NodeIndex getLocalIndex = m_graph.size();
                    m_graph.append(getLocal);
                    insertionSet.append(indexInBlock + 1, getLocalIndex);
                    
                    Node checkStructure(CheckStructure, codeOrigin, OpInfo(m_graph.addStructureSet(iter->second.m_structure)), getLocalIndex);
                    checkStructure.ref();
                    NodeIndex checkStructureIndex = m_graph.size();
                    m_graph.append(checkStructure);
                    insertionSet.append(indexInBlock + 1, checkStructureIndex);
                    
                    if (block->variablesAtTail.operand(variable->local()) == nodeIndex)
                        block->variablesAtTail.operand(variable->local()) = getLocalIndex;
                    
                    m_graph.substituteGetLocal(*block, indexInBlock, variable, getLocalIndex);
                    
                    changed = true;
                    break;
                }
                    
                case SetLocal: {
                    VariableAccessData* variable = node.variableAccessData();
                    HashMap<VariableAccessData*, CheckData>::iterator iter = m_map.find(variable);
                    if (iter == m_map.end())
                        break;
                    if (!iter->second.m_structure)
                        break;
                    if (iter->second.m_isClobbered && !iter->second.m_structure->transitionWatchpointSetIsStillValid())
                        break;

                    // First insert a dead SetLocal to tell OSR that the child's value should
                    // be dropped into this bytecode variable if the CheckStructure decides
                    // to exit.
                    
                    CodeOrigin codeOrigin = node.codeOrigin;
                    NodeIndex child1 = node.child1().index();
                    
                    Node setLocal(SetLocal, codeOrigin, OpInfo(variable), child1);
                    NodeIndex setLocalIndex = m_graph.size();
                    m_graph.append(setLocal);
                    insertionSet.append(indexInBlock, setLocalIndex);
                    m_graph[child1].ref();
                    // Use a ForwardCheckStructure to indicate that we should exit to the
                    // next bytecode instruction rather than reexecuting the current one.
                    Node checkStructure(ForwardCheckStructure, codeOrigin, OpInfo(m_graph.addStructureSet(iter->second.m_structure)), child1);
                    checkStructure.ref();
                    NodeIndex checkStructureIndex = m_graph.size();
                    m_graph.append(checkStructure);
                    insertionSet.append(indexInBlock, checkStructureIndex);
                    changed = true;
                    break;
                }
                    
                case CheckStructure: {
                    Node& child = m_graph[node.child1()];
                    if (child.op() != GetLocal)
                        break;
                    HashMap<VariableAccessData*, CheckData>::iterator iter = m_map.find(child.variableAccessData());
                    if (iter == m_map.end())
                        break;
                    if (!iter->second.m_structure)
                        break;
                    if (!iter->second.m_isClobbered) {
                        node.setOpAndDefaultFlags(Phantom);
                        ASSERT(node.refCount() == 1);
                        break;
                    }
                    if (!iter->second.m_structure->transitionWatchpointSetIsStillValid())
                        break;
                    ASSERT(iter->second.m_structure == node.structureSet().singletonStructure());
                    node.convertToStructureTransitionWatchpoint();
                    changed = true;
                    break;
                }
                    
                default:
                    break;
                }
            }
            insertionSet.execute(*block);
        }
        
        return changed;
    }
Example #29
0
shoot()
{
	int firstnumber, value;
	register int n;

	if (!testbit(inven,LASER))
		puts("You aren't holding a blaster.");
	else {
		firstnumber = wordnumber;
		while(wordtype[++wordnumber] == ADJS);
		while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){
			value = wordvalue[wordnumber];
			printf("%s:\n", objsht[value]);
			for (n=0; objsht[value][n]; n++);
			if (testbit(location[position].objects,value)){
				clearbit(location[position].objects,value);
				time++;
				printf("The %s explode%s\n",objsht[value],(objsht[value][n-1]=='s' ? (objsht[value][n-2]=='s' ? "s." : ".") : "s."));
				if (value == BOMB)
					die();
			}
			else
				printf("I dont see any %s around here.\n", objsht[value]);
			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
				wordnumber++;
			else
				return(firstnumber);
		}
			    /* special cases with their own return()'s */

		if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS){
			time++;
			switch(wordvalue[wordnumber]){
			
				case DOOR:
					switch(position){
						case 189:
						case 231:
							puts("The door is unhinged.");
							location[189].north = 231;
							location[231].south = 189;
							whichway(location[position]);
							break;
						case 30:
							puts("The wooden door splinters.");
							location[30].west = 25;
							whichway(location[position]);
							break;
						case 31:
							puts("The laser blast has no effect on the door.");
							break;
						case 20:
							puts("The blast hits the door and it explodes into flame.  The magnesium burns");
							puts("so rapidly that we have no chance to escape.");
							die();
						default:
							puts("Nothing happens.");
					}
					break;

				case NORMGOD:
					if (testbit(location[position].objects,BATHGOD)){
						puts("The goddess is hit in the chest and splashes back against the rocks.");
						puts("Dark blood oozes from the charred blast hole.  Her naked body floats in the");
						puts("pools and then off downstream.");
						clearbit(location[position].objects,BATHGOD);
						setbit(location[180].objects,DEADGOD);
						power += 5;
						ego -= 10;
						notes[JINXED]++;
					} else if (testbit(location[position].objects,NORMGOD)){
						puts("The blast catches the goddess in the stomach, knocking her to the ground.");
						puts("She writhes in the dirt as the agony of death taunts her.");
						puts("She has stopped moving.");
						clearbit(location[position].objects,NORMGOD);
						setbit(location[position].objects,DEADGOD);
						power += 5;
						ego -= 10;
						notes[JINXED]++;
						if (wintime)
							live();
						break;
					} else
						puts("I don't see any goddess around here.");
					break;

				case TIMER:
					if (testbit(location[position].objects,TIMER)){
						puts("The old man slumps over the bar.");
						power++;
						ego -= 2;
						notes[JINXED]++;
						clearbit(location[position].objects,TIMER);
						setbit(location[position].objects,DEADTIME);
					}
					else puts("What old timer?");
					break;
				case MAN:
					if (testbit(location[position].objects,MAN)){
						puts("The man falls to the ground with blood pouring all over his white suit.");
						puts("Your fantasy is over.");
						die();
					}
					else puts("What man?");
					break;
				case NATIVE:
					if (testbit(location[position].objects,NATIVE)){
						puts("The girl is blown backwards several feet and lies in a pool of blood.");
						clearbit(location[position].objects,NATIVE);
						setbit(location[position].objects,DEADNATIVE);
						power += 5;
						ego -= 2;
						notes[JINXED]++;
					} else puts("There is no girl here.");
					break;
				case -1:
					puts("Shoot what?");
					break;

				default:
					printf("You can't shoot the %s.\n",objsht[wordvalue[wordnumber]]);
			}
		}
		else puts("You must be a looney.");
	}
	return(firstnumber);
}
Example #30
0
int give(void)
{
    int obj = -1, result = -1, person = 0, firstnumber, last1, last2;

    last1 = last2 = 0;
    firstnumber = wordnumber;
    while (wordtype[++wordnumber] != OBJECT && wordvalue[wordnumber] != AMULET && wordvalue[wordnumber] != MEDALION && wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount)
	continue;
    if (wordnumber <= wordcount) {
	obj = wordvalue[wordnumber];
	if (obj == EVERYTHING)
	    wordtype[wordnumber] = -1;
	last1 = wordnumber;
    }
    wordnumber = firstnumber;
    while ((wordtype[++wordnumber] != NOUNS || wordvalue[wordnumber] == obj) && wordnumber <= wordcount);
    if (wordtype[wordnumber] == NOUNS) {
	person = wordvalue[wordnumber];
	last2 = wordnumber;
    }
    // Setting wordnumber to last1 - 1 looks wrong if last1 is 0, e.g.,
    // plain `give'. However, detecting this case is liable to detect
    // `give foo' as well, which would give a confusing error. We
    // need to make sure the -1 value can cause no problems if it arises.
    // If in the below we get to the drop("Given") then drop will look
    // at word 0 for an object to give, and fail, which is OK; then
    // result will be -1 and we get to the end, where wordnumber gets
    // set to something more sensible. If we get to "I don't think
    // that is possible" then again wordnumber is set to something
    // sensible. The wordnumber we leave with still isn't right if
    // you include words the game doesn't know in your command, but
    // that's no worse than what other commands than give do in
    // the same place.
    wordnumber = last1 - 1;
    if (person && testbit(location[position].objects, person)) {
	if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET))
	    puts("The goddess won't look at you.");
	else
	    result = drop("Given");
    } else {
	puts("I don't think that is possible.");
	wordnumber = max(last1, last2) + 1;
	return 0;
    }
    if (result != -1 && (testbit(location[position].objects, obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)) {
	clearbit(location[position].objects, obj);
	ourtime++;
	ego++;
	switch (person) {
	    case NATIVE:
		puts("She accepts it shyly.");
		ego += 2;
		break;
	    case NORMGOD:
		if (obj == RING || obj == BRACELET) {
		    puts("She takes the charm and puts it on. A little kiss on the cheek is");
		    puts("your reward.");
		    ego += 5;
		    godready += 3;
		}
		if (obj == AMULET || obj == MEDALION || obj == TALISMAN) {
		    win++;
		    ego += 5;
		    power -= 5;
		    if (win >= 3) {
			puts("The powers of the earth are now legitimate. You have destroyed the Darkness");
			puts("and restored the goddess to her throne. The entire island celebrates with");
			puts("dancing and spring feasts. As a measure of her gratitude, the goddess weds you");
			puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus.");
			clearbit(location[position].objects, MEDALION);
			wintime = ourtime;
			live();
		    }
		}
		break;
	    case TIMER:
		if (obj == COINS) {
		    puts("He fingers the coins for a moment and then looks up agape. `Kind you are and");
		    puts("I mean to repay you as best I can.'  Grabbing a pencil and cocktail napkin...\n");
		    printf("+-----------------------------------------------------------------------------+\n");
		    printf("|				   xxxxxxxx\\				      |\n");
		    printf("|				       xxxxx\\	CLIFFS			      |\n");
		    printf("|		FOREST			  xxx\\				      |\n");
		    printf("|                          \\\\           x\\               OCEAN         |\n");
		    printf("|				||	       x\\			      |\n");
		    printf("|				||  ROAD	x\\			      |\n");
		    printf("|				||		x\\			      |\n");
		    printf("|		SECRET		||	  .........			      |\n");
		    printf("|		 - + -		||	   ........			      |\n");
		    printf("|		ENTRANCE	||		...      BEACH		      |\n");
		    printf("|				||		...		  E	      |\n");
		    printf("|				||		...		  |	      |\n");
		    printf("|				//		...	    N <-- + --- S     |\n");
		    printf("|		PALM GROVE     //		...		  |	      |\n");
		    printf("|			      //		...		  W	      |\n");
		    printf("+-----------------------------------------------------------------------------+\n");
		    puts("\n`This map shows a secret entrance to the catacombs.");
		    puts("You will know when you arrive because I left an old pair of shoes there.'");
		}
		break;
	}
    }
    wordnumber = max(last1, last2) + 1;
    return firstnumber;
}