MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

undo token stream for coro

+37 -35
-3
include/sugar.h
··· 45 45 int for_let_stack_len; 46 46 int for_let_stack_cap; 47 47 UT_array *scope_stack; 48 - void *token_stream; 49 - int token_stream_pos; 50 - const char *token_stream_code; 51 48 } coroutine_t; 52 49 53 50 typedef struct {
+1 -1
meson/version/meson.build
··· 4 4 timestamp_opt = get_option('build_timestamp') 5 5 timestamp = timestamp_opt != '' ? timestamp_opt : run_command('date', '+%s', check: true).stdout().strip() 6 6 7 - ant_version = '0.5.2.' + timestamp + '-g' + git_hash 7 + ant_version = '0.5.3.' + timestamp + '-g' + git_hash 8 8 cmd_cc = meson.get_compiler('c') 9 9 10 10 target_triple = run_command(cmd_cc.cmd_array(), '-dumpmachine', check: true).stdout().strip()
+36 -12
src/ant.c
··· 199 199 jsoff_t obj_offset; 200 200 int state; 201 201 bool has_rejection_handler; 202 + bool processing; 202 203 UT_hash_handle hh; 203 204 UT_hash_handle hh_unhandled; 204 205 } promise_data_entry_t; ··· 629 630 jsoff_t clen, pos; 630 631 uint8_t tok, consumed; 631 632 int token_stream_pos; 633 + void *token_stream; 634 + const char *token_stream_code; 632 635 } js_parse_state_t; 633 636 634 637 #define JS_SAVE_STATE(js, state) do { \ ··· 638 641 (state).tok = (js)->tok; \ 639 642 (state).consumed = (js)->consumed; \ 640 643 (state).token_stream_pos = (js)->token_stream_pos; \ 644 + (state).token_stream = (js)->token_stream; \ 645 + (state).token_stream_code = (js)->token_stream_code; \ 641 646 } while(0) 642 647 643 648 #define JS_RESTORE_STATE(js, state) do { \ ··· 647 652 (js)->tok = (state).tok; \ 648 653 (js)->consumed = (state).consumed; \ 649 654 (js)->token_stream_pos = (state).token_stream_pos; \ 655 + (js)->token_stream = (state).token_stream; \ 656 + (js)->token_stream_code = (state).token_stream_code; \ 650 657 } while(0) 651 658 652 659 static size_t strstring(struct js *js, jsval_t value, char *buf, size_t len); ··· 19689 19696 jsval_t val = pd->value; 19690 19697 19691 19698 unsigned int len = utarray_len(pd->handlers); 19699 + if (len == 0) { return; } pd->processing = true; 19700 + 19692 19701 for (unsigned int i = 0; i < len; i++) { 19693 19702 promise_handler_t *h = (promise_handler_t *)utarray_eltptr(pd->handlers, i); 19694 19703 jsval_t handler = (state == 1) ? h->onFulfilled : h->onRejected; ··· 19717 19726 } 19718 19727 } 19719 19728 19729 + pd->processing = false; 19720 19730 utarray_clear(pd->handlers); 19721 19731 } 19722 19732 ··· 22429 22439 UTARRAY_EACH(coro->scope_stack, jsoff_t, off) op_off(c, off); 22430 22440 } 22431 22441 22432 - if (coro->mco) { 22433 - async_exec_context_t *actx = (async_exec_context_t *)mco_get_user_data(coro->mco); 22434 - if (actx) { 22435 - op_val(c, &actx->closure_scope); 22436 - op_val(c, &actx->result); 22437 - op_val(c, &actx->promise); 22438 - } 22442 + async_exec_context_t *actx; 22443 + if (coro->mco && (actx = mco_get_user_data(coro->mco))) { 22444 + op_val(c, &actx->closure_scope); 22445 + op_val(c, &actx->result); 22446 + op_val(c, &actx->promise); 22439 22447 } 22440 22448 } 22441 22449 ··· 22527 22535 HASH_ITER(hh, promise_registry, pd, pd_tmp) { 22528 22536 HASH_DEL(promise_registry, pd); 22529 22537 promise_data_entry_t *in_unhandled = NULL; 22530 - HASH_FIND(hh_unhandled, unhandled_rejections, &pd->promise_id, sizeof(uint32_t), in_unhandled); 22538 + 22539 + HASH_FIND( 22540 + hh_unhandled, unhandled_rejections, 22541 + &pd->promise_id, sizeof(uint32_t), in_unhandled 22542 + ); 22543 + 22531 22544 if (in_unhandled) HASH_DELETE(hh_unhandled, unhandled_rejections, pd); 22532 - 22533 22545 jsoff_t new_off = weak_off(ctx, pd->obj_offset); 22534 - if (new_off == (jsoff_t)~0) { utarray_free(pd->handlers); free(pd); continue; } 22535 22546 22536 - bool can_collect = (pd->state != 0) && (utarray_len(pd->handlers) == 0); 22537 - if (can_collect) { utarray_free(pd->handlers); free(pd); continue; } 22547 + if (new_off == (jsoff_t)~0 && !pd->processing) { 22548 + utarray_free(pd->handlers); 22549 + free(pd); continue; 22550 + } 22551 + 22552 + bool can_collect = (pd->state != 0) 22553 + && (utarray_len(pd->handlers) == 0) 22554 + && !pd->processing; 22555 + 22556 + if (can_collect) { 22557 + utarray_free(pd->handlers); 22558 + free(pd); continue; 22559 + } 22560 + 22538 22561 pd->obj_offset = new_off; 22539 22562 FWD_VAL(pd->value); 22563 + 22540 22564 UTARRAY_EACH(pd->handlers, promise_handler_t, h) { 22541 22565 FWD_VAL(h->onFulfilled); 22542 22566 FWD_VAL(h->onRejected);
-19
src/sugar.c
··· 84 84 coro->for_let_stack_cap = tmp_cap; 85 85 } 86 86 87 - static void token_stream_swap_with_coro(struct js *js, coroutine_t *coro) { 88 - void *tmp_stream = js->token_stream; 89 - int tmp_pos = js->token_stream_pos; 90 - const char *tmp_code = js->token_stream_code; 91 - 92 - js->token_stream = coro->token_stream; 93 - js->token_stream_pos = coro->token_stream_pos; 94 - js->token_stream_code = coro->token_stream_code; 95 - 96 - coro->token_stream = tmp_stream; 97 - coro->token_stream_pos = tmp_pos; 98 - coro->token_stream_code = tmp_code; 99 - } 100 - 101 87 coro_saved_state_t coro_enter(struct js *js, coroutine_t *coro) { 102 88 extern UT_array *global_scope_stack; 103 89 coro_saved_state_t saved = { js->scope, global_scope_stack }; 104 90 js->scope = coro->scope; 105 91 global_scope_stack = coro->scope_stack; 106 92 for_let_swap_with_coro(js, coro); 107 - token_stream_swap_with_coro(js, coro); 108 93 return saved; 109 94 } 110 95 ··· 115 100 js->scope = saved.scope; 116 101 global_scope_stack = saved.scope_stack; 117 102 for_let_swap_with_coro(js, coro); 118 - token_stream_swap_with_coro(js, coro); 119 103 } 120 104 121 105 static size_t calculate_coro_stack_size(void) { ··· 228 212 .for_let_stack = NULL, 229 213 .for_let_stack_len = 0, 230 214 .for_let_stack_cap = 0, 231 - .token_stream = NULL, 232 - .token_stream_pos = 0, 233 - .token_stream_code = NULL, 234 215 }; 235 216 236 217 if (nargs > 0) {