Skip to content

Commit a4f9f52

Browse files
author
hartsantler
committed
Golang backend: hello world.
1 parent 2a03ea8 commit a4f9f52

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

pythonjs/pythonjs_to_go.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def __init__(self, requirejs=False, insert_runtime=False):
1515
#self._classes = dict()
1616
#self._class_props = dict()
1717

18+
def visit_Print(self, node):
19+
r = [ 'fmt.Print(%s);' %self.visit(e) for e in node.values]
20+
return ''.join(r)
21+
22+
1823
def visit_Module(self, node):
1924
header = [
2025
'package main',
@@ -63,9 +68,20 @@ def _visit_call_helper_var(self, node):
6368

6469
out = []
6570
for v in args:
66-
out.append( self.indent() + 'var ' + v)
67-
68-
return '\n'.join(out)
71+
out.append( self.indent() + 'var ' + v + ' int')
72+
73+
#return '\n'.join(out)
74+
return ''
75+
76+
def visit_Assign(self, node):
77+
target = node.targets[0]
78+
if isinstance(target, ast.Tuple):
79+
raise NotImplementedError('target tuple assignment should have been transformed to flat assignment by python_to_pythonjs.py')
80+
else:
81+
target = self.visit(target)
82+
value = self.visit(node.value)
83+
code = 'var %s = %s;' % (target, value)
84+
return code
6985

7086

7187
def main(script):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""catch AttributeError"""
2+
3+
class A: pass
4+
5+
def main():
6+
a = A()
7+
b = False
8+
try:
9+
b = a.xxx
10+
except AttributeError:
11+
b = True
12+
13+
TestError( b == True )

regtests/go/print.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""hello world"""
2+
3+
def main():
4+
print "hi"

regtests/run.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ def run_old_pypy_test_on(filename):
142142
old_pypy_runnable = True
143143
old_pypy_exe = os.path.expanduser('~/pypy-1.9/bin/pypy')
144144

145-
webclgl = None
146-
if os.path.isfile( os.path.expanduser('~/webclgl/WebCLGL_2.0.Min.class.js') ):
147-
webclgl = open( os.path.expanduser('~/webclgl/WebCLGL_2.0.Min.class.js'), 'rb').read().decode('utf-8')
145+
webclgl = []
146+
if os.path.isdir( os.path.expanduser('~/webclgl') ):
147+
#webclgl.append( open( os.path.expanduser('~/webclgl/WebCLGL_2.0.Min.class.js'), 'rb').read().decode('utf-8') )
148+
webclgl.append( open( os.path.expanduser('~/webclgl/WebCLGLUtils.class.js'), 'rb').read().decode('utf-8') )
149+
webclgl.append( open( os.path.expanduser('~/webclgl/WebCLGLBuffer.class.js'), 'rb').read().decode('utf-8') )
150+
webclgl.append( open( os.path.expanduser('~/webclgl/WebCLGLKernel.class.js'), 'rb').read().decode('utf-8') )
151+
webclgl.append( open( os.path.expanduser('~/webclgl/WebCLGL.class.js'), 'rb').read().decode('utf-8') )
148152

149153
## rhino is not run by default because it simply freezes up on maximum callstack errors
150154
rhino_runnable = '--rhino' in sys.argv and runnable("rhino -e 'quit()'")
@@ -432,10 +436,11 @@ def patch_python(filename, dart=False, python='PYTHONJS', backend=None):
432436
# out.append( line )
433437
# code = '\n'.join( out )
434438
a = [
435-
_patch_header,
436439
'PYTHON="%s"'%python,
437440
'BACKEND="%s"'%backend,
438441
]
442+
if backend != 'GO':
443+
a.append(_patch_header)
439444

440445
if python != 'PYTHONJS':
441446
code = typedpython.transform_source( code, strip=True )
@@ -693,9 +698,10 @@ def run_js_nodewebkit(content):
693698

694699
html = ['<html>']
695700
if webclgl:
696-
html.append('<script>')
697-
html.append( webclgl )
698-
html.append('</script>')
701+
for data in webclgl:
702+
html.append('<script>')
703+
html.append( data )
704+
html.append('</script>')
699705

700706
html.append('<script>')
701707
html.extend( lines )
@@ -776,9 +782,12 @@ def run_pythonjs_go_test(dummy_filename):
776782

777783
def run_go(content):
778784
"""compile and run go program"""
779-
#builtins = read(os.path.join("../external/lua.js", "lua.js"))
780785
write("%s.go" % tmpname, content)
781-
return run_command("go build %s.go" % tmpname)
786+
errors = run_command("go build %s.go" % tmpname)
787+
if errors:
788+
return errors
789+
else:
790+
return run_command( tmpname)
782791

783792

784793
def run_html_test( filename, sum_errors ):

0 commit comments

Comments
 (0)