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.

use compat.h for some windows specifics

+41 -37
+3 -3
include/silver/ast.h
··· 77 77 } sv_node_type_t; 78 78 79 79 typedef enum { 80 - VAR_VAR, 81 - VAR_LET, 82 - VAR_CONST, 80 + SV_VAR_VAR, 81 + SV_VAR_LET_ASN, 82 + SV_VAR_CONST, 83 83 } sv_var_kind_t; 84 84 85 85 enum {
+5 -1
src/esm/loader.c
··· 1 + #include <compat.h> // IWYU pragma: keep 2 + 1 3 #include "esm/loader.h" 2 4 #include "esm/commonjs.h" 3 5 #include "esm/library.h" ··· 12 14 #include "reactor.h" 13 15 #include "utils.h" 14 16 15 - #include <libgen.h> 16 17 #include <stdio.h> 17 18 #include <stdlib.h> 18 19 #include <string.h> 19 20 #include <sys/stat.h> 21 + #ifndef _WIN32 22 + #include <libgen.h> 20 23 #include <unistd.h> 24 + #endif 21 25 #include <uthash.h> 22 26 #include <yyjson.h> 23 27
+1 -1
src/repl.c
··· 223 223 sv_ast_t *node = (stmt->type == N_EXPORT) ? stmt->left : stmt; 224 224 if (!node) return true; 225 225 226 - if (node->type == N_VAR && node->var_kind != VAR_VAR) { 226 + if (node->type == N_VAR && node->var_kind != SV_VAR_VAR) { 227 227 for (int i = 0; i < node->args.count; i++) { 228 228 sv_ast_t *decl = node->args.items[i]; 229 229 if (!decl || decl->type != N_VARDECL || !decl->left) continue;
+9 -9
src/silver/ast.c
··· 1421 1421 if (NEXT() == TOK_ASSIGN) { 1422 1422 CONSUME(); 1423 1423 decl->right = parse_assign(p); 1424 - } else if (kind == VAR_CONST && !allow_uninit_const) { 1424 + } else if (kind == SV_VAR_CONST && !allow_uninit_const) { 1425 1425 SV_MKERR_TYPED(JS, JS_ERR_SYNTAX, "Missing initializer in const declaration"); 1426 1426 } 1427 1427 sv_ast_list_push(&var->args, decl); ··· 1644 1644 if (TOK == TOK_VAR || TOK == TOK_LET || TOK == TOK_CONST) { 1645 1645 decl->flags |= EX_DECL; 1646 1646 sv_var_kind_t kind = ( 1647 - TOK == TOK_VAR) ? VAR_VAR : 1648 - (TOK == TOK_LET) ? VAR_LET : VAR_CONST; 1647 + TOK == TOK_VAR) ? SV_VAR_VAR : 1648 + (TOK == TOK_LET) ? SV_VAR_LET : SV_VAR_CONST; 1649 1649 CONSUME(); 1650 1650 decl->left = parse_var_decl(p, kind, false); 1651 1651 if (NEXT() == TOK_SEMICOLON) CONSUME(); ··· 1769 1769 1770 1770 l_var: { 1771 1771 CONSUME(); 1772 - sv_ast_t *n = parse_var_decl(p, VAR_VAR, false); 1772 + sv_ast_t *n = parse_var_decl(p, SV_VAR_VAR, false); 1773 1773 if (NEXT() == TOK_SEMICOLON) CONSUME(); 1774 1774 return n; 1775 1775 } 1776 1776 l_let: { 1777 1777 CONSUME(); 1778 - sv_ast_t *n = parse_var_decl(p, VAR_LET, false); 1778 + sv_ast_t *n = parse_var_decl(p, SV_VAR_LET, false); 1779 1779 if (NEXT() == TOK_SEMICOLON) CONSUME(); 1780 1780 return n; 1781 1781 } 1782 1782 l_const: { 1783 1783 CONSUME(); 1784 - sv_ast_t *n = parse_var_decl(p, VAR_CONST, false); 1784 + sv_ast_t *n = parse_var_decl(p, SV_VAR_CONST, false); 1785 1785 if (NEXT() == TOK_SEMICOLON) CONSUME(); 1786 1786 return n; 1787 1787 } ··· 1835 1835 NEXT(); 1836 1836 if (TOK == TOK_VAR || TOK == TOK_LET || TOK == TOK_CONST) { 1837 1837 sv_var_kind_t kind = ( 1838 - TOK == TOK_VAR) ? VAR_VAR : 1839 - (TOK == TOK_LET) ? VAR_LET : VAR_CONST; 1838 + TOK == TOK_VAR) ? SV_VAR_VAR : 1839 + (TOK == TOK_LET) ? SV_VAR_LET : SV_VAR_CONST; 1840 1840 CONSUME(); 1841 1841 p->no_in = true; 1842 1842 init_node = parse_var_decl(p, kind, true); ··· 1868 1868 return n; 1869 1869 } 1870 1870 1871 - if (init_node && init_node->type == N_VAR && init_node->var_kind == VAR_CONST) { 1871 + if (init_node && init_node->type == N_VAR && init_node->var_kind == SV_VAR_CONST) { 1872 1872 for (int i = 0; i < init_node->args.count; i++) { 1873 1873 sv_ast_t *decl = init_node->args.items[i]; 1874 1874 if (decl && decl->type == N_VARDECL && !decl->right) {
+23 -23
src/silver/compiler.c
··· 803 803 if (!node) return; 804 804 switch (node->type) { 805 805 case N_VAR: 806 - if (node->var_kind == VAR_VAR) { 806 + if (node->var_kind == SV_VAR_VAR) { 807 807 for (int i = 0; i < node->args.count; i++) { 808 808 sv_ast_t *decl = node->args.items[i]; 809 809 if (decl->type == N_VARDECL && decl->left) ··· 902 902 sv_ast_t *decl_node = (node->type == N_EXPORT) ? node->left : node; 903 903 if (!decl_node) continue; 904 904 905 - if (decl_node->type == N_VAR && decl_node->var_kind != VAR_VAR) { 906 - bool is_const = (decl_node->var_kind == VAR_CONST); 905 + if (decl_node->type == N_VAR && decl_node->var_kind != SV_VAR_VAR) { 906 + bool is_const = (decl_node->var_kind == SV_VAR_CONST); 907 907 int lb = c->local_count; 908 908 for (int j = 0; j < decl_node->args.count; j++) { 909 909 sv_ast_t *decl = decl_node->args.items[j]; ··· 2063 2063 } 2064 2064 2065 2065 if (target->type == N_IDENT) { 2066 - bool is_const = (kind == VAR_CONST); 2066 + bool is_const = (kind == SV_VAR_CONST); 2067 2067 int idx = ensure_local_at_depth(c, target->str, target->len, 2068 2068 is_const, c->scope_depth); 2069 2069 emit_put_local(c, idx); ··· 2179 2179 2180 2180 static void compile_array_destructure(sv_compiler_t *c, sv_ast_t *pat, 2181 2181 bool keep) { 2182 - compile_destructure_pattern(c, pat, keep, true, DESTRUCTURE_ASSIGN, VAR_LET); 2182 + compile_destructure_pattern(c, pat, keep, true, DESTRUCTURE_ASSIGN, SV_VAR_LET); 2183 2183 } 2184 2184 2185 2185 static void compile_object_destructure(sv_compiler_t *c, sv_ast_t *pat, 2186 2186 bool keep) { 2187 - compile_destructure_pattern(c, pat, keep, true, DESTRUCTURE_ASSIGN, VAR_LET); 2187 + compile_destructure_pattern(c, pat, keep, true, DESTRUCTURE_ASSIGN, SV_VAR_LET); 2188 2188 } 2189 2189 2190 2190 static bool is_tail_callable(sv_compiler_t *c, sv_ast_t *node) { ··· 2496 2496 sv_ast_t *decl = node->left; 2497 2497 if (decl->type == N_VAR) { 2498 2498 compile_var_decl(c, decl); 2499 - bool is_var = decl->var_kind == VAR_VAR; 2499 + bool is_var = decl->var_kind == SV_VAR_VAR; 2500 2500 for (int i = 0; i < decl->args.count; i++) { 2501 2501 sv_ast_t *var = decl->args.items[i]; 2502 2502 if (!var || var->type != N_VARDECL) continue; ··· 2570 2570 2571 2571 static void compile_var_decl(sv_compiler_t *c, sv_ast_t *node) { 2572 2572 sv_var_kind_t kind = node->var_kind; 2573 - bool is_const = (kind == VAR_CONST); 2573 + bool is_const = (kind == SV_VAR_CONST); 2574 2574 bool repl_top = is_repl_top_level(c); 2575 2575 2576 2576 for (int i = 0; i < node->args.count; i++) { ··· 2579 2579 sv_ast_t *target = decl->left; 2580 2580 2581 2581 if (repl_top) { 2582 - if (!decl->right && kind == VAR_VAR) continue; 2582 + if (!decl->right && kind == SV_VAR_VAR) continue; 2583 2583 if (decl->right) { 2584 2584 compile_expr(c, decl->right); 2585 2585 } else { ··· 2591 2591 compile_destructure_pattern(c, target, false, true, 2592 2592 DESTRUCTURE_ASSIGN, kind); 2593 2593 } 2594 - } else if (kind == VAR_VAR) { 2594 + } else if (kind == SV_VAR_VAR) { 2595 2595 if (decl->right) { 2596 2596 compile_expr(c, decl->right); 2597 2597 compile_lhs_set(c, target, false); ··· 2752 2752 if (node->init->type == N_VAR) { 2753 2753 sv_var_kind_t kind = node->init->var_kind; 2754 2754 compile_var_decl(c, node->init); 2755 - if (kind == VAR_LET || kind == VAR_CONST) 2755 + if (kind == SV_VAR_LET || kind == SV_VAR_CONST) 2756 2756 for_collect_var_decl_slots(c, node->init, &iter_slots, &iter_count, &iter_cap); 2757 2757 } else { 2758 2758 compile_expr(c, node->init); ··· 2858 2858 if (target->type == N_IDENT) { 2859 2859 int loc = resolve_local(c, target->str, target->len); 2860 2860 if (loc == -1) { 2861 - bool is_const = (lhs->var_kind == VAR_CONST); 2861 + bool is_const = (lhs->var_kind == SV_VAR_CONST); 2862 2862 loc = add_local(c, target->str, target->len, is_const, c->scope_depth); 2863 2863 } 2864 2864 emit_put_local(c, loc); 2865 2865 } else { 2866 - if (lhs->var_kind == VAR_VAR) { 2866 + if (lhs->var_kind == SV_VAR_VAR) { 2867 2867 compile_lhs_set(c, target, false); 2868 2868 } else { 2869 2869 compile_destructure_binding(c, target, lhs->var_kind); ··· 2887 2887 int iter_cap = 0; 2888 2888 2889 2889 if (node->left && node->left->type == N_VAR && 2890 - node->left->var_kind != VAR_VAR) { 2891 - bool is_const = (node->left->var_kind == VAR_CONST); 2890 + node->left->var_kind != SV_VAR_VAR) { 2891 + bool is_const = (node->left->var_kind == SV_VAR_CONST); 2892 2892 int lb = c->local_count; 2893 2893 for (int i = 0; i < node->left->args.count; i++) { 2894 2894 sv_ast_t *decl = node->left->args.items[i]; ··· 2905 2905 } 2906 2906 2907 2907 if (!is_for_of && node->left && node->left->type == N_VAR && 2908 - node->left->var_kind == VAR_VAR && node->left->args.count > 0) { 2908 + node->left->var_kind == SV_VAR_VAR && node->left->args.count > 0) { 2909 2909 sv_ast_t *decl = node->left->args.items[0]; 2910 2910 if (decl && decl->right) { 2911 2911 compile_expr(c, decl->right); ··· 3100 3100 node->catch_param->len, false, c->scope_depth); 3101 3101 emit_put_local(c, loc); 3102 3102 } else if (node->catch_param && is_destructure_pattern_node(node->catch_param)) { 3103 - compile_destructure_binding(c, node->catch_param, VAR_LET); 3103 + compile_destructure_binding(c, node->catch_param, SV_VAR_LET); 3104 3104 emit_op(c, OP_POP); 3105 3105 } else { 3106 3106 emit_op(c, OP_POP); ··· 3657 3657 emit_op(&comp, OP_PUT_ARG); 3658 3658 emit_u16(&comp, (uint16_t)i); 3659 3659 } else if (p->left) { 3660 - compile_destructure_binding(&comp, p->left, VAR_LET); 3660 + compile_destructure_binding(&comp, p->left, SV_VAR_LET); 3661 3661 emit_op(&comp, OP_POP); 3662 3662 } else emit_op(&comp, OP_POP); 3663 3663 } else if ( ··· 3665 3665 p->type == N_OBJECT_PAT || p->type == N_OBJECT) { 3666 3666 emit_op(&comp, OP_GET_ARG); 3667 3667 emit_u16(&comp, (uint16_t)i); 3668 - compile_destructure_binding(&comp, p, VAR_LET); 3668 + compile_destructure_binding(&comp, p, SV_VAR_LET); 3669 3669 emit_op(&comp, OP_POP); 3670 3670 } else if (p->type == N_REST && p->right && p->right->type == N_IDENT) { 3671 3671 emit_op(&comp, OP_REST); ··· 3678 3678 } else if (p->type == N_REST && p->right) { 3679 3679 emit_op(&comp, OP_REST); 3680 3680 emit_u16(&comp, (uint16_t)i); 3681 - compile_destructure_binding(&comp, p->right, VAR_LET); 3681 + compile_destructure_binding(&comp, p->right, SV_VAR_LET); 3682 3682 emit_op(&comp, OP_POP); 3683 3683 } 3684 3684 } ··· 3749 3749 if (slot <= 255) { emit_op(&comp, OP_PUT_LOCAL8); emit(&comp, (uint8_t)slot); } 3750 3750 else { emit_op(&comp, OP_PUT_LOCAL); emit_u16(&comp, (uint16_t)slot); } 3751 3751 } else if (p->left) { 3752 - compile_destructure_binding(&comp, p->left, VAR_LET); 3752 + compile_destructure_binding(&comp, p->left, SV_VAR_LET); 3753 3753 emit_op(&comp, OP_POP); 3754 3754 } else { 3755 3755 emit_op(&comp, OP_POP); ··· 3759 3759 p->type == N_OBJECT_PAT || p->type == N_OBJECT) { 3760 3760 emit_op(&comp, OP_GET_ARG); 3761 3761 emit_u16(&comp, (uint16_t)i); 3762 - compile_destructure_binding(&comp, p, VAR_LET); 3762 + compile_destructure_binding(&comp, p, SV_VAR_LET); 3763 3763 emit_op(&comp, OP_POP); 3764 3764 } else if ( 3765 3765 p->type == N_REST && p->right && p->right->type == N_IDENT && ··· 3773 3773 } else if (p->type == N_REST && p->right) { 3774 3774 emit_op(&comp, OP_REST); 3775 3775 emit_u16(&comp, (uint16_t)i); 3776 - compile_destructure_binding(&comp, p->right, VAR_LET); 3776 + compile_destructure_binding(&comp, p->right, SV_VAR_LET); 3777 3777 emit_op(&comp, OP_POP); 3778 3778 } 3779 3779 }