Пример #1
0
void kp_obj_show(ktap_state_t *ks, const ktap_val_t *v)
{
	switch (itype(v)) {
	case KTAP_TNIL:
		kp_puts(ks, "nil");
		break;
	case KTAP_TTRUE:
		kp_puts(ks, "true");
		break;
	case KTAP_TFALSE:
		kp_puts(ks, "false");
		break;
	case KTAP_TNUM:
		kp_printf(ks, "%ld", nvalue(v));
		break;
	case KTAP_TLIGHTUD:
		kp_printf(ks, "lightud 0x%lx", (unsigned long)pvalue(v));
		break;
	case KTAP_TCFUNC:
		kp_printf(ks, "cfunction 0x%lx", (unsigned long)fvalue(v));
		break;
	case KTAP_TFUNC:
		kp_printf(ks, "function 0x%lx", (unsigned long)gcvalue(v));
		break;
	case KTAP_TSTR:
		kp_puts(ks, svalue(v));
		break;
	case KTAP_TTAB:
		kp_printf(ks, "table 0x%lx", (unsigned long)hvalue(v));
		break;
#ifdef CONFIG_KTAP_FFI
	case KTAP_TCDATA:
		kp_cdata_dump(ks, cdvalue(v));
		break;
#endif
	case KTAP_TEVENTSTR:
		/* check event context */
		if (!ks->current_event) {
			kp_error(ks,
			"cannot stringify event str in invalid context\n");
			return;
		}

		kp_transport_event_write(ks, ks->current_event);
		break;
	case KTAP_TKSTACK:
		kp_transport_print_kstack(ks, v->val.stack.depth,
					      v->val.stack.skip);
		break;
        default:
		kp_error(ks, "print unknown value type: %d\n", itype(v));
		break;
	}
}
Пример #2
0
/* Compare two objects without calling metamethods. */
int lj_obj_equal(cTValue *o1, cTValue *o2)
{
  if (itype(o1) == itype(o2)) {
    if (tvispri(o1))
      return 1;
    if (!tvisnum(o1))
      return gcrefeq(o1->gcr, o2->gcr);
  } else if (!tvisnumber(o1) || !tvisnumber(o2)) {
    return 0;
  }
  return numberVnum(o1) == numberVnum(o2);
}
Пример #3
0
const ktap_val_t *kp_tab_get(ktap_tab_t *t, const ktap_val_t *key)
{
	int i;

	switch (itype(key)) {
	case KTAP_TNIL:
		return niltv;
	case KTAP_TNUM:
		for (i = 0; i <= t->hmask; i++) {
			ktap_val_t *v = gkey(gnode(t, i));
			if (is_number(v) && nvalue(key) == nvalue(v))
				return gval(gnode(t, i));
		}
		break;
	case KTAP_TSTR:
		for (i = 0; i <= t->hmask; i++) {
			ktap_val_t *v = gkey(gnode(t, i));
			if (is_string(v) && (rawtsvalue(key) == rawtsvalue(v)))
				return gval(gnode(t, i));
		}
		break;
	default:
		for (i = 0; i <= t->hmask; i++) {
			if (kp_obj_equal(key, gkey(gnode(t, i))))
				return gval(gnode(t, i));
		}
		break;
	}

	return niltv;
}
Пример #4
0
void
luaL_setcdatagc(struct lua_State *L, int idx)
{
	/* Calculate absolute value in the stack. */
	if (idx < 0)
		idx = lua_gettop(L) + idx + 1;

	/* Code below is based on ffi_gc() from luajit/src/lib_ffi.c */

	/* Get cdata from the stack */
	assert(lua_type(L, idx) == LUA_TCDATA);
	GCcdata *cd = cdataV(L->base + idx - 1);

	/* Get finalizer from the stack */
	TValue *fin = lj_lib_checkany(L, lua_gettop(L));

#if !defined(NDEBUG)
	CTState *cts = ctype_cts(L);
	CType *ct = ctype_raw(cts, cd->ctypeid);
	(void) ct;
	assert(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||
	       ctype_isrefarray(ct->info));
#endif /* !defined(NDEBUG) */

	/* Set finalizer */
	lj_cdata_setfin(L, cd, gcval(fin), itype(fin));

	/* Pop finalizer */
	lua_pop(L, 1);
}
Пример #5
0
STCalEnum::InterpolationType CalibrationManager::stringToInterpolationEnum(const string &s)
{
  String itype(s);
  itype.upcase();
  const Char *c = itype.c_str();
  String::size_type len = itype.size();
  Regex nearest("^NEAREST(NEIGHBOR)?$");
  Regex linear("^LINEAR$");
  Regex spline("^(C(UBIC)?)?SPLINE$");
  Regex poly("^POLY(NOMIAL)?$");
  if (nearest.match(c, len) != String::npos) {
    return STCalEnum::NearestInterpolation;
  }
  else if (linear.match(c, len) != String::npos) {
    return STCalEnum::LinearInterpolation;
  }
  else if (spline.match(c, len) != String::npos) {
    return STCalEnum::CubicSplineInterpolation;
  }
  else if (poly.match(c, len) != String::npos) {
    return STCalEnum::PolynomialInterpolation;
  }

  os_.origin(LogOrigin("CalibrationManager","stringToInterpolationEnum",WHERE));
  os_ << LogIO::WARN << "Interpolation type " << s << " is not available. Use default interpolation method." << LogIO::POST;
  return STCalEnum::DefaultInterpolation;
}
Пример #6
0
void kp_obj_dump(ktap_state_t *ks, const ktap_val_t *v)
{
	switch (itype(v)) {
	case KTAP_TNIL:
		kp_puts(ks, "NIL");
		break;
	case KTAP_TTRUE:
		kp_printf(ks, "true");
		break;
	case KTAP_TFALSE:
		kp_printf(ks, "false");
		break;
	case KTAP_TNUM:
		kp_printf(ks, "NUM %ld", nvalue(v));
		break;
	case KTAP_TLIGHTUD:
		kp_printf(ks, "LIGHTUD 0x%lx", (unsigned long)pvalue(v));
		break;
	case KTAP_TFUNC:
		kp_printf(ks, "FUNCTION 0x%lx", (unsigned long)fvalue(v));
		break;
	case KTAP_TSTR:
		kp_printf(ks, "STR #%s", svalue(v));
		break;
	case KTAP_TTAB:
		kp_printf(ks, "TABLE 0x%lx", (unsigned long)hvalue(v));
		break;
        default:
		kp_printf(ks, "GCVALUE 0x%lx", (unsigned long)gcvalue(v));
		break;
	}
}
Пример #7
0
/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */
TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op)
{
  if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) {
    ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;
    MMS mm = (op & 2) ? MM_le : MM_lt;
    cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm);
    if (LJ_UNLIKELY(tvisnil(mo))) goto err;
    return mmcall(L, cont, mo, o1, o2);
  } else if (LJ_52 || itype(o1) == itype(o2)) {
    /* Never called with two numbers. */
    if (tvisstr(o1) && tvisstr(o2)) {
      int32_t res = lj_str_cmp(strV(o1), strV(o2));
      return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1));
    } else {
    trymt:
      while (1) {
	ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;
	MMS mm = (op & 2) ? MM_le : MM_lt;
	cTValue *mo = lj_meta_lookup(L, o1, mm);
#if LJ_52
	if (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm))))
