bool SeqType::contains(Term &t)
{
  if (!t.is_seq())
    return false;
  
  for (int i=0 ; i < t.size() ; i++)
    if (!elem_type->contains(t.item(i)))
      return false;
  
  return !nonempty || t.size() > 0;
}
bool SetType::contains(Term &t)
{
  if (!t.is_set())
    return false;
  
  for (int i=0 ; i < t.size() ; i++)
    if (!elem_type->contains(t.item(i)))
      return false;
  
  return true;
}
bool FixedSeqType::contains(Term &t)
{
  if (!t.is_seq() || t.size() != elem_types.size())
    return false;
  
  int len = t.size();
  for (int i=0 ; i < len ; i++)
    if (!elem_types[i]->contains(t.item(i)))
      return false;

  return true;
}
Beispiel #4
0
NextAction ForStatement::execute(Env &env, LocalDefs &ie)
{
  if (src_expr.is_null())
  {
    assert(idx_var.is_null());
    assert(!start_expr.is_null());
    assert(!end_expr.is_null());

    Term start_obj = start_expr.evaluate(env, ie);
    Term end_obj = end_expr.evaluate(env, ie);
    
    if (start_obj.is_int() && end_obj.is_int()) // && start_obj.get_int() <= end_obj.get_int())
    {
      int start = start_obj.get_int();
      int end = end_obj.get_int();
      
      //assert(start <= end);
      
      for (int i=start ; i <= end ; i++)
	    {
	      env.set(var, int_obj(i));
		    NextAction res = body->execute(env, ie);
		    env.unset(var);
    		
		    if (res.is_return())
			    return res;
	      if (res.is_break())
			    return NextAction(NextAction::continue_normal_execution);
	    }
	    
      return NextAction(NextAction::continue_normal_execution);
    }

    cout << "Invalid range in for loop or sequence comprehension\n";
    cout << start_obj.to_string(true) << endl;
    cout << end_obj.to_string(true) << endl;
    Program::get_singleton().print_stack();    
    halt;
  }
  else
  {
    assert(start_expr.is_null());
    assert(end_expr.is_null());
    
    Term src = src_expr.evaluate(env, ie);
    
    int len = src.size();
    for (int i=0 ; i < len ; i++)
	  {
	    env.set(var, src.item(i));
	    if (idx_var != PlainId())
	      env.set(idx_var, int_obj(i));
  	  
		  NextAction res = body->execute(env, ie);
  		
		  env.unset(var);
	    if (idx_var != PlainId())
	      env.unset(idx_var);
  		
		  if (res.is_return())
			  return res;
	    if (res.is_break())
			  return NextAction(NextAction::continue_normal_execution);
	  }
  }
  
  return NextAction(NextAction::continue_normal_execution);
}