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 global colorizer

+19 -106
+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.1.0.3') 77 + version_conf.set('ANT_VERSION', '0.1.0.4') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+12 -4
src/ant.c
··· 767 767 mark_multiref(obj); 768 768 return; 769 769 } 770 - mark_multiref(obj); 771 770 772 771 if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; 773 772 stringify_stack[stringify_depth++] = obj; ··· 788 787 mark_multiref(obj); 789 788 return; 790 789 } 791 - mark_multiref(obj); 792 790 793 791 if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; 794 792 stringify_stack[stringify_depth++] = obj; ··· 811 809 mark_multiref(func_obj); 812 810 return; 813 811 } 814 - mark_multiref(func_obj); 815 812 816 813 if (stringify_depth >= MAX_STRINGIFY_DEPTH) return; 817 814 stringify_stack[stringify_depth++] = func_obj; ··· 4393 4390 if (exe) { 4394 4391 if (is_err(val)) return val; 4395 4392 if (is_err(key)) return key; 4396 - jsval_t res = setprop(js, obj, key, resolveprop(js, val)); 4393 + jsval_t resolved_val = resolveprop(js, val); 4394 + 4395 + if (vtype(resolved_val) == T_FUNC) { 4396 + jsval_t func_obj = mkval(T_OBJ, vdata(resolved_val)); 4397 + jsoff_t name_prop = lkp(js, func_obj, "name", 4); 4398 + if (name_prop == 0) { 4399 + jsval_t name_key = js_mkstr(js, "name", 4); 4400 + if (!is_err(name_key)) setprop(js, func_obj, name_key, key); 4401 + } 4402 + } 4403 + 4404 + jsval_t res = setprop(js, obj, key, resolved_val); 4397 4405 if (is_err(res)) return res; 4398 4406 } 4399 4407 }
+6 -101
src/modules/io.c
··· 12 12 #define ANSI_YELLOW "\x1b[33m" 13 13 #define ANSI_RESET "\x1b[0m" 14 14 15 - #define JSON_KEY "\x1b[36m" 15 + #define JSON_KEY "\x1b[0m" 16 16 #define JSON_STRING "\x1b[32m" 17 17 #define JSON_NUMBER "\x1b[33m" 18 18 #define JSON_BOOL "\x1b[35m" ··· 22 22 #define JSON_TAG "\x1b[34m" 23 23 #define JSON_REF "\x1b[90m" 24 24 25 - static void print_json_colored(const char *json, FILE *stream) { 26 - bool in_string = false; 27 - bool is_key = true; 28 - bool escape_next = false; 29 - char string_char = 0; 30 - 31 - for (const char *p = json; *p; p++) { 32 - if (escape_next) { 33 - fputc(*p, stream); 34 - escape_next = false; 35 - continue; 36 - } 37 - 38 - if (*p == '\\' && in_string) { 39 - fputc(*p, stream); 40 - escape_next = true; 41 - continue; 42 - } 43 - 44 - if (*p == '\'' || *p == '"') { 45 - if (!in_string) { 46 - fprintf(stream, "%s%c", is_key ? JSON_KEY : JSON_STRING, *p); 47 - in_string = true; 48 - string_char = *p; 49 - } else if (*p == string_char) { 50 - fprintf(stream, "%c%s", *p, ANSI_RESET); 51 - in_string = false; 52 - string_char = 0; 53 - } else { 54 - fputc(*p, stream); 55 - } 56 - continue; 57 - } 58 - 59 - if (in_string) { 60 - fputc(*p, stream); 61 - continue; 62 - } 63 - 64 - if (*p == ':') { 65 - fputc(*p, stream); 66 - is_key = false; 67 - continue; 68 - } 69 - 70 - if (*p == ',' || *p == '{' || *p == '[') { 71 - if (*p == '{' || *p == '[') { 72 - fprintf(stream, "%s%c%s", JSON_BRACE, *p, ANSI_RESET); 73 - } else { 74 - fputc(*p, stream); 75 - } 76 - is_key = (*p == ',' || *p == '{'); 77 - continue; 78 - } 79 - 80 - if (*p == '}' || *p == ']') { 81 - fprintf(stream, "%s%c%s", JSON_BRACE, *p, ANSI_RESET); 82 - continue; 83 - } 84 - 85 - if (strncmp(p, "true", 4) == 0) { 86 - fprintf(stream, "%strue%s", JSON_BOOL, ANSI_RESET); 87 - p += 3; 88 - continue; 89 - } 90 - 91 - if (strncmp(p, "false", 5) == 0) { 92 - fprintf(stream, "%sfalse%s", JSON_BOOL, ANSI_RESET); 93 - p += 4; 94 - continue; 95 - } 96 - 97 - if (strncmp(p, "null", 4) == 0) { 98 - fprintf(stream, "%snull%s", JSON_NULL, ANSI_RESET); 99 - p += 3; 100 - continue; 101 - } 102 - 103 - if ((*p >= '0' && *p <= '9') || *p == '-') { 104 - fprintf(stream, "%s", JSON_NUMBER); 105 - while ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+' || *p == 'e' || *p == 'E') { 106 - fputc(*p, stream); 107 - if (!(*(p + 1) >= '0' && *(p + 1) <= '9') && *(p + 1) != '.' && *(p + 1) != '-' && *(p + 1) != '+' && *(p + 1) != 'e' && *(p + 1) != 'E') break; 108 - p++; 109 - } 110 - fprintf(stream, "%s", ANSI_RESET); 111 - continue; 112 - } 113 - 114 - fputc(*p, stream); 115 - } 116 - } 117 - 118 25 void print_value_colored(const char *str, FILE *stream) { 119 26 bool in_string = false; 120 27 bool escape_next = false; ··· 237 144 continue; 238 145 } 239 146 240 - if (strncmp(p, "Infinity", 8) == 0) { 147 + if (strncmp(p, "Infinity", 8) == 0 && !is_key) { 241 148 fprintf(stream, "%sInfinity%s", JSON_NUMBER, ANSI_RESET); 242 149 p += 7; 243 150 continue; 244 151 } 245 152 246 - if (strncmp(p, "NaN", 3) == 0 && !isalnum((unsigned char)p[3]) && p[3] != '_') { 153 + if (strncmp(p, "NaN", 3) == 0 && !isalnum((unsigned char)p[3]) && p[3] != '_' && !is_key) { 247 154 fprintf(stream, "%sNaN%s", JSON_NUMBER, ANSI_RESET); 248 155 p += 2; 249 156 continue; ··· 288 195 fprintf(stream, "%s", str); 289 196 } else { 290 197 const char *str = js_str(js, args[i]); 291 - if (str[0] == '{' || str[0] == '[') { 292 - if (color) fprintf(stream, "%s", ANSI_RESET); 293 - print_json_colored(str, stream); 294 - if (color) fprintf(stream, "%s", color); 295 - } else print_value_colored(str, stdout); 198 + if (color) fprintf(stream, "%s", ANSI_RESET); 199 + print_value_colored(str, stream); 200 + if (color) fprintf(stream, "%s", color); 296 201 } 297 202 } 298 203