rm new; rm void

This commit is contained in:
2026-02-06 02:12:19 -06:00
parent bead0c48d4
commit c814c0e1d8
2 changed files with 1 additions and 100 deletions

View File

@@ -8529,8 +8529,6 @@ enum {
TOK_DEF,
TOK_THIS,
TOK_DELETE,
TOK_VOID,
TOK_NEW,
TOK_IN,
TOK_DO,
TOK_WHILE,
@@ -8640,8 +8638,6 @@ static const char *ast_token_kind_str(int token_val) {
case TOK_DEF: return "def";
case TOK_THIS: return "this";
case TOK_DELETE: return "delete";
case TOK_VOID: return "void";
case TOK_NEW: return "new";
case TOK_IN: return "in";
case TOK_DO: return "do";
case TOK_WHILE: return "while";
@@ -9799,8 +9795,6 @@ static const JSKeywordEntry js_keywords[] = {
{ "def", TOK_DEF, FALSE },
{ "this", TOK_THIS, FALSE },
{ "delete", TOK_DELETE, FALSE },
{ "void", TOK_VOID, FALSE },
{ "new", TOK_NEW, FALSE },
{ "in", TOK_IN, FALSE },
{ "do", TOK_DO, FALSE },
{ "while", TOK_WHILE, FALSE },
@@ -12443,8 +12437,6 @@ static __exception int js_parse_postfix_expr (JSParseState *s,
if (js_parse_array_literal (s)) return -1;
}
break;
case TOK_NEW:
return js_parse_error (s, "'new' keyword is not supported");
default:
return js_parse_error (s, "unexpected token in expression: '%.*s'", (int)(s->buf_ptr - s->token.ptr), s->token.ptr);
}
@@ -16663,7 +16655,6 @@ static __exception int js_parse_directives (JSParseState *s) {
case TOK_VAR:
case TOK_THIS:
case TOK_DELETE:
case TOK_NEW:
case TOK_DO:
case TOK_WHILE:
case TOK_FOR:
@@ -28239,13 +28230,11 @@ redo:
else if (len == 3 && !memcmp (start, "var", 3)) s->token_val = TOK_VAR;
else if (len == 3 && !memcmp (start, "def", 3)) s->token_val = TOK_DEF;
else if (len == 3 && !memcmp (start, "for", 3)) s->token_val = TOK_FOR;
else if (len == 3 && !memcmp (start, "new", 3)) s->token_val = TOK_NEW;
else if (len == 3 && !memcmp (start, "try", 3)) s->token_val = TOK_TRY;
else if (len == 4 && !memcmp (start, "else", 4)) s->token_val = TOK_ELSE;
else if (len == 4 && !memcmp (start, "this", 4)) s->token_val = TOK_THIS;
else if (len == 4 && !memcmp (start, "null", 4)) s->token_val = TOK_NULL;
else if (len == 4 && !memcmp (start, "true", 4)) s->token_val = TOK_TRUE;
else if (len == 4 && !memcmp (start, "void", 4)) s->token_val = TOK_VOID;
else if (len == 4 && !memcmp (start, "case", 4)) s->token_val = TOK_CASE;
else if (len == 5 && !memcmp (start, "false", 5)) s->token_val = TOK_FALSE;
else if (len == 5 && !memcmp (start, "while", 5)) s->token_val = TOK_WHILE;
@@ -28567,13 +28556,11 @@ static int tokenize_next (ASTParseState *s) {
else if (len == 3 && !memcmp (start, "var", 3)) s->token_val = TOK_VAR;
else if (len == 3 && !memcmp (start, "def", 3)) s->token_val = TOK_DEF;
else if (len == 3 && !memcmp (start, "for", 3)) s->token_val = TOK_FOR;
else if (len == 3 && !memcmp (start, "new", 3)) s->token_val = TOK_NEW;
else if (len == 3 && !memcmp (start, "try", 3)) s->token_val = TOK_TRY;
else if (len == 4 && !memcmp (start, "else", 4)) s->token_val = TOK_ELSE;
else if (len == 4 && !memcmp (start, "this", 4)) s->token_val = TOK_THIS;
else if (len == 4 && !memcmp (start, "null", 4)) s->token_val = TOK_NULL;
else if (len == 4 && !memcmp (start, "true", 4)) s->token_val = TOK_TRUE;
else if (len == 4 && !memcmp (start, "void", 4)) s->token_val = TOK_VOID;
else if (len == 4 && !memcmp (start, "case", 4)) s->token_val = TOK_CASE;
else if (len == 5 && !memcmp (start, "false", 5)) s->token_val = TOK_FALSE;
else if (len == 5 && !memcmp (start, "while", 5)) s->token_val = TOK_WHILE;
@@ -29254,34 +29241,6 @@ static cJSON *ast_parse_unary (ASTParseState *s) {
ast_node_end (s, node, s->buf_ptr);
return node;
}
case TOK_VOID: {
ast_next_token (s);
cJSON *node = ast_node (s, "void", start);
cJSON *expr = ast_parse_unary (s);
cJSON_AddItemToObject (node, "expression", expr);
ast_node_end (s, node, s->buf_ptr);
return node;
}
case TOK_NEW: {
ast_next_token (s);
cJSON *node = ast_node (s, "new", start);
cJSON *expr = ast_parse_postfix (s);
cJSON_AddItemToObject (node, "expression", expr);
/* If followed by (, parse arguments */
if (s->token_val == '(') {
ast_next_token (s);
cJSON *list = cJSON_AddArrayToObject (node, "list");
while (s->token_val != ')' && s->token_val != TOK_EOF) {
cJSON *arg = ast_parse_assign_expr (s);
if (arg) cJSON_AddItemToArray (list, arg);
if (s->token_val == ',') ast_next_token (s);
else break;
}
if (s->token_val == ')') ast_next_token (s);
}
ast_node_end (s, node, s->buf_ptr);
return node;
}
default:
return ast_parse_postfix (s);
}
@@ -30284,23 +30243,13 @@ static void ast_sem_check_expr (ASTSemState *st, ASTSemScope *scope, cJSON *expr
/* Unary ops */
if (strcmp (kind, "!") == 0 || strcmp (kind, "~") == 0 ||
strcmp (kind, "typeof") == 0 || strcmp (kind, "void") == 0 ||
strcmp (kind, "typeof") == 0 ||
strcmp (kind, "delete") == 0 || strcmp (kind, "neg") == 0 ||
strcmp (kind, "pos") == 0 || strcmp (kind, "spread") == 0) {
ast_sem_check_expr (st, scope, cJSON_GetObjectItem (expr, "expression"));
return;
}
/* new expression */
if (strcmp (kind, "new") == 0) {
ast_sem_check_expr (st, scope, cJSON_GetObjectItem (expr, "expression"));
cJSON *arg;
cJSON_ArrayForEach (arg, cJSON_GetObjectItem (expr, "list")) {
ast_sem_check_expr (st, scope, arg);
}
return;
}
/* Array literal */
if (strcmp (kind, "array") == 0) {
cJSON *el;
@@ -31754,15 +31703,6 @@ static int mach_gen_expr (MachGenState *s, cJSON *expr) {
return slot;
}
/* Void operator */
if (strcmp (kind, "void") == 0) {
cJSON *operand = cJSON_GetObjectItem (expr, "expression");
mach_gen_expr (s, operand);
int slot = mach_alloc_slot (s);
mach_emit_const_null (s, slot);
return slot;
}
/* Ternary */
if (strcmp (kind, "then") == 0) {
cJSON *cond = cJSON_GetObjectItem (expr, "expression");
@@ -31870,39 +31810,6 @@ static int mach_gen_expr (MachGenState *s, cJSON *expr) {
return dest;
}
/* New expression */
if (strcmp (kind, "new") == 0) {
cJSON *callee = cJSON_GetObjectItem (expr, "expression");
cJSON *args_list = cJSON_GetObjectItem (expr, "list");
int func_slot = mach_gen_expr (s, callee);
cJSON *arg_slots = cJSON_CreateArray ();
int argc = 0;
if (args_list) {
cJSON *arg;
cJSON_ArrayForEach (arg, args_list) {
int slot = mach_gen_expr (s, arg);
cJSON_AddItemToArray (arg_slots, cJSON_CreateNumber (slot));
argc++;
}
}
int dest = mach_alloc_slot (s);
cJSON *instr = cJSON_CreateArray ();
cJSON_AddItemToArray (instr, cJSON_CreateString ("new"));
cJSON_AddItemToArray (instr, cJSON_CreateNumber (dest));
cJSON_AddItemToArray (instr, cJSON_CreateNumber (func_slot));
cJSON_AddItemToArray (instr, cJSON_CreateNumber (argc));
cJSON *el;
cJSON_ArrayForEach (el, arg_slots) {
cJSON_AddItemToArray (instr, cJSON_CreateNumber (el->valueint));
}
cJSON_AddItemToArray (s->instructions, instr);
cJSON_Delete (arg_slots);
return dest;
}
/* Assignment operators */
if (strcmp (kind, "assign") == 0 ||
strcmp (kind, "+=") == 0 || strcmp (kind, "-=") == 0 ||

View File

@@ -300,9 +300,6 @@ delete del_obj.a
// --- in operator ---
var in_result = "b" in del_obj
// --- new expression ---
var new_obj = new Object()
// --- go statement ---
function async_task() { return 1 }
function caller() { go async_task() }
@@ -359,8 +356,5 @@ var prec_chain = 1 + 2 * 3 ** 2 - 4 / 2 % 3
var re = /hello/
var re_flags = /world/gi
// --- void operator ---
var v = void 0
// --- line comment at end ---
var end = 1 // done