Example #1
0
//two args: exp & tail_context
static cellpoint eval_or(void)
{
	reg = cdr(args_ref(1));
	if (is_true(is_null(reg))){
		args_pop(2);
		return a_false;
	}
	stack_push(&vars_stack, reg);
	while (is_false(is_null(cdr(reg)))){
		//evals the expressions which aren't the last expression
		args_push(a_false);
		args_push(car(reg));
		reg = eval();
		if (is_true(reg)){
			args_pop(2);
			return reg;
		}
		//renews the remaining expressions
		stack_push(&vars_stack, cdr(stack_pop(&vars_stack)));
		reg = stack_top(&vars_stack);
	}
	//evals the last expressions
	args_push(args_ref(2));
	args_push(car(stack_pop(&vars_stack)));
	reg = eval();
	args_pop(2);
	return reg;
}
Example #2
0
//one arg: exp
static cellpoint definition_value(void)
{
	if (is_true(is_null(cdr(cdr(args_ref(1)))))){
		printf("define: bad syntax in: ");
		write(args_ref(1));
		newline();
		error_handler();
	}
	reg = car(cdr(args_ref(1)));
	if (is_true(is_symbol(reg))){
		reg = car(cdr(cdr(args_ref(1))));
	}else {
		//get formal arguments list
		reg = cdr(reg);
		stack_push(&vars_stack, reg);
		//get body
		reg = cdr(cdr(args_ref(1)));
		//make a lambda expression
		args_push(reg);
		args_push(stack_pop(&vars_stack));
		reg = make_lambda();
	}
	args_pop(1);
	return reg;
}
Example #3
0
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
{
  switch (key)
    {
    case ARG_FOLDER:
      explicit_folder = 1;
      folder_name = arg;
      break;

    case ARG_INTERACTIVE:
      interactive = is_true (arg);
      break;

    case ARG_NOINTERACTIVE:
      interactive = 0;
      break;
	
    case ARG_RECURSIVE:
      recurse = is_true (arg);
      break;
      
    case ARG_NORECURSIVE:
      recurse = 0;
      break;

    case ARG_LICENSE:
      mh_license (argp_program_version);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
Example #4
0
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
{
  switch (key)
    {
    case ARG_LICENSE:
      mh_license (argp_program_version);
      break;

    case ARG_ALIAS:
      mh_alias_read (arg, 1);
      break;

    case ARG_NOALIAS:
      nolist_mode = 1;
      break;
      
    case ARG_LIST:
      list_mode = is_true (arg);
      break;
	
    case ARG_NORMALIZE:
      normalize_mode = is_true (arg);
      break;

    case ARG_USER:
      user_mode = is_true (arg);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
Example #5
0
static package
bf_verb_code(Var arglist, Byte next, void *vdata, Objid progr)
{				/* (object, verb-desc [, fully-paren [, indent]]) */
    int nargs = arglist.v.list[0].v.num;
    Objid oid = arglist.v.list[1].v.obj;
    Var desc = arglist.v.list[2];
    int parens = nargs >= 3 && is_true(arglist.v.list[3]);
    int indent = nargs < 4 || is_true(arglist.v.list[4]);
    db_verb_handle h;
    Var code;
    enum error e;

    if ((e = validate_verb_descriptor(desc)) != E_NONE
	|| (e = E_INVARG, !valid(oid))) {
	free_var(arglist);
	return make_error_pack(e);
    }
    h = find_described_verb(oid, desc);
    free_var(arglist);

    if (!h.ptr)
	return make_error_pack(E_VERBNF);
    else if (!db_verb_allows(h, progr, VF_READ))
	return make_error_pack(E_PERM);

    code = new_list(0);
    unparse_program(db_verb_program(h), lister, &code, parens, indent,
		    MAIN_VECTOR);

    return make_var_pack(code);
}
Example #6
0
void
test_map_pairs (void* data)
{
	Map* map = Map_new(runtime);

	Map_put(map, hash_for(NIL), NIL, TRUE);
	Map_put(map, hash_for(TRUE), TRUE, FALSE);
	Map_put(map, hash_for(FALSE), FALSE, NIL);

	Vector* pairs = Map_pairs(map);

	for (uint64_t i = 0; i < Vector_length(pairs); i++) {
		Tuple* pair = Vector_get(pairs, i);

		if (is_nil(Tuple_get(pair, 0))) {
			tt_assert(is_true(Tuple_get(pair, 1)));
		}
		else if (is_true(Tuple_get(pair, 0))) {
			tt_assert(is_false(Tuple_get(pair, 1)));
		}
		else if (is_false(Tuple_get(pair, 0))) {
			tt_assert(is_nil(Tuple_get(pair, 1)));
		}
	}

end:
	Map_destroy(map);
}
String Conjunct::print_to_string(int true_printed) {
  String s=""; 

  int num = myLocals.size();
  if(num) {
    s += "Exists ( ";
    int i;
    for (i = 1; i <= num; i++) {
      Variable_ID v = myLocals[i];
      s += v->char_name();
      if(i < num) s += ",";
    }
    if (true_printed || !(is_true())) s += " : ";
  }

  if(is_true()) {
    s += true_printed ? "TRUE" : "";
  } else { 
    if (is_unknown()) 
      s += "UNKNOWN";
    else {
      s += problem->prettyPrintProblemToString();
      if (!exact)
        s += " && UNKNOWN";
    } 
  }


  if (num) s += ")";
  return s;
}
Example #8
0
/////////////////////////////////////////////////////////////
//apply
//requires three arguments:proc , args & tail_context
////////////////////////////////////////////////////////////
cellpoint apply(void)
{
	if (is_true(is_prim_proc(args_ref(1)))){
		reg = args_ref(1);
		args_push(args_ref(2));
		args_push(reg);
		reg = apply_prim_proc();
	}else if (is_true(is_compound_proc(args_ref(1)))){
		//if this application isn't in a tail context,
		//then store the current_env
		if (is_false(args_ref(3))){
			stack_push(&env_stack, current_env);
		}
		/*for test
		  test the tail recursion
		 */
//		printf("call ");
//		write(args_ref(1));
//		newline();
//		args_push(env_stack);
//		printf("the length of env_stack: %d\n", get_integer(list_len()));
		//calls procedure_parameters
		args_push(args_ref(1));
		reg = procedure_parameters();
		stack_push(&vars_stack, reg);
		//calls procedure_env
		args_push(args_ref(1));
		reg = procedure_env();
		//calls extend_env
		stack_push(&vars_stack, args_ref(2));
		args_push(reg);
		args_push(stack_pop(&vars_stack));
		args_push(stack_pop(&vars_stack));
		current_env = extend_env();
		//calls procedure_body
		args_push(args_ref(1));
		reg = procedure_body();
		//calls eval_lambda_body
		args_push(reg);
		reg = eval_lambda_body();
		//if this application isn't in tail context,
		//then restore the stored current_env
		if (is_false(args_ref(3))){
			current_env = stack_pop(&env_stack);
		}
	}else {
		printf("Unknown procedure : ");
		write(args_ref(1));
		newline();
		error_handler();
	}
	args_pop(3);
	return reg;
}
Example #9
0
static void check_bindings(char *proc, cellpoint binding, cellpoint exp)
{
	if (is_true(is_list(binding))){
		if (is_true(is_symbol(car(binding))) && 
			is_false(is_null(cdr(binding))) &&
			is_true(is_null(cdr(cdr(binding))))){
			return;
		}
	}
	printf("%s: Bad syntax (no an identifier and expression for binding) in: ", proc);
	write(exp);
	newline();
	error_handler();
}
Example #10
0
static struct rmsgpack_dom_value operator_and(struct rmsgpack_dom_value input,
      unsigned argc, const struct argument * argv)
{
   unsigned i;
   struct rmsgpack_dom_value res;
   memset(&res, 0, sizeof(res));

   res.type = RDT_BOOL;
   res.val.bool_ = 0;

   for (i = 0; i < argc; i++)
   {
      if (argv[i].type == AT_VALUE)
         res = equals(input, 1, &argv[i]);
      else
      {
         res = is_true(
               argv[i].a.invocation.func(input,
                  argv[i].a.invocation.argc,
                  argv[i].a.invocation.argv
                  ),
               0, NULL);
      }

      if (!res.val.bool_)
         return res;
   }
   return res;
}
Example #11
0
// want to verify that we can observe the correct end counter value
// in the face of concurrent updates
static void concurrentCounters(void)
{
  int i, num_threads = 4;
  struct counter_data data = { 0, 100000, 0, NULL };
  pthread_t threads[num_threads];

  data.scope = ph_counter_scope_define(NULL, "testConcurrentCounters", 1);
  is_true(data.scope != NULL);

  data.slot = ph_counter_scope_register_counter(data.scope, "dummy");
  is(0, data.slot);

  for (i = 0; i < num_threads; i++) {
    pthread_create(&threads[i], NULL, spin_and_count, &data);
  }

  /* unleash the threads on the data */
  ck_pr_store_uint(&data.barrier, 1);

  for (i = 0; i < num_threads; i++) {
    void *unused;
    pthread_join(threads[i], &unused);
  }

  is(num_threads * data.iters,
      ph_counter_scope_get(data.scope, data.slot));
}
Example #12
0
File: interp.c Project: mdoug/FIAL
static inline int execute_if (node *stmt, exec_env *env)
{
	int ret;
	value val;

	ret = eval_expression(&val, stmt->left, env);
	if(ret  < 0) {
		return ret;
	} else {
		ret = 0;
	}
	if(is_true(&val)) {
		ret = push_block(env, stmt->right);
		if(ret >= 0) {
			env->skip_advance = 1;
			return 0;
		}
		env->error.code = ERROR_BAD_ALLOC;
		env->error.line = stmt->loc.line;
		env->error.col  = stmt->loc.col;
		env->error.file = env->lib->label;
		env->error.static_msg = "unable to push block.";

		return ret;
	}
	return 1;
}
Example #13
0
//one arg: ops
static cellpoint list_of_values(void)
{
	args_push(args_ref(1));
	reg = no_operands();
	if (is_true(reg)){
		reg = NIL;
	}else {
		//get the first operand
		args_push(args_ref(1));
		reg = first_operand();
		//eval the first operand with tail_context is a_false
		args_push(a_false);
		args_push(reg);
		reg = eval();
		stack_push(&vars_stack, reg);
		//eval the rest operands
		args_push(args_ref(1));
		reg = rest_operands();
		args_push(reg);
		reg = list_of_values();
		
		reg = cons(stack_pop(&vars_stack), reg);
	}
	args_pop(1);
	return reg;
}
Example #14
0
void
goto_symext::claim(const expr2tc &claim_expr, const std::string &msg) {

  if (unwinding_recursion_assumption)
    return ;

  // Can happen when evaluating certain special intrinsics. Gulp.
  if (cur_state->guard.is_false())
    return;

  total_claims++;

  expr2tc new_expr = claim_expr;
  cur_state->rename(new_expr);

  // first try simplifier on it
  do_simplify(new_expr);

  if (is_true(new_expr))
    return;

  cur_state->guard.guard_expr(new_expr);
  cur_state->global_guard.guard_expr(new_expr);
  remaining_claims++;
  target->assertion(cur_state->guard.as_expr(), new_expr, msg,
                    cur_state->gen_stack_trace(),
                    cur_state->source);
}
Example #15
0
//two args: exp & tail_context
static cellpoint eval_if(void)
{
	//computes if_predicate
	args_push(args_ref(1));
	reg = if_predicate();
	//tail_context is a_false
	args_push(a_false);
	args_push(reg);
	reg = eval();
	if (is_true(reg)){
		//computes if_consequent
		args_push(args_ref(1));
		reg = if_consequent();
		//transmits the tail_context
		args_push(args_ref(2));
		args_push(reg);
		reg = eval();
	}else {
		//computes if_alternative
		args_push(args_ref(1));
		reg = if_alternative();
		//transmits the tail_context
		args_push(args_ref(2));
		args_push(reg);
		reg = eval();
	}
	args_pop(2);
	return reg;
}
Example #16
0
        // Not
        tribool operator!() const
        {
            if (is_unknown())
                return tribool();

            return tribool(!is_true());
        }
Example #17
0
//one arg: exp
static cellpoint letstar_2_nested_lets(void)
{
	//get the reverse list of bindings list
	args_push(args_ref(1));
	reg = letstar_bindings();
	args_push(reg);
	reg = reverse();
	stack_push(&vars_stack, reg);
	//get body of let* expression
	args_push(args_ref(1));
	reg = letstar_body();
	//create nested lets
	if (is_true(is_null(stack_top(&vars_stack)))){
		args_push(reg);
		args_push(stack_pop(&vars_stack));
		reg = make_let();
	}else {
		while (is_false(is_null(stack_top(&vars_stack)))){
			check_bindings("let*", car(stack_top(&vars_stack)), args_ref(1));
			args_push(reg);
			args_push(cons(car(stack_top(&vars_stack)), NIL));
			reg = make_let();
			reg = cons(reg, NIL);
			//renews bingdings
			stack_push(&vars_stack, cdr(stack_pop(&vars_stack)));
		}
		stack_pop(&vars_stack);
		reg = car(reg);
	}
	args_pop(1);
	return reg;
}
Example #18
0
void guardt::add(const exprt &expr)
{
  assert(expr.type().id()==ID_bool);

  if(is_false() || expr.is_true())
    return;
  else if(is_true() || expr.is_false())
  {
    *this=expr;

    return;
  }
  else if(id()!=ID_and)
  {
    and_exprt a;
    a.copy_to_operands(*this);
    *this=a;
  }

  operandst &op=operands();

  if(expr.id()==ID_and)
    op.insert(op.end(),
              expr.operands().begin(),
              expr.operands().end());
  else
    op.push_back(expr);
}
void test() {
  /* Field testing: NWERC 2012 Problem I, Kattis pieceittogether */
  /* TODO: UVa 11294, UVa 10319 */

  for (int n = 1; n <= 15; n++) {
    for (int iter = 0; iter < 100; iter++) {
      int cnt = randint(1, 100);
      vii clauses(cnt);
      for (int i = 0; i < cnt; i++) {
        int a = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
        int b = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
        clauses[i] = ii(a, b);
      }
      // cout << n << " " << iter << " " << cnt << endl;

      TwoSat ts(n);
      iter(it,clauses) {
        ts.add_or(it->first, it->second);
      }
      if (ts.sat()) {
        vector<bool> is_true(n+1, false);
        // for (int i = 0; i < size(all_truthy); i++) if (all_truthy[i] > 0) is_true[all_truthy[i]] = true;
        rep(i,0,n) if (V[n+(i+1)].val == 1) is_true[i+1] = true;
        for (int i = 0; i < cnt; i++) {
          bool a = is_true[abs(clauses[i].first)],
             b = is_true[abs(clauses[i].second)];
          assert_true((clauses[i].first > 0 ? a : !a) || (clauses[i].second > 0 ? b : !b), true);
        }
      } else {
        for (int j = 0; j < (1<<n); j++) {
Example #20
0
void
test_map_put (void* data)
{
	Map*   map  = Map_new(runtime);
	Tuple* pair = Map_put(map, hash_for(TRUE), TRUE, FALSE);

	tt_assert(is_true(Tuple_get(pair, 0)));
	tt_assert(is_false(Tuple_get(pair, 1)));

	pair = Map_put(map, hash_for(TRUE), TRUE, NIL);

	tt_assert(is_true(Tuple_get(pair, 0)));
	tt_assert(is_nil(Tuple_get(pair, 1)));

end:
	Map_destroy(map);
}
result test_string_equals_EmptyStrings() {
	int passed = 0;
	char* description = "string_equals(char*, char*) : 2EmptyString CASE";

	passed = is_true(string_equals("", ""));

	return (result){passed, description};
}
result test_string_substring_StringWithSubstring() {
	int passed = 0;
	char* description = "string_substring(char*, char*) : StringWithSubstring CASE";

	passed = is_true(string_substring("abc", "ab"));

	return (result){passed, description};
}
Example #23
0
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
{
  switch (key)
    {
    case ARG_FOLDER: 
      mh_set_current_folder (arg);
      break;

    case ARG_SEQUENCE:
      add_sequence (arg);
      break;

    case ARG_ADD:
    case ARG_DELETE:
    case ARG_LIST:
      action = key;
      break;
      
    case ARG_PUBLIC:
      if (is_true (arg))
	seq_flags &= ~SEQ_PRIVATE;
      else
	seq_flags |= SEQ_PRIVATE;
      break;
      
    case ARG_NOPUBLIC:
      seq_flags |= SEQ_PRIVATE;
      break;
      
    case ARG_ZERO:
      if (is_true (arg))
	seq_flags |= SEQ_ZERO;
      else
	seq_flags &= ~SEQ_ZERO;
      break;

    case ARG_NOZERO:
      seq_flags &= ~SEQ_ZERO;
      break;
      
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
result test_string_equals_StringWithSameString() {
	int passed = 0;
	char* description = "string_equals(char*, char*) : StringWithSameString CASE";

	passed = is_true(string_equals("abc", "abc"));

	return (result){passed, description};
}
Example #25
0
int main(int argc, char* argv[])
{
	long count = 0;
	for ( int m = 2 ; m < mnum ; ++ m)
	{
		count += is_true(m);
	}
	std::cout<<count<<std::endl;
}
Example #26
0
char* nan_compress()
{
	char* tmp_set = (char*)malloc(40);
	strcpy(tmp_set, "[ ] Compress Backup (Slow but Saves Space)");
	if (is_true(tw_use_compression_val) == 1) {
		tmp_set[1] = 'x';
	}
	return tmp_set;
}
Example #27
0
//one arg: clauses
static cellpoint expand_clauses(void)
{
	if (is_true(is_null(args_ref(1)))){
		reg = a_false;
	}else {
		args_push(car(args_ref(1)));
		reg = is_cond_else_clause();
		if (is_true(reg)){
			reg = cdr(args_ref(1));
			if(is_true(is_null(reg))){
				//calls cond_actions
				args_push(car(args_ref(1)));
				reg = cond_actions();
				//calls sequence_2_exp
				args_push(reg);
				reg = sequence_2_exp();
			}else {
				printf("Error: ELSE clause isn't last clause in cond expression.\n");
				error_handler();
			}
		}else {
			//calls cond_predicate
			args_push(car(args_ref(1)));
			reg = cond_predicate();
			stack_push(&vars_stack, reg);
			//calls sequence_2_exp
			args_push(car(args_ref(1)));
			reg = cond_actions();
			args_push(reg);
			reg = sequence_2_exp();
			stack_push(&vars_stack, reg);
			//calls expand_clauses to expand the rest clauses
			args_push(cdr(args_ref(1)));
			reg = expand_clauses();
			//calls make_if
			args_push(reg);
			args_push(stack_pop(&vars_stack));
			args_push(stack_pop(&vars_stack));
			reg = make_if();
		}
	}
	args_pop(1);
	return reg;
}
Example #28
0
int all(c_array* array, int (*is_true)(byte*))
{
	size_t i;
	for (i=0; i<array->len; ++i) {
		if (!is_true(&array->data[i*array->elem_size])) {
			return 0;
		}
	}
	return 1;
}
Example #29
0
int any(c_array* array, int (*is_true)(const void*))
{
	size_t i;
	for (i=0; i<array->len; ++i) {
		if (is_true(&array->data[i*array->elem_size])) {
			return 1;
		}
	}
	return 0;
}
Example #30
0
	void TokenIf::gettext( std::wostream &stream, data_map &data )
	{
		if (is_true(m_expr, data))
		{
			for(size_t j = 0 ; j < m_children.size() ; ++j)
			{
				m_children[j]->gettext(stream, data) ;
			}
		}
	}