Beispiel #1
0
def patch_python(filename, dart=False, python='PYTHONJS', backend=None):
    """Rewrite the Python code"""
    code = patch_assert(filename)

    ## a main function can not be simply injected like this for dart,
    ## because dart has special rules about what can be created outside
    ## of the main function at the module level.
    #if dart:
    #    out = []
    #    main_inserted = False
    #    for line in code.splitlines():
    #        if line.startswith('TestError') or line.startswith('TestWarning'):
    #            if not main_inserted:
    #                out.append('def main():')
    #                main_inserted = True
    #            out.append( '\t'+line )
    #        else:
    #            out.append( line )
    #    code = '\n'.join( out )
    a = [
        _patch_header, 
        'PYTHON="%s"'%python, 
        'BACKEND="%s"'%backend, 
    ]

    if python != 'PYTHONJS':
        code = typedpython.transform_source( code, strip=True )
        a.append( _python_only_extra_header )

    a.append( code )

    if not dart and python != 'PYTHONJS':
        a.append( 'main()' )

    return '\n'.join( a )
Beispiel #2
0
def patch_python(filename, dart=False, python='PYTHONJS', backend=None):
    """Rewrite the Python code"""
    code = patch_assert(filename)

    ## a main function can not be simply injected like this for dart,
    ## because dart has special rules about what can be created outside
    ## of the main function at the module level.
    #if dart:
    #    out = []
    #    main_inserted = False
    #    for line in code.splitlines():
    #        if line.startswith('TestError') or line.startswith('TestWarning'):
    #            if not main_inserted:
    #                out.append('def main():')
    #                main_inserted = True
    #            out.append( '\t'+line )
    #        else:
    #            out.append( line )
    #    code = '\n'.join( out )
    a = [
        _patch_header,
        'PYTHON="%s"' % python,
        'BACKEND="%s"' % backend,
    ]

    if python != 'PYTHONJS':
        code = typedpython.transform_source(code, strip=True)
        a.append(_python_only_extra_header)

    a.append(code)

    if not dart and python != 'PYTHONJS':
        a.append('main()')

    return '\n'.join(a)
Beispiel #3
0
def main(script, insert_runtime=True):
	script = typedpython.transform_source(script)
	#raise SyntaxError(script)
	try:
		tree = ast.parse(script)
	except SyntaxError as err:
		sys.stderr.write(script)
		raise err

	g = VerilogGenerator( source=script )
	g.visit(tree) # first pass gathers classes
	return g.visit(tree)
Beispiel #4
0
def main(script, insert_runtime=True):
    script = typedpython.transform_source(script)
    #raise SyntaxError(script)
    try:
        tree = ast.parse(script)
    except SyntaxError as err:
        sys.stderr.write(script)
        raise err

    g = VerilogGenerator(source=script)
    g.visit(tree)  # first pass gathers classes
    return g.visit(tree)