@@ -20,228 +20,6 @@ mergeInto(LibraryManager.library, {
20
20
} ,
21
21
22
22
#if ASYNCIFY
23
- #if ! WASM_BACKEND
24
- /*
25
- * The layout of normal and async stack frames
26
- *
27
- * --------------------- <-- saved sp for the current function
28
- * <last normal stack frame>
29
- * ---------------------
30
- * pointer to the previous frame <-- __async_cur_frame
31
- * saved sp
32
- * callback function <-- ctx, returned by alloc/reallloc, used by the program
33
- * saved local variable1
34
- * saved local variable2
35
- * ...
36
- * --------------------- <-- STACKTOP
37
- *
38
- */
39
- __async : 0 , // whether a truly async function has been called
40
- __async_unwind : 1 , // whether to unwind the async stack frame
41
- __async_retval : '{{{ makeStaticAlloc(2) }}}' , // store the return value for async functions
42
- __async_cur_frame : 0 , // address to the current frame, which stores previous frame, stack pointer and async context
43
-
44
- // __async_retval is not actually required in emscripten_async_resume
45
- // but we want it included when ASYNCIFY is enabled
46
- emscripten_async_resume__deps : [ '__async' , '__async_unwind' , '__async_retval' , '__async_cur_frame' ] ,
47
- emscripten_async_resume__sig : 'v' ,
48
- emscripten_async_resume__asm : true ,
49
- emscripten_async_resume : function ( ) {
50
- var callback = 0 ;
51
- ___async = 0 ;
52
- ___async_unwind = 1 ;
53
- while ( 1 ) {
54
- if ( ! ___async_cur_frame ) return ;
55
- callback = { { { makeGetValueAsm ( '___async_cur_frame' , 8 , 'i32' ) } } } ;
56
- // the signature of callback is always vi
57
- // the only argument is ctx
58
- { { { makeDynCall ( 'vi' ) } } } ( callback | 0 , ( ___async_cur_frame + 8 ) | 0 ) ;
59
- if ( ___async ) return ; // that was an async call
60
- if ( ! ___async_unwind ) {
61
- // keep the async stack
62
- ___async_unwind = 1 ;
63
- continue ;
64
- }
65
- // unwind normal stack frame
66
- stackRestore ( { { { makeGetValueAsm ( '___async_cur_frame' , 4 , 'i32' ) } } } ) ;
67
- // pop the last async stack frame
68
- ___async_cur_frame = { { { makeGetValueAsm ( '___async_cur_frame' , 0 , 'i32' ) } } } ;
69
- }
70
- } ,
71
-
72
- emscripten_sleep__deps: [ 'emscripten_async_resume' , '$Browser' ] ,
73
- emscripten_sleep : function ( ms ) {
74
- Module [ 'setAsync' ] ( ) ; // tell the scheduler that we have a callback on hold
75
- Browser . safeSetTimeout ( _emscripten_async_resume , ms ) ;
76
- } ,
77
-
78
- emscripten_alloc_async_context__deps : [ '__async_cur_frame' ] ,
79
- emscripten_alloc_async_context__sig : 'iii' ,
80
- emscripten_alloc_async_context__asm : true ,
81
- emscripten_alloc_async_context : function ( len , sp ) {
82
- len = len | 0 ;
83
- sp = sp | 0 ;
84
- // len is the size of ctx
85
- // we also need to store prev_frame, stack pointer before ctx
86
- var new_frame = 0 ; new_frame = stackAlloc ( ( len + 8 ) | 0 ) | 0 ;
87
- // save sp
88
- { { { makeSetValueAsm ( 'new_frame' , 4 , 'sp' , 'i32' ) } } } ;
89
- // link the frame with previous one
90
- { { { makeSetValueAsm ( 'new_frame' , 0 , '___async_cur_frame' , 'i32' ) } } } ;
91
- ___async_cur_frame = new_frame ;
92
- return ( ___async_cur_frame + 8 ) | 0 ;
93
- } ,
94
-
95
- emscripten_realloc_async_context__deps : [ '__async_cur_frame' ] ,
96
- emscripten_realloc_async_context__sig : 'ii' ,
97
- emscripten_realloc_async_context__asm : true ,
98
- emscripten_realloc_async_context : function ( len ) {
99
- len = len | 0 ;
100
- // assuming that we have on the stacktop
101
- stackRestore ( ___async_cur_frame | 0 ) ;
102
- return ( ( stackAlloc ( ( len + 8 ) | 0 ) | 0 ) + 8 ) | 0 ;
103
- } ,
104
-
105
- emscripten_free_async_context__deps : [ '__async_cur_frame' ] ,
106
- emscripten_free_async_context__sig : 'vi' ,
107
- emscripten_free_async_context__asm : true ,
108
- emscripten_free_async_context : function ( ctx ) {
109
- // this function is called when a possibly async function turned out to be sync
110
- // just undo a recent emscripten_alloc_async_context
111
- ctx = ctx | 0 ;
112
- #if ASSERTIONS
113
- if ( ( ( ( ___async_cur_frame + 8 ) | 0 ) != ( ctx | 0 ) ) | 0 ) abort ( ) ;
114
- #endif
115
- stackRestore ( ___async_cur_frame | 0 ) ;
116
- ___async_cur_frame = { { { makeGetValueAsm ( '___async_cur_frame' , 0 , 'i32' ) } } } ;
117
- } ,
118
-
119
- emscripten_check_async: true ,
120
- emscripten_do_not_unwind : true ,
121
- emscripten_do_not_unwind_async : true ,
122
-
123
- emscripten_get_async_return_value_addr__deps : [ '__async_retval' ] ,
124
- emscripten_get_async_return_value_addr : true ,
125
-
126
- /*
127
- * Layout of an ASYNCIFY coroutine structure
128
- *
129
- * 0 callee's async ctx
130
- * 4 callee's STACKTOP
131
- * 8 callee's STACK_MAX
132
- * 12 my async ctx
133
- * 16 my STACKTOP
134
- * 20 my stack size
135
- * 24 coroutine function
136
- * 28 coroutine arg
137
- * 32 my stack:
138
- * ...
139
- */
140
- emscripten_coroutine_create__sig : 'iiii' ,
141
- emscripten_coroutine_create__asm : true ,
142
- emscripten_coroutine_create__deps : [ 'malloc' , 'emscripten_alloc_async_context' ] ,
143
- emscripten_coroutine_create : function ( f , arg , stack_size ) {
144
- f = f | 0 ;
145
- arg = arg | 0 ;
146
- stack_size = stack_size | 0 ;
147
- var coroutine = 0 ;
148
-
149
- if ( ( stack_size | 0 ) <= 0 ) stack_size = 4096 ;
150
-
151
- coroutine = _malloc ( stack_size + 32 | 0 ) | 0 ;
152
- { { { makeSetValueAsm ( 'coroutine' , 12 , 0 , 'i32' ) } } } ;
153
- { { { makeSetValueAsm ( 'coroutine' , 16 , '(coroutine+32)' , 'i32' ) } } } ;
154
- { { { makeSetValueAsm ( 'coroutine' , 20 , 'stack_size' , 'i32' ) } } } ;
155
- { { { makeSetValueAsm ( 'coroutine' , 24 , 'f' , 'i32' ) } } } ;
156
- { { { makeSetValueAsm ( 'coroutine' , 28 , 'arg' , 'i32' ) } } } ;
157
- return coroutine | 0 ;
158
- } ,
159
- emscripten_coroutine_next__sig : 'ii' ,
160
- emscripten_coroutine_next__asm : true ,
161
- emscripten_coroutine_next__deps : [ '__async_cur_frame' , '__async' , 'emscripten_async_resume' , 'free' ] ,
162
- emscripten_coroutine_next : function ( coroutine ) {
163
- coroutine = coroutine | 0 ;
164
- var coroutine_not_finished = 0 , temp = 0 ;
165
- // switch context
166
- { { { makeSetValueAsm ( 'coroutine' , 0 , '___async_cur_frame' , 'i32' ) } } } ;
167
- temp = stackSave ( ) | 0 ;
168
- { { { makeSetValueAsm ( 'coroutine' , 4 , 'temp' , 'i32' ) } } } ;
169
- { { { makeSetValueAsm ( 'coroutine' , 8 , 'STACK_MAX' , 'i32' ) } } } ;
170
- ___async_cur_frame = { { { makeGetValueAsm ( 'coroutine' , 12 , 'i32' ) } } } ;
171
- stackRestore ( { { { makeGetValueAsm ( 'coroutine' , 16 , 'i32' ) } } } ) ;
172
- STACK_MAX = coroutine + 32 + { { { makeGetValueAsm ( 'coroutine' , 20 , 'i32' ) } } } | 0 ;
173
-
174
- if ( ! ___async_cur_frame ) {
175
- // first run
176
- { { { makeDynCall ( 'vi' ) } } } (
177
- { { { makeGetValueAsm ( 'coroutine' , 24 , 'i32' ) } } } ,
178
- { { { makeGetValueAsm ( 'coroutine' , 28 , 'i32' ) } } }
179
- ) ;
180
- } else {
181
- _emscripten_async_resume ( ) ;
182
- }
183
-
184
- // switch context
185
- { { { makeSetValueAsm ( 'coroutine' , 12 , '___async_cur_frame' , 'i32' ) } } } ;
186
- temp = stackSave ( ) | 0 ;
187
- { { { makeSetValueAsm ( 'coroutine' , 16 , 'temp' , 'i32' ) } } } ;
188
- ___async_cur_frame = { { { makeGetValueAsm ( 'coroutine' , 0 , 'i32' ) } } } ;
189
- stackRestore ( { { { makeGetValueAsm ( 'coroutine' , 4 , 'i32' ) } } } ) ;
190
- STACK_MAX = { { { makeGetValueAsm ( 'coroutine' , 8 , 'i32' ) } } } ;
191
-
192
- coroutine_not_finished = ___async ;
193
- if ( ! coroutine_not_finished ) {
194
- // coroutine has finished
195
- _free ( coroutine ) ;
196
- }
197
- // coroutine may be created during an async function
198
- // we do not want to affect the original async ctx
199
- // strictly we should backup and restore ___async, ___async_retval and ___async_unwind
200
- // but ___async=0 seems enough
201
- ___async = 0 ;
202
-
203
- return coroutine_not_finished | 0 ;
204
- } ,
205
- emscripten_yield__sig: 'v' ,
206
- emscripten_yield__asm : true ,
207
- emscripten_yield : function ( ) {
208
- ___async = 1 ;
209
- } ,
210
-
211
- emscripten_wget__deps : [ 'emscripten_async_resume' , '$PATH_FS' , '$Browser' ] ,
212
- emscripten_wget : function ( url , file ) {
213
- var _url = UTF8ToString ( url ) ;
214
- var _file = UTF8ToString ( file ) ;
215
- _file = PATH_FS . resolve ( FS . cwd ( ) , _file ) ;
216
- Module [ 'setAsync' ] ( ) ;
217
- noExitRuntime = true ;
218
- var destinationDirectory = PATH . dirname ( _file ) ;
219
- FS . createPreloadedFile (
220
- destinationDirectory ,
221
- PATH . basename ( _file ) ,
222
- _url , true , true ,
223
- _emscripten_async_resume ,
224
- _emscripten_async_resume ,
225
- undefined , // dontCreateFile
226
- undefined , // canOwn
227
- function ( ) { // preFinish
228
- // if the destination directory does not yet exist, create it
229
- FS . mkdirTree ( destinationDirectory ) ;
230
- }
231
- ) ;
232
- } ,
233
-
234
- emscripten_fiber_init : function ( ) {
235
- throw 'emscripten_fiber_init is not implemented for fastcomp ASYNCIFY' ;
236
- } ,
237
- emscripten_fiber_init_from_current_context : function ( ) {
238
- throw 'emscripten_fiber_init_from_current_context is not implemented for fastcomp ASYNCIFY' ;
239
- } ,
240
- emscripten_fiber_swap : function ( ) {
241
- throw 'emscripten_fiber_swap is not implemented for fastcomp ASYNCIFY' ;
242
- } ,
243
-
244
- #else // !WASM_BACKEND
245
23
$Asyncify__deps : [ '$Browser' , '$runAndAbortIfError' ] ,
246
24
$Asyncify : {
247
25
State : {
@@ -719,7 +497,6 @@ mergeInto(LibraryManager.library, {
719
497
emscripten_yield : function ( ) {
720
498
throw 'emscripten_yield has been removed. Please use the Fibers API' ;
721
499
} ,
722
- #endif
723
500
#else // ASYNCIFY
724
501
emscripten_sleep : function ( ) {
725
502
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_sleep' ;
@@ -754,6 +531,6 @@ mergeInto(LibraryManager.library, {
754
531
#endif // ASYNCIFY
755
532
} ) ;
756
533
757
- if ( WASM_BACKEND && ASYNCIFY ) {
534
+ if ( ASYNCIFY ) {
758
535
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE . push ( '$Asyncify' ) ;
759
536
}
0 commit comments