#else
	cTValue *mo2 = lj_meta_lookup(L, o2, mm);
	if (tvisnil(mo) || !lj_obj_equal(mo, mo2))
#endif
	{
	  if (op & 2) {  /* MM_le not found: retry with MM_lt. */
	    cTValue *ot = o1; o1 = o2; o2 = ot;  /* Swap operands. */
	    op ^= 3;  /* Use LT and flip condition. */
	    continue;
	  }
	  goto err;
	}
	return mmcall(L, cont, mo, o1, o2);
      }
    }
  } else if (tvisbool(o1) && tvisbool(o2)) {
    goto trymt;
  } else {
  err:
    lj_err_comp(L, o1, o2);
    return NULL;
  }
}
Пример #8
0
static int kplib_stringof(ktap_state_t *ks)
{
	ktap_val_t *v = kp_arg(ks, 1);
	const ktap_str_t *ts = NULL;

	if (itype(v) == KTAP_TEVENTSTR) {
		ts = kp_event_stringify(ks);
	} else if (itype(v) == KTAP_TKIP) {
		char str[KSYM_SYMBOL_LEN];

		SPRINT_SYMBOL(str, nvalue(v));
		ts = kp_str_newz(ks, str);
	}

	if (unlikely(!ts))
		return -1;

	set_string(ks->top++, ts);
	return 1;
}
Пример #9
0
static int doisrch(BW *bw, int dir)
{				/* Create a struct isrch */
	struct isrch *isrch = (struct isrch *) joe_malloc(SIZEOF(struct isrch));

	izque(IREC, link, &isrch->irecs);
	isrch->pattern = vsncpy(NULL, 0, NULL, 0);
	isrch->dir = dir;
	isrch->quote = 0;
	isrch->prompt = vsncpy(NULL, 0, sz(joe_gettext(_("I-find: "))));
	isrch->ofst = sLen(isrch->prompt);
	return itype(bw->parent, -1, isrch, NULL);
}
Пример #10
0
int kp_obj_equal(const ktap_val_t *t1, const ktap_val_t *t2)
{
	switch (itype(t1)) {
	case KTAP_TNIL:
		return 1;
	case KTAP_TNUM:
		return nvalue(t1) == nvalue(t2);
	case KTAP_TTRUE:
	case KTAP_TFALSE:
		return itype(t1) == itype(t2);
	case KTAP_TLIGHTUD:
		return pvalue(t1) == pvalue(t2);
	case KTAP_TFUNC:
		return fvalue(t1) == fvalue(t2);
	case KTAP_TSTR:
		return rawtsvalue(t1) == rawtsvalue(t2);
	default:
		return gcvalue(t1) == gcvalue(t2);
	}

	return 0;
}
Пример #11
0
/*
 * ktap will not use lua's length operator for table,
 * also # is not for length operator any more in ktap.
 */
