Skip to content

Commit 67c786d

Browse files
author
hartsantler
committed
test runner now inserts WebCLGL into runtime when running tests under nodewebkit.
1 parent 3351aa7 commit 67c786d

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

pythonjs/pythonjs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,19 @@ def _visit_function(self, node):
234234
lines.append('function %s( %s, __offset ) {' %(glsl_wrapper_name, ','.join(args)) )
235235
lines.append(' __offset = __offset || 0') ## note by default: 0 allows 0-1.0
236236
lines.append(' var __webclgl = new WebCLGL()')
237-
lines.append(' var __kernel = __webclgl.createKernel( __shader__ );')
237+
lines.append(' var __kernel = __webclgl.createKernel( "\\n".join(__shader__) );')
238+
lines.append(' var __return_length = 1')
238239

239-
lines.append(' var return_buffer = __webclgl.createBuffer(1, "FLOAT", __offset)') ## TODO length of return buffer
240240
for i,arg in enumerate(args):
241241
lines.append(' if (%s instanceof Array) {' %arg)
242+
lines.append(' __return_length = %s.length' %arg)
242243
lines.append(' var %s_buffer = __webclgl.createBuffer(%s.length, "FLOAT", __offset)' %(arg,arg))
243244
lines.append(' __webclgl.enqueueWriteBuffer(%s_buffer, %s)' %(arg, arg))
244245
lines.append(' __kernel.setKernelArg(%s, %s_buffer)' %(i, arg))
245246
lines.append(' } else { __kernel.setKernelArg(%s, %s) }' %(i, arg))
246247

248+
lines.append(' var return_buffer = __webclgl.createBuffer(__return_length, "FLOAT", __offset)')
249+
247250
lines.append(' __kernel.compile()')
248251
lines.append(' __webclgl.enqueueNDRangeKernel(__kernel, return_buffer)')
249252
lines.append(' return __webclgl.enqueueReadBuffer_Float( return_buffer )')
@@ -430,7 +433,7 @@ def inline_helper_return_id(self, return_id):
430433
return "var __returns__%s = null;"%return_id
431434

432435
def _visit_call_helper_numpy_array(self, node):
433-
raise NotImplementedError('TODO numpy.array')
436+
#raise NotImplementedError('TODO numpy.array')
434437
return self.visit(node.args[0]) ## TODO typed arrays
435438

436439
def _visit_call_helper_list(self, node):

regtests/run.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ def run_old_pypy_test_on(filename):
138138
pypy_runnable = True
139139
pypy_exe = 'pypy'
140140

141-
if os.path.isfile( os.path.expanduser('~/pypy-1.9/bin/pypy') ):
141+
if os.path.isfile( os.path.expanduser('~/pypy-1.9/bin/pypy') ) and '--old-pypy' in sys.argv:
142142
old_pypy_runnable = True
143143
old_pypy_exe = os.path.expanduser('~/pypy-1.9/bin/pypy')
144144

145-
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')
146148

147149
## rhino is not run by default because it simply freezes up on maximum callstack errors
148150
rhino_runnable = '--rhino' in sys.argv and runnable("rhino -e 'quit()'")
@@ -631,7 +633,19 @@ def run_js_nodewebkit(content):
631633
"main()",
632634
"__nw.App.quit()"
633635
]
634-
write("/tmp/test.html", '<html><script>%s</script></html>' %'\n'.join(lines))
636+
637+
html = ['<html>']
638+
if webclgl:
639+
html.append('<script>')
640+
html.append( webclgl )
641+
html.append('</script>')
642+
643+
html.append('<script>')
644+
html.extend( lines )
645+
html.append('</script>')
646+
647+
html.append('</html>')
648+
write("/tmp/test.html", '\n'.join(html))
635649

636650
#write("%s.js" % tmpname, '\n'.join(lines))
637651
#return run_command("node %s.js" % tmpname)

0 commit comments

Comments
 (0)