Skip to content

Commit 95fae01

Browse files
author
hartsantler
committed
dart backend: fixed passing type info and started on prototype for SIMD support.
1 parent 115bb24 commit 95fae01

6 files changed

Lines changed: 17 additions & 3 deletions

File tree

pythonjs/ast_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def retrieve_vars(body):
4646
local_vars.add( '%s=%s' %(user_typedef, u.id) )
4747
user_typedef = None
4848
else:
49+
#add = True ## TODO this should work?!
50+
#for x in local_vars:
51+
# if u.id == x or ('=' in x and x.split('=')[-1] == u.id):
52+
# add = False
53+
# break
54+
#if add:
4955
local_vars.add( u.id )
5056

5157
elif isinstance(u, ast.Tuple):

pythonjs/python_to_pythonjs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,7 @@ def visit_FunctionDef(self, node):
24952495
## the dart backend can use this extra type information.
24962496
vars = []
24972497
local_typedefs = []
2498+
local_typedef_names = set()
24982499
if not self._with_coffee:
24992500
local_vars, global_vars = retrieve_vars(node.body)
25002501
local_vars = local_vars-global_vars
@@ -2506,15 +2507,18 @@ def visit_FunctionDef(self, node):
25062507
usertype = None
25072508
if '=' in v:
25082509
t,n = v.split('=') ## unpack type and name
2510+
if self._with_dart and t in typedpython.simd_types:
2511+
t = t[0].upper() + t[1:]
25092512
v = '%s=%s' %(n,t) ## reverse
2513+
local_typedef_names.add( n )
25102514
if t == 'long':
25112515
writer.write('''inline("if (__NODEJS__==true) var long = require('long')")''') ## this is ugly
25122516

25132517
if n in args:
25142518
args_typedefs.append( v )
25152519
else:
25162520
local_typedefs.append( v )
2517-
elif v in args: pass
2521+
elif v in args or v in local_typedef_names: pass
25182522
else: vars.append( v )
25192523

25202524
if args_typedefs:

pythonjs/pythonjs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _visit_call_helper_var(self, node):
403403
if args:
404404
out.append( 'var ' + ','.join(args) )
405405
if node.keywords:
406-
out.append( 'var ' + ','.join([key.value.id for key in node.keywords]) )
406+
out.append( 'var ' + ','.join([key.arg for key in node.keywords]) )
407407

408408
return ';'.join(out)
409409

pythonjs/pythonjs_to_dart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def _visit_call_helper_var(self, node):
471471
out.append( 'var ' + ','.join(args) )
472472
if node.keywords:
473473
for key in node.keywords:
474-
out.append( '%s %s' %(key.arg, key.value.id) )
474+
out.append( '%s %s' %(key.value.id, key.arg) )
475475

476476
return ';'.join(out)
477477

pythonjs/runtime/dart_builtins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License: "New BSD"
44

55
dart_import('dart:collection')
6+
dart_import('dart:typed_data')
67
dart_import('dart:math', 'Math')
78

89
#@dart.extends

pythonjs/typedpython.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
whitespace = [' ', '\t']
22
native_number_types = ['int', 'float', 'double'] ## float and double are the same
3+
simd_types = ['float32x4', 'int32x4']
4+
vector_types = simd_types ## TODO support non-simd vec types like vec3f?
35
number_types = ['long'] ## requires https://github.com/dcodeIO/Long.js
46
number_types.extend( native_number_types )
57

68
types = ['str', 'list', 'dict']
79
types.extend( number_types)
10+
types.extend( vector_types )
811

912

1013
def transform_source( source, strip=False ):

0 commit comments

Comments
 (0)