int kp_obj_len(ktap_state_t *ks, const ktap_val_t *v)
{
	switch(itype(v)) {
	case KTAP_TTAB:
		return kp_tab_len(ks, hvalue(v));
	case KTAP_TSTR:
		return rawtsvalue(v)->len;
	default:
		kp_printf(ks, "cannot get length of type %d\n", v->type);
		return -1;
	}
	return 0;
}
Пример #12
0
void op_itype2()
{
 /* Stack:

     |=============================|=============================|
     |            BEFORE           |           AFTER             |
     |=============================|=============================|
 top |  TOTAL() accumulator base   |  Result                     |
     |-----------------------------|-----------------------------|
     |  ADDR to object code        |                             |
     |=============================|=============================|
 */

 DESCRIPTOR * descr;

 descr = e_stack - 1;
 GetInt(descr);
 tbase = (short int)(descr->data.value);
 k_pop(1);

 itype();
}
Пример #13
0
int ursrch(W *w, int k)
{
	BW *bw;
	WIND_BW(bw, w);
	if (smode && lastisrch) {
		struct isrch *isrch = lastisrch;

		lastisrch = 0;
		return itype(bw->parent, 'R' - '@', isrch, NULL);
	} else {
		if (globalsrch) {
			rmsrch(globalsrch);
			globalsrch = 0;
		}
		if (lastisrch) {
			lastpat = vstrunc(lastpat, 0);
			lastpat = vsncpy(lastpat, 0, lastisrch->pattern, sLen(lastisrch->pattern));
			rmisrch(lastisrch);
			lastisrch = 0;
		}
		return doisrch(bw, 1);
	}
}
Пример #14
0
void op_itype()
{
 tbase = 0;
 itype();
}
Пример #15
0
/*=====================================
 * iistype -- Check type of interp node
 *===================================*/
