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.

update GC functions to use op_val instead of fwd_val

+69 -58
-3
include/ant.h
··· 30 30 #define ANT_LIMIT_SIZE_CACHE 16384 31 31 #define CORO_PER_TICK_LIMIT 10000 32 32 33 - #define GC_FWD_ARGS jsval_t (*fwd_val)(void *ctx, jsval_t old), void *ctx 34 - #define GC_UPDATE_ARGS ant_t *js, jsoff_t (*fwd_off)(void *ctx, jsoff_t old), GC_FWD_ARGS 35 - 36 33 #define JS_DESC_W (1 << 0) 37 34 #define JS_DESC_E (1 << 1) 38 35 #define JS_DESC_C (1 << 2)
+6
include/gc.h
··· 1 1 #ifndef GC_H 2 2 #define GC_H 3 3 4 + #include <types.h> 5 + 4 6 #define GC_FWD_LOAD_FACTOR 70 5 7 #define GC_ROOTS_INITIAL_CAP 32 8 + 9 + #define GC_FWD_ARGS jsval_t (*fwd_val)(void *ctx, jsval_t old), void *ctx 10 + #define GC_UPDATE_ARGS ant_t *js, jsoff_t (*fwd_off)(void *ctx, jsoff_t old), GC_FWD_ARGS 11 + #define GC_OP_VAL_ARGS void (*op_val)(void *ctx, jsval_t *val), void *ctx 6 12 7 13 #endif
+1
include/internal.h
··· 2 2 #define ANT_INTERNAL_H 3 3 4 4 #include "ant.h" 5 + #include "gc.h" 5 6 6 7 struct for_let_ctx { 7 8 const char *var_name; // interned variable name
+5 -3
include/modules/child_process.h
··· 1 1 #ifndef ANT_CHILD_PROCESS_MODULE_H 2 2 #define ANT_CHILD_PROCESS_MODULE_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 + #include "types.h" 5 6 6 7 jsval_t child_process_library(struct js *js); 7 - void child_process_poll_events(void); 8 8 int has_pending_child_processes(void); 9 - void child_process_gc_update_roots(GC_FWD_ARGS); 9 + 10 + void child_process_poll_events(void); 11 + void child_process_gc_update_roots(GC_OP_VAL_ARGS); 10 12 11 13 #endif
+2 -2
include/modules/fetch.h
··· 1 1 #ifndef FETCH_H 2 2 #define FETCH_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 5 6 6 void init_fetch_module(void); 7 7 void fetch_poll_events(void); 8 - void fetch_gc_update_roots(GC_FWD_ARGS); 8 + void fetch_gc_update_roots(GC_OP_VAL_ARGS); 9 9 10 10 int has_pending_fetches(void); 11 11
+3 -2
include/modules/ffi.h
··· 1 1 #ifndef ANT_FFI_H 2 2 #define ANT_FFI_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 + #include "types.h" 5 6 6 7 jsval_t ffi_library(struct js *js); 7 8 jsval_t ffi_call_by_index(struct js *js, unsigned int func_index, jsval_t *args, int nargs); 8 9 9 - void ffi_gc_update_roots(GC_FWD_ARGS); 10 + void ffi_gc_update_roots(GC_OP_VAL_ARGS); 10 11 11 12 #endif
+3 -2
include/modules/fs.h
··· 1 1 #ifndef ANT_FS_MODULE_H 2 2 #define ANT_FS_MODULE_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 + #include "types.h" 5 6 6 7 jsval_t fs_library(struct js *js); 7 8 int has_pending_fs_ops(void); 8 9 9 10 void init_fs_module(void); 10 11 void fs_poll_events(void); 11 - void fs_gc_update_roots(GC_FWD_ARGS); 12 + void fs_gc_update_roots(GC_OP_VAL_ARGS); 12 13 13 14 #endif
+2 -2
include/modules/process.h
··· 1 1 #ifndef PROCESS_H 2 2 #define PROCESS_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 5 6 - void process_gc_update_roots(GC_FWD_ARGS); 6 + void process_gc_update_roots(GC_OP_VAL_ARGS); 7 7 void process_enable_keypress_events(void); 8 8 9 9 void init_process_module(void);
+3 -2
include/modules/readline.h
··· 1 1 #ifndef READLINE_H 2 2 #define READLINE_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 + #include "types.h" 5 6 #include <stdbool.h> 6 7 7 8 jsval_t readline_library(struct js *js); 8 9 jsval_t readline_promises_library(struct js *js); 9 10 10 11 bool has_active_readline_interfaces(void); 11 - void readline_gc_update_roots(GC_FWD_ARGS); 12 + void readline_gc_update_roots(GC_OP_VAL_ARGS); 12 13 13 14 #endif
+3 -2
include/modules/timer.h
··· 1 1 #ifndef TIMER_H 2 2 #define TIMER_H 3 3 4 - #include "ant.h" 4 + #include "gc.h" 5 + #include "types.h" 5 6 6 7 void init_timer_module(void); 7 8 void process_timers(struct js *js); ··· 9 10 void process_immediates(struct js *js); 10 11 void queue_microtask(struct js *js, jsval_t callback); 11 12 void queue_promise_trigger(uint32_t promise_id); 12 - void timer_gc_update_roots(GC_FWD_ARGS); 13 + void timer_gc_update_roots(GC_OP_VAL_ARGS); 13 14 14 15 int has_pending_timers(void); 15 16 int has_pending_microtasks(void);
+7 -7
src/ant.c
··· 22779 22779 op_val(c, &mod->default_export); 22780 22780 } 22781 22781 22782 - timer_gc_update_roots(c->fwd_val, c->ctx); 22783 - ffi_gc_update_roots(c->fwd_val, c->ctx); 22784 - fetch_gc_update_roots(c->fwd_val, c->ctx); 22785 - fs_gc_update_roots(c->fwd_val, c->ctx); 22786 - child_process_gc_update_roots(c->fwd_val, c->ctx); 22787 - readline_gc_update_roots(c->fwd_val, c->ctx); 22788 - process_gc_update_roots(c->fwd_val, c->ctx); 22782 + timer_gc_update_roots(op_val, c); 22783 + ffi_gc_update_roots(op_val, c); 22784 + fetch_gc_update_roots(op_val, c); 22785 + fs_gc_update_roots(op_val, c); 22786 + child_process_gc_update_roots(op_val, c); 22787 + readline_gc_update_roots(op_val, c); 22788 + process_gc_update_roots(op_val, c); 22789 22789 22790 22790 map_registry_entry_t *map_reg, *map_reg_tmp; 22791 22791 HASH_ITER(hh, map_registry, map_reg, map_reg_tmp) {
+2 -2
src/gc.c
··· 339 339 340 340 jsoff_t header = gc_loadoff(ctx->js->mem, old_off); 341 341 342 - jsoff_t next_prop = header & ~(3U | FLAGMASK); 342 + jsoff_t next_prop = header & ~(3ULL | FLAGMASK); 343 343 if (next_prop != 0 && next_prop < ctx->js->brk) { 344 344 jsoff_t new_next = gc_reserve_prop(ctx, next_prop); 345 345 jsoff_t new_header = (new_next & ~3ULL) | (header & (3ULL | FLAGMASK)); ··· 367 367 368 368 jsoff_t header = gc_loadoff(ctx->js->mem, old_off); 369 369 370 - jsoff_t first_prop = header & ~(3U | FLAGMASK); 370 + jsoff_t first_prop = header & ~(3ULL | FLAGMASK); 371 371 if (first_prop != 0 && first_prop < ctx->js->brk) { 372 372 jsoff_t new_first = gc_reserve_prop(ctx, first_prop); 373 373 jsoff_t new_header = (new_first & ~3ULL) | (header & (3ULL | FLAGMASK));
+4 -4
src/modules/child_process.c
··· 1157 1157 } 1158 1158 } 1159 1159 1160 - void child_process_gc_update_roots(GC_FWD_ARGS) { 1160 + void child_process_gc_update_roots(GC_OP_VAL_ARGS) { 1161 1161 for (child_process_t *cp = pending_children_head; cp; cp = cp->next) { 1162 - cp->child_obj = fwd_val(ctx, cp->child_obj); 1163 - cp->promise = fwd_val(ctx, cp->promise); 1162 + op_val(ctx, &cp->child_obj); 1163 + op_val(ctx, &cp->promise); 1164 1164 1165 1165 child_event_t *evt, *tmp; 1166 1166 HASH_ITER(hh, cp->events, evt, tmp) { 1167 - for (int i = 0; i < evt->count; i++) evt->listeners[i].callback = fwd_val(ctx, evt->listeners[i].callback); 1167 + for (int i = 0; i < evt->count; i++) op_val(ctx, &evt->listeners[i].callback); 1168 1168 } 1169 1169 } 1170 1170 }
+3 -3
src/modules/fetch.c
··· 368 368 } 369 369 } 370 370 371 - void fetch_gc_update_roots(GC_FWD_ARGS) { 371 + void fetch_gc_update_roots(GC_OP_VAL_ARGS) { 372 372 if (!pending_requests) return; 373 373 unsigned int len = utarray_len(pending_requests); 374 374 for (unsigned int i = 0; i < len; i++) { 375 375 fetch_request_t **reqp = (fetch_request_t **)utarray_eltptr(pending_requests, i); 376 376 if (reqp && *reqp) { 377 - (*reqp)->promise = fwd_val(ctx, (*reqp)->promise); 378 - (*reqp)->headers_obj = fwd_val(ctx, (*reqp)->headers_obj); 377 + op_val(ctx, &(*reqp)->promise); 378 + op_val(ctx, &(*reqp)->headers_obj); 379 379 } 380 380 } 381 381 }
+2 -2
src/modules/ffi.c
··· 991 991 return js_mkundef(); 992 992 } 993 993 994 - void ffi_gc_update_roots(GC_FWD_ARGS) { 994 + void ffi_gc_update_roots(GC_OP_VAL_ARGS) { 995 995 pthread_mutex_lock(&ffi_callbacks_mutex); 996 996 ffi_callback_t *cb, *tmp; 997 997 HASH_ITER(hh, ffi_callbacks, cb, tmp) { 998 - cb->js_func = fwd_val(ctx, cb->js_func); 998 + op_val(ctx, &cb->js_func); 999 999 } 1000 1000 pthread_mutex_unlock(&ffi_callbacks_mutex); 1001 1001 }
+2 -2
src/modules/fs.c
··· 1311 1311 } 1312 1312 } 1313 1313 1314 - void fs_gc_update_roots(GC_FWD_ARGS) { 1314 + void fs_gc_update_roots(GC_OP_VAL_ARGS) { 1315 1315 if (!pending_requests) return; 1316 1316 unsigned int len = utarray_len(pending_requests); 1317 1317 for (unsigned int i = 0; i < len; i++) { 1318 1318 fs_request_t **reqp = (fs_request_t **)utarray_eltptr(pending_requests, i); 1319 - if (reqp && *reqp) { (*reqp)->promise = fwd_val(ctx, (*reqp)->promise); } 1319 + if (reqp && *reqp) { op_val(ctx, &(*reqp)->promise); } 1320 1320 } 1321 1321 }
+8 -8
src/modules/process.c
··· 1676 1676 js_set(js, global, "process", process_obj); 1677 1677 } 1678 1678 1679 - #define GC_FWD_EVENTS(events) do { \ 1679 + #define GC_OP_EVENTS(events) do { \ 1680 1680 ProcessEventType *evt, *tmp; \ 1681 1681 HASH_ITER(hh, events, evt, tmp) { \ 1682 1682 for (int i = 0; i < evt->listener_count; i++) \ 1683 - evt->listeners[i].listener = fwd_val(ctx, evt->listeners[i].listener); \ 1683 + op_val(ctx, &evt->listeners[i].listener); \ 1684 1684 } \ 1685 1685 } while(0) 1686 1686 1687 - void process_gc_update_roots(GC_FWD_ARGS) { 1688 - GC_FWD_EVENTS(process_events); 1689 - GC_FWD_EVENTS(stdin_events); 1690 - GC_FWD_EVENTS(stdout_events); 1691 - GC_FWD_EVENTS(stderr_events); 1687 + void process_gc_update_roots(GC_OP_VAL_ARGS) { 1688 + GC_OP_EVENTS(process_events); 1689 + GC_OP_EVENTS(stdin_events); 1690 + GC_OP_EVENTS(stdout_events); 1691 + GC_OP_EVENTS(stderr_events); 1692 1692 } 1693 1693 1694 - #undef GC_FWD_EVENTS 1694 + #undef GC_OP_EVENTS 1695 1695 1696 1696 bool has_active_stdin(void) { 1697 1697 return stdin_state.reading;
+8 -8
src/modules/readline.c
··· 1258 1258 return false; 1259 1259 } 1260 1260 1261 - void readline_gc_update_roots(GC_FWD_ARGS) { 1261 + void readline_gc_update_roots(GC_OP_VAL_ARGS) { 1262 1262 rl_interface_t *iface, *tmp; 1263 1263 HASH_ITER(hh, interfaces, iface, tmp) { 1264 - iface->input_stream = fwd_val(ctx, iface->input_stream); 1265 - iface->output_stream = fwd_val(ctx, iface->output_stream); 1266 - iface->completer = fwd_val(ctx, iface->completer); 1267 - iface->js_obj = fwd_val(ctx, iface->js_obj); 1268 - iface->pending_question_resolve = fwd_val(ctx, iface->pending_question_resolve); 1269 - iface->pending_question_reject = fwd_val(ctx, iface->pending_question_reject); 1264 + op_val(ctx, &iface->input_stream); 1265 + op_val(ctx, &iface->output_stream); 1266 + op_val(ctx, &iface->completer); 1267 + op_val(ctx, &iface->js_obj); 1268 + op_val(ctx, &iface->pending_question_resolve); 1269 + op_val(ctx, &iface->pending_question_reject); 1270 1270 1271 1271 RLEventType *evt, *evt_tmp; 1272 1272 HASH_ITER(hh, iface->events, evt, evt_tmp) { 1273 - for (int i = 0; i < evt->listener_count; i++) evt->listeners[i].listener = fwd_val(ctx, evt->listeners[i].listener); 1273 + for (int i = 0; i < evt->listener_count; i++) op_val(ctx, &evt->listeners[i].listener); 1274 1274 } 1275 1275 } 1276 1276 }
+5 -4
src/modules/timer.c
··· 13 13 14 14 #include "arena.h" 15 15 #include "errors.h" 16 + #include "internal.h" 16 17 #include "runtime.h" 17 18 #include "modules/timer.h" 18 19 ··· 365 366 js_set(js, global, "queueMicrotask", js_mkfun(js_queue_microtask)); 366 367 } 367 368 368 - void timer_gc_update_roots(GC_FWD_ARGS) { 369 + void timer_gc_update_roots(GC_OP_VAL_ARGS) { 369 370 for (timer_entry_t *t = timer_state.timers; t; t = t->next) { 370 - t->callback = fwd_val(ctx, t->callback); 371 + op_val(ctx, &t->callback); 371 372 } 372 373 for (microtask_entry_t *m = timer_state.microtasks; m; m = m->next) { 373 - if (m->promise_id == 0) m->callback = fwd_val(ctx, m->callback); 374 + if (m->promise_id == 0) op_val(ctx, &m->callback); 374 375 } 375 376 for (immediate_entry_t *i = timer_state.immediates; i; i = i->next) { 376 - i->callback = fwd_val(ctx, i->callback); 377 + op_val(ctx, &i->callback); 377 378 } 378 379 }