예제 #1
0
NextAction IfStmt::execute(Env &env, LocalDefs &ie)
{
	Term ec = cond.evaluate(env, ie);
	
	if (!ec.is_true() && !ec.is_false())
	{
		string ecs = ec.to_string(true);
		cout << "Condition for if statement doesn't evaluate to either true or false:\n";
		cout << ecs << endl;
		halt;	
	}
	//assert(ec.is_true() || ec.is_false());

	if (ec.is_true())
		return if_true->execute(env, ie);
	else if (!if_false.is_null())
		return if_false->execute(env, ie);
	else
		return NextAction(NextAction::continue_normal_execution);
}
예제 #2
0
NextAction LoopStmt::execute(Env &env, LocalDefs &ie)
{
	for (bool first=true ; ; first=false)
	{
		Term ec = first && is_tail_cond ? bool_obj(true) : cond.evaluate(env, ie);
		assert(ec.is_true() || ec.is_false());

		if (ec.is_true())
		{
			NextAction res = body->execute(env, ie);
			if (res.is_return())
				return res;
		  if (res.is_break())
  			return NextAction(NextAction::continue_normal_execution);
		}
		else
		{
			return NextAction(NextAction::continue_normal_execution);
		}
	}
}