Skip to content

Commit c7a7744

Browse files
author
hartsantler
committed
new backend Gopherjs
1 parent 628d2a8 commit c7a7744

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

pythonjs/translator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ def main(script, module_path=None):
2727
if '--go' in sys.argv:
2828
a = python_to_pythonjs(script, go=True, module_path=module_path)
2929
code = pythonjs_to_go( a )
30+
elif '--gopherjs' in sys.argv:
31+
a = python_to_pythonjs(script, go=True, module_path=module_path)
32+
code = pythonjs_to_go( a )
33+
34+
exe = os.path.expanduser('~/go/bin/gopherjs')
35+
if not os.path.isfile(exe):
36+
raise RuntimeError('gopherjs not installed to ~/go/bin/gopherjs')
37+
import subprocess
38+
path = '/tmp/gopherjs-input.go'
39+
open(path, 'wb').write(code)
40+
subprocess.check_call([exe, 'build', path], cwd='/tmp')
41+
code = open('/tmp/gopherjs-input.js', 'rb').read()
42+
3043
elif '--dart' in sys.argv:
3144
a = python_to_pythonjs(script, dart=True, module_path=module_path)
3245
code = pythonjs_to_dart( a )

regtests/run.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def run_old_pypy_test_on(filename):
194194
luajs_runnable = os.path.isfile( lua2js ) and '--lua2js' in sys.argv
195195

196196
go_runnable = runnable( 'go version')
197+
gopherjs_runnable = runnable( 'gopherjs')
197198

198199
assert rhino_runnable or node_runnable
199200

@@ -474,7 +475,7 @@ def run_python3_test_on(filename):
474475

475476

476477

477-
def translate_js(filename, javascript=False, dart=False, coffee=False, lua=False, luajs=False, go=False, multioutput=False, requirejs=True):
478+
def translate_js(filename, javascript=False, dart=False, coffee=False, lua=False, luajs=False, go=False, gopherjs=False, multioutput=False, requirejs=True):
478479
global tmpname
479480
tmpname = os.path.join(
480481
tempfile.gettempdir(),
@@ -506,7 +507,7 @@ def translate_js(filename, javascript=False, dart=False, coffee=False, lua=False
506507
]
507508
content = '\n'.join( source )
508509

509-
elif go:
510+
elif go or gopherjs:
510511
content = patch_python(filename, backend='GO')
511512

512513
else:
@@ -535,6 +536,8 @@ def translate_js(filename, javascript=False, dart=False, coffee=False, lua=False
535536
cmd.append( '--luajs')
536537
elif go:
537538
cmd.append( '--go' )
539+
elif gopherjs:
540+
cmd.append( '--gopherjs' )
538541

539542
if not requirejs:
540543
cmd.append( '--no-wrapper' )
@@ -799,6 +802,15 @@ def run_go(content):
799802
return run_command( '/tmp/regtest-go' )
800803

801804

805+
def run_pythonjs_gopherjs_test(dummy_filename):
806+
"""PythonJS (Gopherjs)"""
807+
return run_if_no_error(run_gopherjs_node)
808+
809+
def run_gopherjs_node(content):
810+
"""Run Gopherjs using Node"""
811+
write("%s.js" % tmpname, content)
812+
return run_command("node %s.js" % tmpname)
813+
802814
def run_html_test( filename, sum_errors ):
803815
lines = open(filename, 'rb').read().decode('utf-8').splitlines()
804816
filename = os.path.split(filename)[-1]
@@ -967,6 +979,9 @@ def display(function):
967979
js = translate_js(filename, go=True)
968980
display(run_pythonjs_go_test)
969981

982+
if gopherjs_runnable:
983+
js = translate_js(filename, gopherjs=True)
984+
display(run_pythonjs_gopherjs_test)
970985

971986
print()
972987
return sum_errors

0 commit comments

Comments
 (0)