@@ -1208,25 +1208,26 @@ def make_jscall(sig):
12081208 return ret
12091209
12101210 @staticmethod
1211- def make_dynCall (sig ):
1212- # Optimize dynCall accesses in the case when not building with dynamic
1213- # linking enabled.
1214- if not Settings .MAIN_MODULE and not Settings .SIDE_MODULE :
1215- return 'dynCall_' + sig
1211+ def make_dynCall (sig , args ):
1212+ # wasm2c and asyncify are yet compatible with direct wasm table calls
1213+ if Settings .ASYNCIFY or Settings .WASM2C or not JS .is_legal_sig (sig ):
1214+ args = ',' .join (args )
1215+ if not Settings .MAIN_MODULE and not Settings .SIDE_MODULE :
1216+ # Optimize dynCall accesses in the case when not building with dynamic
1217+ # linking enabled.
1218+ return 'dynCall_%s(%s)' % (sig , join )
1219+ else :
1220+ return 'Module["dynCall_%s"](%s)' % (sig , args )
12161221 else :
1217- return 'Module["dynCall_' + sig + '"]'
1222+ return 'wasmTable.get(%s)(%s)' % (args [0 ], ',' .join (args [1 :]))
1223+
12181224
12191225 @staticmethod
12201226 def make_invoke (sig , named = True ):
12211227 legal_sig = JS .legalize_sig (sig ) # TODO: do this in extcall, jscall?
1222- args = ',' . join ( ['a' + str (i ) for i in range (1 , len (legal_sig ))])
1228+ args = [ 'index' ] + ['a' + str (i ) for i in range (1 , len (legal_sig ))]
12231229 ret = 'return ' if sig [0 ] != 'v' else ''
1224- args = 'index' + (',' if args else '' ) + args
1225- # wasm2c doesn't yet support for the new `tableCall`
1226- if Settings .WASM2C or not JS .is_legal_sig (sig ):
1227- body = '%s%s(%s);' % (ret , JS .make_dynCall (sig ), args )
1228- else :
1229- body = '%stableCall(%s);' % (ret , args )
1230+ body = '%s%s;' % (ret , JS .make_dynCall (sig , args ))
12301231 # C++ exceptions are numbers, and longjmp is a string 'longjmp'
12311232 if Settings .SUPPORT_LONGJMP :
12321233 rethrow = "if (e !== e+0 && e !== 'longjmp') throw e;"
@@ -1244,7 +1245,7 @@ def make_invoke(sig, named=True):
12441245 %s
12451246 _setThrew(1, 0);
12461247 }
1247- }''' % (name , args , body , rethrow )
1248+ }''' % (name , ',' . join ( args ) , body , rethrow )
12481249
12491250 return ret
12501251
0 commit comments