1 Control Synopsis
share/lib/std/control/__init__.flx
include "std/control/svc";
include "std/control/control";
include "std/control/unique";
include "std/control/iterator";
include "std/control/schannels";
include "std/control/fibres";
include "std/control/spipes";
include "std/control/chips";
2 Misc Control Flow
share/lib/std/control/control.flx
open class Control
{
open C_hack;
fun fix[D,C] (f:(D->C)->D->C) (x:D) : C => f (fix f) x;
typefun tfix<K> (f: K ->K):K => f x as x:K;
proc _swap[t] (a:&t,b:&t) =
{
var tmp = *a;
a <- *b;
b <- tmp;
}
proc swap[t] (a:&t,b:&t) => _swap(a,b);
proc forever (bdy:unit->void)
{
rpeat:>
bdy();
goto rpeat;
dummy:>
}
publish "do nothing [the name pass comes from Python]"
proc pass(){}
proc for_each
(init:unit->void)
(cond:unit->bool)
(incr:unit->void)
(bdy:unit->void)
{
init();
rpeat:>
if not (cond()) goto finish;
bdy();
incr();
goto rpeat;
finish:>
}
proc branch-and-link (target:&LABEL, save:&LABEL)
{
save <- next;
goto *target;
next:>
}
gen throw[ret,exn] : exn -> ret = "(throw $1,*(?1*)0)";
proc raise[exn] : exn = "(throw $1);";
proc proc_fail:string = 'throw ::std::runtime_error($1);'
requires Cxx_headers::stdexcept;
fun fun_fail[ret]:string -> ret = '(throw ::std::runtime_error($1),*(?1*)0)'
requires Cxx_headers::stdexcept;
_gc_pointer type cont = "::flx::rtl::con_t*";
fun entry_label : cont -> LABEL = "::flx::rtl::jump_address_t($1)";
fun current_position : cont -> LABEL = "::flx::rtl::jump_address_t($1,$1->pc)";
fun entry_label[T] (p:T->0):LABEL => entry_label (C_hack::cast[cont] p);
fun current_continuation: unit -> cont = "this";
_gc_pointer type fthread = "::flx::rtl::fthread_t*";
fun throw_continuation(x: unit->void) : any { _throw (C_hack::cast[cont] x); }
private proc _throw: cont = "throw $1;";
}