BOOLEAN
iistype (PNODE node,
         INT type)
{
    return itype(node) == type;
}
Пример #16
0
void triangleMesher(const Vector3d& v1, const Vector3d& v2, const Vector3d& v3, const int nArcDiv, MV3& vertex)
{
	M3 xyz(3,27,4);
	IA1 ixstr(4), ixend(4), iystr(4), iyend(4), izstr(4), izend(4), nzsti(4), itype(4);
	itype(1)=itype(2)=itype(3)=itype(4)=1;

    const int ndiv = ((nArcDiv+1)/2)*2;
	ixstr(1)=iystr(1)=izstr(1)=1;
	ixend(1)=iyend(1)=ndiv+1;
	izend(1)=1;
	const int izn = 1;
    const int lengx=ixend(izn)-ixstr(izn);
    const int lengy=iyend(izn)-iystr(izn);
    const int lengz=izend(izn)-izstr(izn);
    ixstr(izn)=ixstr(izn);
    ixend(izn)=ixstr(izn)+lengx/2;
    iystr(izn)=iystr(izn);
    iyend(izn)=iystr(izn)+lengy/2;
    izstr(izn)=izstr(izn);
    izend(izn)=izend(izn);
	const int izn1=izn+1;
    ixstr(izn1)=ixstr(izn)+lengx/2;
    ixend(izn1)=ixstr(izn)+lengx;
    iystr(izn1)=iystr(izn);
    iyend(izn1)=iystr(izn)+lengy/2;
    izstr(izn1)=izstr(izn);
    izend(izn1)=izend(izn);
	const int izn2=izn+2;
    ixstr(izn2)=ixstr(izn)+lengx/2;
    ixend(izn2)=ixstr(izn)+lengx;
    iystr(izn2)=iystr(izn)+lengy/2;
    iyend(izn2)=iystr(izn)+lengy;
    izstr(izn2)=izstr(izn);
    izend(izn2)=izend(izn);

	const int nx=ixend(1)-ixstr(1)+1;
	const int nz=izend(1)-izstr(1)+1;
	nzsti(1)=1;
	nzsti(2)=nzsti(1)+nx;
	nzsti(3)=nzsti(2)+nx;
	vertex.reSize(nx*3, nx, nz);

	const Vector3d v123 = (v1+v2+v3)*(1.0/3);
	const Vector3d v12 = (v1+v2)*0.5;
	const Vector3d v23 = (v2+v3)*0.5;
	const Vector3d v13 = (v1+v3)*0.5;

	//zone 1
	Vector3dToFMatrix(v1, xyz, 1, izn);
	Vector3dToFMatrix(v12, xyz, 2, izn);
	Vector3dToFMatrix(v123, xyz, 3, izn);
	Vector3dToFMatrix(v13, xyz, 4, izn);
	Vector3dToFMatrix(v1, xyz, 5, izn);
	Vector3dToFMatrix(v12, xyz, 6, izn);
	Vector3dToFMatrix(v123, xyz, 7, izn);
	Vector3dToFMatrix(v13, xyz, 8, izn);
	
	//zone 2
	Vector3dToFMatrix(v2, xyz, 1, izn1);
	Vector3dToFMatrix(v23, xyz, 2, izn1);
	Vector3dToFMatrix(v123, xyz, 3, izn1);
	Vector3dToFMatrix(v12, xyz, 4, izn1);
	Vector3dToFMatrix(v2, xyz, 5, izn1);
	Vector3dToFMatrix(v23, xyz, 6, izn1);
	Vector3dToFMatrix(v123, xyz, 7, izn1);
	Vector3dToFMatrix(v12, xyz, 8, izn1);

	//zone 3
	Vector3dToFMatrix(v3, xyz, 1, izn2);
	Vector3dToFMatrix(v13, xyz, 2, izn2);
	Vector3dToFMatrix(v123, xyz, 3, izn2);
	Vector3dToFMatrix(v23, xyz, 4, izn2);
	Vector3dToFMatrix(v3, xyz, 5, izn2);
	Vector3dToFMatrix(v13, xyz, 6, izn2);
	Vector3dToFMatrix(v123, xyz, 7, izn2);
	Vector3dToFMatrix(v23, xyz, 8, izn2);

	for (int iz=izn; iz<=3; iz++){
		MV3 mat=vertex(nzsti(iz));
        mesh8zn(mat,ixstr,ixend,iystr,iyend,izstr,izend,xyz,iz,itype);
	}
}
// ============================================================================
// pxpByteCode
// ============================================================================
pxpByteCode::pxpByteCode( pkgDecompiler* decompiler )
:   Decompiler(decompiler)
,   CToken(NULL)
,   CTokenTree(NULL)
,   CTokenGroup(NULL)
,   CTokenGroupTree(NULL)
,   CTokenItem(NULL)
,   CTokenItemTree(NULL)
,   CTokenGroupCnd(NULL)
,   CTokenGroupCndTree(NULL)
,   unXmlParser()
{
    // temp tree nodes
    unXmlParseTree bytecode   ( wxT("bytecode") );
    unXmlParseTree bgroup     ( wxT("group") );
    unXmlParseTree gname      ( wxT("name") );
    unXmlParseTree gmemo      ( wxT("memo") );

    unXmlParseTree gtoken     ( wxT("token") );
    unXmlParseTree tcode      ( wxT("code") );
    unXmlParseTree tname      ( wxT("name") );
    unXmlParseTree tdesc      ( wxT("desc") );
    unXmlParseTree tdata      ( wxT("data") );

    unXmlParseTree titem      ( wxT("item") );
    unXmlParseTree itype      ( wxT("type") );
    unXmlParseTree iname      ( wxT("name") );

    unXmlParseTree ttext      ( wxT("text") );

    unXmlParseTree gcond      ( wxT("gcond") );
    unXmlParseTree cif        ( wxT("if") );
    unXmlParseTree ceq        ( wxT("eq") );
    unXmlParseTree cthen      ( wxT("then") );
    unXmlParseTree cleft      ( wxT("left") );
    unXmlParseTree cright     ( wxT("right") );

    unXmlParseTree ctstream   ( wxT("tstream") );
    unXmlParseTree cnum       ( wxT("num") );

    unXmlParseTree nfunc      ( wxT("nativefunctions") );
    unXmlParseTree ffirst     ( wxT("first") );
    unXmlParseTree fextended  ( wxT("extended") );

    // token group - pre
    bgroup.AddCommand( new_xpObjCreate<pkgTokenGroup>(txpParseTree) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroup, txpTokenGroupObject ) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupTree, txpParseTree ) );
        gname.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::SetName, txpNodeName(txpParseTree) ) );
        gname.AddPostCommand( new_xpFunc1( Decompiler, &pkgDecompiler::AddTokenGroup, txpTokenGroup ) );

    // token group - post
    bgroup.AddPostCommand( new_xpObjClear(txpParseTree) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroup ) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupTree ) );

    // gcond = pre
    gcond.AddCommand( new_xpObjCreate<pkgTokenCondition>(txpParseTree) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCnd, txpTokenGroupCndObject ) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCndTree, txpParseTree ) );

    // gcond = post
    gcond.AddPostCommand( new_xpObjClear(txpParseTree) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCnd ) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCndTree ) );

    // token - pre
    gtoken.AddCommand( new_xpObjCreate<dtToken>(txpParseTree) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetToken, txpTokenObject ) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenTree, txpParseTree ) );
        tcode.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenData, txpNodeData(txpParseTree) ) );
        tname.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenName, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetDesc, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::AddToken, txpToken ) );
        tdesc.AddCommand( new_xpFunc2( Decompiler, &pkgDecompiler::AddToken, txpToken, txpTokenGroupCnd ) );

    // token - post
    gtoken.AddPostCommand( new_xpFunc0( txpToken, &dtToken::DumpInfo ) );
    gtoken.AddPostCommand( new_xpObjClear(txpParseTree) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearToken ) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenTree ) );

    // titem - pre
    titem.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItemTree, txpParseTree ) );
        itype.AddCommand( new_xpObjFactory( txpTokenItemTree, &GDataTypeFactory, &pkgDataTypeFactory::Create, txpNodeName(txpParseTree) ) );
        itype.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItem, txpTokenItemTreeObject ) );
        iname.AddCommand( new_xpFunc1( txpTokenItem, &pkgDataType::SetDesc, txpNodeName(txpParseTree) ) );

    // titem - post
    titem.AddPostCommand( new_xpFunc1( txpToken, &dtToken::AddItem, txpTokenItem ) );
    titem.AddPostCommand( new_xpObjClear(txpParseTree) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItem ) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItemTree ) );
    
    ffirst.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdFirst, txpNodeData(txpParseTree) ) );
    fextended.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdExtended, txpNodeData(txpParseTree) ) );


    // construct tree starting from leaves
    // ie: node on right side *cannot* appear anywhere below on left side

    // token
    gtoken.AddChild( tcode, pl::one );
    gtoken.AddChild( tname, pl::one );
    gtoken.AddChild( tdesc, pl::one );
            titem.AddChild( itype, pl::one );
            titem.AddChild( iname, pl::one );
        tdata.AddChild( titem, pl::minone );
        tdata.AddChild( ttext, pl::maxone );
    gtoken.AddChild( tdata, pl::maxone );

    // if
            cleft.AddChild( ctstream, pl::maxone );
            cleft.AddChild( cnum, pl::maxone );
            cright.AddChild( ctstream, pl::maxone );
            cright.AddChild( cnum, pl::maxone );
        ceq.AddChild( cleft, pl::one );
        ceq.AddChild( cright, pl::one );
    cif.AddChild( ceq, pl::one );

    // then
    cthen.AddChild( gtoken, pl::any );

    // group
    bgroup.AddChild( gname, pl::one );
    bgroup.AddChild( gmemo, pl::any );
        gcond.AddChild( cif, pl::one );
        gcond.AddChild( cthen, pl::one );
    bgroup.AddChild( gcond, pl::maxone );
    bgroup.AddChild( gtoken, pl::any );

    // native functions
    nfunc.AddChild( fextended, pl::one );
    nfunc.AddChild( ffirst, pl::one );

    // bytecode
    bytecode.AddChild( bgroup, pl::minone );
    bytecode.AddChild( nfunc, pl::maxone );

    ParseTree = new unXmlParseTree( bytecode );
}
Пример #18
0
int main ( int, char ** )
try
{
    // Prepare the interpreter.a
    const py::Library library;

    // Build input stream class for 'wsgi.input' object.
    py::TypeBuilder itype("istream");
    itype.init(py::ctor<&exports::init>());
    itype.add(py::Method("read", py::vararg<&exports::read>()));
    itype.add(py::Method("readline", py::noargs<&exports::readline>()));
    itype.add(py::Method("readlines", py::vararg<&exports::readlines>()));
    itype.iterable(py::noargs<&exports::iter>(),
                  py::noargs<&exports::next>());
    itype.finish();

    // Have 'wsgi.input' object read from standard input stream.
    py::Object istream = itype();
    py::TypeBuilder::set_baton
        (istream, static_cast<std::istream*>(&std::cin));

    // Build output stream class for 'wsgi.errors' object.
    py::TypeBuilder otype("ostream");
    otype.init(py::ctor<&exports::init>());
    otype.add(py::Method("flush", py::noargs<&exports::flush>()));
    otype.add(py::Method("write", py::vararg<&exports::write>()));
    otype.add(py::Method("writelines", py::vararg<&exports::writelines>()));
    otype.finish();

    // Have 'wsgi.errors' object write to standard output stream.
    py::Object ostream = otype();
    py::TypeBuilder::set_baton
        (ostream, static_cast<std::ostream*>(&std::cout));

    // WSGI bootstrap code.
    wsgi::Runner execute("wsgi-bootstrap.py");
    // WSGI application handler.
    wsgi::Application application("sample", "wsgi-application.py");

    // Prepare application execution context.
    py::Map environment;
    // Required CGI-style variables.
    environment.put("REQUEST_METHOD", "GET");  // "GET", "POST", ...
#if 0
    environment.put("SCRIPT_NAME", "");     // Path to application script.
    environment.put("PATH_INFO", "");       // URL delegated to application.
    environment.put("QUERY_STRING", "");    // URL query string.
    environment.put("SERVER_NAME", "");     //
    environment.put("SERVER_PORT", "");     //
    environment.put("SERVER_PROTOCOL", ""); // "HTTP/1.x"
    // Optional CGI-style variables.
    environment.put("CONTENT_TYPE", "");
    environment.put("CONTENT_LENGTH", "");
#endif
#if 0
    // HTTP headers.
    environment.put("HTTP_HOST", "");
    //environment.put(...);
#endif
    // WSGI variables.
    py::Tuple version(2);
    version[0] = py::Int(1);
    version[1] = py::Int(0);
    environment.put("wsgi.version", version);
    environment.put("wsgi.url_scheme", "http");
    environment.put("wsgi.input", istream);
    environment.put("wsgi.errors", ostream);
    environment.put("wsgi.multithread", py::False());
    environment.put("wsgi.multiprocess", py::False());
    environment.put("wsgi.run_once", py::True());

    // Execute application and print HTTP response to "cout".
    wsgi::http_response(execute(application, environment),
                        wsgi::ostream_handler(std::cout));
}
catch ( const py::SystemError& error )
{
    std::cerr
        << "Error: '" << error.message() << "'."
        << std::endl;
    return (EXIT_FAILURE);
}
catch ( const py::Error& )
{
    std::cerr
        << "Error: 'some python error'."
        << std::endl;
    return (EXIT_FAILURE);
}
catch ( const std::exception& error )
{
    std::cerr
        << "Error: '" << error.what() << "'."
        << std::endl;
    return (EXIT_FAILURE);
}