object *expand_clauses(object *clauses) { object *first; object *rest; if (is_the_empty_list(clauses)) { return false; } else { first = car(clauses); rest = cdr(clauses); if (is_cond_else_clause(first)) { if (is_the_empty_list(rest)) { return sequence_to_exp(cond_actions(first)); } else { fprintf(stderr, "else clause isn't last cond->if"); exit(1); } } else { return make_if(cond_predicate(first), sequence_to_exp(cond_actions(first)), expand_clauses(rest)); } } }
static pSlipObject expand_clauses(pSlip gd, pSlipObject clauses) { pSlipObject first; pSlipObject rest; if (sIsObject_EmptyList(gd, clauses) == S_TRUE) { return gd->singleton_False; } else { first = car(clauses); rest = cdr(clauses); if (is_cond_else_clause(gd, first) == S_TRUE) { if (sIsObject_EmptyList(gd, rest) == S_TRUE) { return sequence_to_exp(gd, cond_actions(first)); } else { throw_error(gd, "else clause isn't last cond->if"); return gd->singleton_False; } } else { return make_if(gd, cond_predicate(first), sequence_to_exp(gd, cond_actions(first)), expand_clauses(gd, rest)); } } }
static int is_cond_else_clause(pSlip gd, pSlipObject clause) { if (cond_predicate(clause) == gd->singleton_Else) return S_TRUE; else return S_FALSE; }
static object *expand_clauses(object *clauses) { if (is_empty_list(clauses)) { return get_boolean(0); } else { object *first = car(clauses); object *rest = cdr(clauses); if (cond_predicate(first) == lookup_symbol("else")) { if (is_empty_list(rest)) { return sequence_to_exp(cond_actions(first)); } else { error("else clause must be last in cond expression"); } } else { return make_if(cond_predicate(first), sequence_to_exp(cond_actions(first)), expand_clauses(rest)); } } }
//one arg: clause static cellpoint is_cond_else_clause(void) { //calls cond_predicate args_push(args_ref(1)); reg = cond_predicate(); stack_push(&vars_stack, reg); //calls eq args_push(make_symbol("else")); args_push(stack_pop(&vars_stack)); reg = eq(); args_pop(1); return reg; }
void condition_test_waits(condition_test_data* data) { boost::mutex::scoped_lock lock(data->mutex); BOOST_CHECK(lock ? true : false); // Test wait. while (data->notified != 1) data->condition.wait(lock); BOOST_CHECK(lock ? true : false); BOOST_CHECK_EQUAL(data->notified, 1); data->awoken++; data->condition.notify_one(); // Test predicate wait. data->condition.wait(lock, cond_predicate(data->notified, 2)); BOOST_CHECK(lock ? true : false); BOOST_CHECK_EQUAL(data->notified, 2); data->awoken++; data->condition.notify_one(); // Test timed_wait. boost::xtime xt = delay(10); while (data->notified != 3) data->condition.timed_wait(lock, xt); BOOST_CHECK(lock ? true : false); BOOST_CHECK_EQUAL(data->notified, 3); data->awoken++; data->condition.notify_one(); // Test predicate timed_wait. xt = delay(10); cond_predicate pred(data->notified, 4); BOOST_CHECK(data->condition.timed_wait(lock, xt, pred)); BOOST_CHECK(lock ? true : false); BOOST_CHECK(pred()); BOOST_CHECK_EQUAL(data->notified, 4); data->awoken++; data->condition.notify_one(); // Test predicate timed_wait with relative timeout cond_predicate pred_rel(data->notified, 5); BOOST_CHECK(data->condition.timed_wait(lock, boost::posix_time::seconds(10), pred_rel)); BOOST_CHECK(lock ? true : false); BOOST_CHECK(pred_rel()); BOOST_CHECK_EQUAL(data->notified, 5); data->awoken++; data->condition.notify_one(); }
//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; }
object *expand_clauses(object *clauses) { object *first; object *rest; if (is_empty(clauses)) return false; first = car(clauses); rest = cdr(clauses); if (!is_cond_else_clause(first)) return make_if(cond_predicate(first), sequence_to_exp(cond_actions(first)), expand_clauses(rest)); if (is_empty(rest)) return sequence_to_exp(cond_actions(first)); fprintf(stderr, "else clause isn't last cond->if"); exit(EXIT_FAILURE); }
void condition_test_waits(condition_test_data<Condition, Mutex>* data) { boost::interprocess::scoped_lock<Mutex> lock(data->mutex); BOOST_INTERPROCESS_CHECK(lock ? true : false); // Test wait. while (data->notified != 1) data->condition.wait(lock); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 1); data->awoken++; data->condition.notify_one(); // Test predicate wait. data->condition.wait(lock, cond_predicate(data->notified, 2)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 2); data->awoken++; data->condition.notify_one(); // Test timed_wait. while (data->notified != 3) data->condition.timed_wait(lock, ptime_delay(5)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 3); data->awoken++; data->condition.notify_one(); // Test predicate timed_wait. cond_predicate pred(data->notified, 4); bool ret = data->condition.timed_wait(lock, ptime_delay(5), pred); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(pred()); BOOST_INTERPROCESS_CHECK(data->notified == 4); data->awoken++; data->condition.notify_one(); }
char is_cond_else_clause(object *clause) { return cond_predicate(clause) == else_symbol(); }