Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9f143f

Browse files
author
hartsantler
committed
go backend: multidimensional array [][]
1 parent 3b12597 commit d9f143f

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

pythonjs/python_to_pythonjs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ def visit_Import(self, node):
424424
tornado = ['tornado', 'tornado.web', 'tornado.ioloop']
425425

426426
for alias in node.names:
427-
if alias.name in tornado:
427+
if self._with_go:
428+
writer.write('import %s' %alias.name)
429+
elif alias.name in tornado:
428430
pass ## pythonjs/fakelibs/tornado.py
429431
elif alias.name == 'tempfile':
430432
pass ## pythonjs/fakelibs/tempfile.py

pythonjs/pythonjs_to_go.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ def visit_Expr(self, node):
150150
return self.visit(node.value)
151151

152152
def visit_Import(self, node):
153-
r = [alias.name for alias in node.names]
153+
r = [alias.name.replace('__SLASH__', '/') for alias in node.names]
154154
if r:
155-
return 'import "%s"' %';'.join(r)
155+
return 'import("%s")' %';'.join(r)
156156
else:
157157
return ''
158158

pythonjs/typedpython.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def transform_source( source, strip=False ):
4444
if nextchar.strip(): break
4545
j += 1
4646

47-
if a and char==']' and j==i+1 and nextchar!=None and nextchar in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
47+
if a and char==']' and j==i+1 and nextchar!=None and nextchar in '[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
4848
assert '[' in a
4949
gotype = []
5050
b = a.pop()
@@ -54,7 +54,10 @@ def transform_source( source, strip=False ):
5454
gotype.reverse()
5555
gotype = ''.join(gotype)
5656
if not gotype:
57-
a.append('__go__array__(')
57+
if nextchar=='[':
58+
a.append('__go__array__<<')
59+
else:
60+
a.append('__go__array__(')
5861
elif gotype.isdigit():
5962
a.append('__go__arrayfixed__(%s,' %gotype)
6063
else:
@@ -69,6 +72,10 @@ def transform_source( source, strip=False ):
6972
elif hit_go_typedef and char=='{':
7073
a.append(')<<{')
7174
hit_go_typedef = False
75+
elif hit_go_typedef and char==',':
76+
a.append('),')
77+
hit_go_typedef = False
78+
7279

7380
elif a and char in __whitespace:
7481
b = ''.join(a)
@@ -153,8 +160,15 @@ def transform_source( source, strip=False ):
153160
break
154161
indent = ''.join(indent)
155162
output.append( indent + '@returns(%s)' %rtype)
156-
elif c.startswith('import ') and '-' in c:
157-
c = c.replace('-', '__DASH__')
163+
164+
if c.startswith('import '):
165+
if '-' in c:
166+
c = c.replace('-', '__DASH__')
167+
if '/' in c:
168+
c = c.replace('/', '__SLASH__')
169+
if '"' in c:
170+
c = c.replace('"', '')
171+
158172

159173
if ' new ' in c:
160174
c = c.replace(' new ', ' __new__>>')
@@ -430,6 +444,8 @@ def f(*args:int, **kwargs:int) ->int:
430444
431445
a = []int(x for x in range(3))
432446
447+
y = go.make([]float64, 1000)
448+
433449
'''
434450

435451
if __name__ == '__main__':

0 commit comments

Comments
 (0)