static void pop_process() { ProcessStack& process_stack = get_singletonA()->process_stack; g_assert(process_stack.size()); Glib::RefPtr<ProcessStackEntry> top = *process_stack.rbegin(); g_assert(top); get_singletonA()->what_doing.clear(); process_stack.pop_back(); if(top->_block_changes) { if(process_stack.size()) { Glib::RefPtr<ProcessStackEntry> newtop = *process_stack.rbegin(); g_assert(newtop); if(!newtop->_block_changes) get_singletonA()->_block_changes(true); }else get_singletonA()->_block_changes(true); } signal_something_changed().emit(); }
ExecStatus doprop_val(Space& home, int n, Info* x, Offset& ox, Info* y, Offset& oy, int& n_na, ProcessStack& xa, ProcessStack& ya) { do { int i = xa.pop(); int j = ox(x[i].view).val(); // Assign the y variable to i (or test if already assigned!) { ModEvent me = oy(y[j].view).eq(home,i); if (me_failed(me)) { return ES_FAILED; } // Record that y[j] has been assigned and must be propagated if (me_modified(me)) ya.push(j); } // Prune the value j from all x variables for (int k=i; k--; ) { ModEvent me = ox(x[k].view).nq(home,j); if (me_failed(me)) { return ES_FAILED; } if (me_modified(me)) { if (me == ME_INT_VAL) { // Record that x[k] has been assigned and must be propagated xa.push(k); } else { // One value has been removed and this removal does not need // to be propagated again: after all y[j] = i, so it holds // that y[j] != k. x[k].removed(j); } } } // The same for the other views for (int k=i+1; k<n; k++) { ModEvent me = ox(x[k].view).nq(home,j); if (me_failed(me)) { return ES_FAILED; } if (me_modified(me)) { if (me == ME_INT_VAL) { // Record that x[k] has been assigned and must be propagated xa.push(k); } else { // One value has been removed and this removal does not need // to be propagated again: after all y[j] = i, so it holds // that y[j] != k. x[k].removed(j); } } } x[i].assigned(); n_na--; } while (!xa.empty()); return ES_OK; }
static void abort_process() { ProcessStack& process_stack = get_singletonA()->process_stack; if(process_stack.size()) { Glib::RefPtr<ProcessStackEntry> top = *process_stack.rbegin(); top->_is_aborted = true; } }
/* by appending two strings together precondition: stack.top(2) = left string stack.top(1) = right string postcondition: stack.top(1) = concatenated strings */ void HlString::append(Heap& hp, ProcessStack& stack) { HlString* psl = expect_type<HlString>(stack.top(2), "'string-join expects two strings, first argument is not a string" ); HlString* psr = expect_type<HlString>(stack.top(1), "'string-join expects two strings, first argument is not a string" ); HlString* pa = hp.create<HlString>(); append_string_impl(pa->pimpl, psl->pimpl, psr->pimpl); stack.pop(1); stack.top(1) = Object::to_ref<Generic*>(pa); }
static bool is_curr_process_aborted() { if(get_singletonA()->_abort_all) return true; ProcessStack& process_stack = get_singletonA()->process_stack; if(process_stack.size()) { Glib::RefPtr<ProcessStackEntry> top = *process_stack.rbegin(); return top->_is_aborted; } return false; }
forceinline ExecStatus prop_val(Space& home, int n, Info* x, Offset& ox, Info* y, Offset& oy, int& n_na, ProcessStack& xa, ProcessStack& ya) { if (xa.empty()) return ES_OK; return doprop_val<View,Offset,Info>(home,n,x,ox,y,oy,n_na,xa,ya); }
/* On-stack creation */ void HlString::stack_create(Heap& hp, ProcessStack& stack, size_t N) { HlStringBuilderCore sb; /*iterate over the stack top, frop top(N) to top(1)*/ for(size_t i = 0; i < N; ++i) { Object::ref cc = stack.top(N - i); if(!is_a<UnicodeChar>(cc)) { throw_HlError( "attempt to create string from non-character" ); } sb.add(as_a<UnicodeChar>(cc)); } /*pop*/ stack.pop(N); HlString* sp = hp.create<HlString>(); sb.inner(sp->pimpl); stack.push(Object::to_ref<Generic*>(sp)); }
static void fill_state(State& state) { ProcessStack& process_stack = get_singletonA()->process_stack; state.reset(); if(process_stack.size()) { Glib::RefPtr<ProcessStackEntry> top = *process_stack.rbegin(); g_assert(top); if(get_singletonA()->what_doing.empty()) { state.state = top->_what_doing; }else { if(get_singletonA()->what_doing.empty()) state.state = top->_what_doing; else state.state = Glib::ustring::compose("%1 [%2]", top->_what_doing, get_singletonA()->what_doing); } state.is_aborted = top->_is_aborted; if(top->_n_total_steps) { state.has_progress = true; state.p = gdouble(top->curr_step()) / gdouble(top->_n_total_steps); } state.abortable = top->_abortable; }else if(get_singletonA()->what_doing.empty()) { state.state = "Ready"; }else { state.state = get_singletonA()->what_doing; } }
/* Construction of a HlString from a std::string */ void HlString::from_cpp_string( Heap& hp, ProcessStack& stack, std::string const& s) { /*create a new buffer to contain the string*/ boost::shared_array<BYTE> buffer( new BYTE[s.size()] ); BYTE* start = &buffer[0]; BYTE* dest = start; /*get the string contents*/ BYTE const* src = (BYTE const*) &*s.begin(); /*keep track of the length of the string in unichars*/ size_t len = 0; bool nonascii = false; /*copy into buffer*/ while(src != (BYTE const*) &*s.end()) { BYTE const* p = src; utf8_adv_check(p, nonascii); std::copy(src, p, dest); size_t diff = p - src; dest += diff; src = p; ++len; } string_ptr rv; /*were we ASCII or UTF-8?*/ if(nonascii) { rv.reset( new Utf8Impl(buffer, start, dest, len) ); } else { rv.reset( new AsciiImpl(buffer, start, len) ); } /*now allocate on the given Heap*/ HlString* sp = hp.create<HlString>(); sp->pimpl = rv; stack.push(Object::to_ref<Generic*>(sp)); }