Пример #1
0
int BoolTest::run(Env &env, LocalDefs &ienv)
{
  //cout << "---------------------------------\n";
  //term1.print(cout);
  //cout << "\n";
  //term2.print(cout);
  //cout << "\n\n";

  //Term et1 = prg.evaluate(term1);
  //Term et2 = prg.evaluate(term2);

  //cout << "\n\n";
  //et1.print(cout);
  //cout << "\n";
  //et2.print(cout);
  //cout << "\n";

  //string es = expr.to_string();

  Env new_env(env);

  Term et = expr.evaluate(new_env, ienv);

  string ts = et.to_string();

  if (et.is_true())
  {
    cout << "Test OK" << endl;
    return 0;
  }

  cout << "Test Failed" << endl;

  //string rs_str = t.top_symbol().to_string();

  //if (t.top_symbol() == Symbol::eq())
  //{
  //  assert(t.arity() == 2);

  //  Term st1 = t.subterm(0);
  //  Term st2 = t.subterm(1);

  //  Term et1 = prg.evaluate(st1);
  //  Term et2 = prg.evaluate(st2);

  //  if (et1 != et2)
  //  {
  //    cout << "-------------" << endl;
  //    cout << st1.to_string() << endl << st2.to_string() << endl;
  //    cout << "- - - - - - -" << endl;
  //    cout << et1.to_string() << endl << et2.to_string() << endl;
  //    cout << "-------------" << endl;
  //  }
  //}

  //getchar();

  return 1;
}
Пример #2
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);
}
Пример #3
0
NextAction AssertStmt::execute(Env &env, LocalDefs &ie)
{
	Term v = expr.evaluate(env, ie);
  if (!v.is_true())
  {
    cout << "Assertion failed somewhere\n";
    Program::get_singleton().print_stack();
    halt;  
  }

	return NextAction(NextAction::continue_normal_execution);
}
Пример #4
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);
		}
	}
}