Esempio n. 1
0
def test_gencpppxd():
    ts.register_class('FCComp', 
                      cython_c_type='cpp_fccomp.FCComp', 
                      cython_cimport='cpp_fccomp', 
                      cython_cy_type='fccomp.FCComp', 
                      cython_cyimport='fccomp')
    ts.register_class('Toaster', 
                      cython_c_type='cpp_toaster.Toaster', 
                      cython_cimport='cpp_toaster', 
                      cython_cy_type='toaster.Toaster', 
                      cython_cyimport='toaster', 
                      cython_py_type='Toaster.Toaster',
                      )
    obs = cg.gencpppxd(toaster_desc).splitlines()
    exp = exp_cpppxd.splitlines()
    ts.deregister_class('FCComp')
    ts.deregister_class('Toaster')
    print "\n".join(obs)
    assert_equal(len(obs), len(exp))
    for o, e in zip(obs, exp):
        assert_equal(o, e)
Esempio n. 2
0
def genbindings(ns):
    """Generates bidnings using the command line setting specified in ns.
    """
    ns.cyclus = False  # FIXME cyclus bindings don't exist yet!

    # compute all descriptions first 
    env = {}
    for classname, fname, mkcython, mkcyclus in CLASSES:
        print("parsing " + classname)
        desc = env[classname] = describe_class(classname, 
                                               os.path.join('cpp', fname), 
                                               verbose=ns.verbose)
        if ns.verbose:
            pprint(env[classname])

        print("registering " + classname)
        pxd_base = desc['pxd_filename'].rsplit('.', 1)[0]         # eg, fccomp
        cpppxd_base = desc['cpppxd_filename'].rsplit('.', 1)[0]   # eg, cpp_fccomp
        class_c2py = ('{pytype}({var})', 
                      ('{proxy_name} = {pytype}()\n'
                       '(<{ctype} *> {proxy_name}._inst)[0] = {var}'),
                      ('if {cache_name} is None:\n'
                       '    {proxy_name} = {pytype}()\n'
                       '    {proxy_name}._free_inst = False\n'
                       '    {proxy_name}._inst = &{var}\n'
                       '    {cache_name} = {proxy_name}\n')
                     )
        class_py2c = ('{proxy_name} = <{cytype}> {var}', '(<{ctype} *> {proxy_name}._inst)[0]')
        class_cimport = ('bright', cpppxd_base) 
        ts.register_class(classname,                              # FCComp
            cython_c_type=cpppxd_base + '.' + classname,          # cpp_fccomp.FCComp
            cython_cimport=class_cimport,  
            cython_cy_type=pxd_base + '.' + classname,            # fccomp.FCComp   
            cython_py_type=pxd_base + '.' + classname,            # fccomp.FCComp   
            cython_template_class_name=classname.replace('_', '').capitalize(),
            cython_cyimport=pxd_base,                             # fccomp
            cython_pyimport=pxd_base,                             # fccomp
            cython_c2py=class_c2py,
            cython_py2c=class_py2c,
            )
    cache.dump()

    # now preregister types with the type system
    for prc in PREREGISTER_CLASSES:
        ts.register_class(**dict(zip(PREREGISTER_KEYS, prc)))

    # Now register specialization
    ts.register_specialization(('map', 'str', ('Material', '*'), 0), 
        cython_c_type='material._MapStrMaterial', 
        cython_cy_type='material._MapStrMaterial', 
        cython_py_type='material.MapStrMaterial',
        cython_cimport=(('pyne', 'material'),),
        cython_cyimport=(('pyne', 'material'),),
        cython_pyimport=(('pyne', 'material'),),
        )

    # next, make cython bindings
    for classname, fname, mkcython, mkcyclus in CLASSES:
        if not mkcython or not ns.cython:
            continue
        print("making cython bindings for " + classname)
        # generate first, then write out to ensure this is atomic per-class
        desc = env[classname]
        cpppxd = gencpppxd(desc)
        pxd = genpxd(desc)
        pyx = genpyx(desc, env)
        newoverwrite(cpppxd, os.path.join('bright', desc['cpppxd_filename']))
        newoverwrite(pxd, os.path.join('bright', desc['pxd_filename']))
        newoverwrite(pyx, os.path.join('bright', desc['pyx_filename']))

    # next, make cyclus bindings
    for classname, fname, mkcython, mkcyclus in CLASSES:
        if not mkcyclus or not ns.cyclus:
            continue
        print("making cyclus bindings for " + classname)
Esempio n. 3
0
def test_gencpppxd():
    obs = cg.gencpppxd(toaster_desc).splitlines()
    exp = exp_cpppxd.splitlines()
    assert_equal(len(obs), len(exp))
    for o, e in zip(obs, exp):
        assert_equal(o, e)