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.

fix scoping for gc

+38 -10
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.0.7.18') 77 + version_conf.set('ANT_VERSION', '0.0.7.19') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+34 -6
src/ant.c
··· 100 100 } FreeListEntry; 101 101 102 102 static UT_array *global_free_list = NULL; 103 + static UT_array *global_scope_stack = NULL; 103 104 static jsoff_t protected_brk = 0; 105 + 106 + static const UT_icd jsoff_icd = { 107 + .sz = sizeof(jsoff_t), 108 + .init = NULL, 109 + .copy = NULL, 110 + .dtor = NULL, 111 + }; 104 112 105 113 static const UT_icd free_list_icd = { 106 114 .sz = sizeof(FreeListEntry), ··· 1382 1390 } 1383 1391 1384 1392 static void js_unmark_used_entities(struct js *js) { 1385 - jsval_t scope = js->scope; 1386 - do { 1387 - js_unmark_entity(js, (jsoff_t) vdata(scope)); 1388 - scope = upper(js, scope); 1389 - } while (vdata(scope) != 0); 1393 + js_unmark_entity(js, (jsoff_t) vdata(js->scope)); 1394 + if (global_scope_stack) { 1395 + jsoff_t *p = NULL; 1396 + while ((p = (jsoff_t *)utarray_next(global_scope_stack, p)) != NULL) { 1397 + js_unmark_entity(js, *p); 1398 + } 1399 + } 1400 + js_unmark_entity(js, 0); 1390 1401 if (js->nogc) js_unmark_entity(js, js->nogc); 1391 1402 } 1392 1403 ··· 1548 1559 static void js_compact_from_end(struct js *js) { 1549 1560 jsoff_t new_brk = js->brk; 1550 1561 1562 + jsoff_t min_brk = (jsoff_t) vdata(js->scope) + 8; 1563 + if (global_scope_stack) { 1564 + jsoff_t *p = NULL; 1565 + while ((p = (jsoff_t *)utarray_next(global_scope_stack, p)) != NULL) { 1566 + if (*p + 8 > min_brk) min_brk = *p + 8; 1567 + } 1568 + } 1569 + 1551 1570 for (jsoff_t off = 0; off < js->brk; off += esize(loadoff(js, off) & ~(GCMASK | CONSTMASK))) { 1552 1571 jsoff_t v = loadoff(js, off); 1553 1572 if ((v & GCMASK) == 0) new_brk = off + esize(v & ~(GCMASK | CONSTMASK)); 1554 1573 } 1555 1574 1575 + if (new_brk < min_brk) new_brk = min_brk; 1556 1576 js->brk = new_brk; 1557 1577 } 1558 1578 ··· 1750 1770 1751 1771 void js_mkscope(struct js *js) { 1752 1772 assert((js->flags & F_NOEXEC) == 0); 1773 + if (global_scope_stack == NULL) utarray_new(global_scope_stack, &jsoff_icd); 1753 1774 jsoff_t prev = (jsoff_t) vdata(js->scope); 1775 + utarray_push_back(global_scope_stack, &prev); 1754 1776 js->scope = mkobj(js, prev); 1755 1777 } 1756 1778 1757 1779 void js_delscope(struct js *js) { 1758 - js->scope = upper(js, js->scope); 1780 + if (global_scope_stack && utarray_len(global_scope_stack) > 0) { 1781 + jsoff_t *prev = (jsoff_t *)utarray_back(global_scope_stack); 1782 + js->scope = mkval(T_OBJ, *prev); 1783 + utarray_pop_back(global_scope_stack); 1784 + } else { 1785 + js->scope = upper(js, js->scope); 1786 + } 1759 1787 } 1760 1788 1761 1789 static void mkscope(struct js *js) { js_mkscope(js); }
+2 -3
src/main.c
··· 55 55 56 56 js_set_filename(js, filename); 57 57 js_setup_import_meta(js, filename); 58 + 58 59 js_mkscope(js); 60 + js_protect_init_memory(js); 59 61 60 62 jsval_t result = js_eval(js, buffer, len); 61 63 free(buffer); ··· 137 139 init_timer_module(); 138 140 init_process_module(); 139 141 140 - 141 142 ant_register_library("ant:fs", fs_library); 142 143 ant_register_library("ant:shell", shell_library); 143 144 ant_register_library("ant:path", path_library); 144 145 ant_register_library("ant:ffi", ffi_library); 145 - 146 - js_protect_init_memory(js); 147 146 148 147 if (repl_mode) ant_repl_run(); else { 149 148 js_result = execute_module(js, module_file);
+1
src/repl.c
··· 191 191 192 192 void ant_repl_run() { 193 193 struct js *js = rt->js; 194 + js_protect_init_memory(js); 194 195 195 196 printf("Welcome to Ant JavaScript v%s\n", ANT_VERSION); 196 197 printf("Type \".help\" for more information.\n");