diff --git a/source/quickjs.c b/source/quickjs.c index b9962661..9f5e897c 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -554,8 +554,6 @@ typedef enum MachOpcode { MACH_NEWARRAY, /* R(A) = new array, B = element count in R(A+1)..R(A+B) */ MACH_CLOSURE, /* R(A) = closure(functions[Bx]) (ABx) */ - /* Special */ - MACH_TYPEOF, /* R(A) = typeof R(B) */ MACH_THROW, /* disrupt — trigger disruption */ MACH_NOP, @@ -612,8 +610,7 @@ static const char *mach_opcode_names[MACH_OP_COUNT] = { [MACH_NEWOBJECT] = "newobject", [MACH_NEWARRAY] = "newarray", [MACH_CLOSURE] = "closure", - [MACH_TYPEOF] = "typeof", - [MACH_THROW] = "disrupt", + [MACH_THROW] = "throw", [MACH_NOP] = "nop", }; @@ -31131,16 +31128,6 @@ static int mach_compile_expr(MachCompState *cs, cJSON *node, int dest) { mach_free_reg_to(cs, save); return dest; } - if (strcmp(kind, "typeof") == 0) { - if (dest < 0) dest = mach_reserve_reg(cs); - cJSON *operand = cJSON_GetObjectItem(node, "expression"); - if (!operand) operand = cJSON_GetObjectItem(node, "right"); - int save = cs->freereg; - int r = mach_compile_expr(cs, operand, -1); - mach_emit(cs, MACH_ABC(MACH_TYPEOF, dest, r, 0)); - mach_free_reg_to(cs, save); - return dest; - } /* Assignment */ if (strcmp(kind, "=") == 0) { @@ -32219,21 +32206,6 @@ static JSValue JS_CallRegisterVM(JSContext *ctx, JSCodeRegister *code, break; } - case MACH_TYPEOF: { - JSValue v = frame->slots[b]; - const char *type_str; - if (JS_IsNull(v)) type_str = "object"; - else if (JS_IsBool(v)) type_str = "boolean"; - else if (JS_IsInt(v) || JS_IsNumber(v)) type_str = "number"; - else if (JS_VALUE_IS_TEXT(v)) type_str = "string"; - else if (JS_IsFunction(v)) type_str = "function"; - else type_str = "object"; - JSValue ts = JS_NewString(ctx, type_str); - frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val); - frame->slots[a] = ts; - break; - } - case MACH_GETFIELD: { JSValue obj = frame->slots[b]; JSValue key = code->cpool[c]; @@ -35103,7 +35075,6 @@ static void dump_register_code(JSContext *ctx, JSCodeRegister *code, int indent) case MACH_DEC: case MACH_LNOT: case MACH_BNOT: - case MACH_TYPEOF: printf("r%d, r%d", a, b); break; diff --git a/tests/demo.ce b/tests/demo.ce new file mode 100644 index 00000000..90c55a40 --- /dev/null +++ b/tests/demo.ce @@ -0,0 +1,39 @@ +function safe_add(a, b) { + return a + b +} disruption { + print("disruption caught in safe_add") +} + +function inner() { + disrupt +} + +function outer() { + inner() +} disruption { + print("disruption caught in outer — from inner()") +} + +// Test 1: explicit disrupt with handler +function test_explicit() { + disrupt +} disruption { + print("test 1: explicit disrupt handled") +} +test_explicit() + +// Test 2: type error disrupt (number + function) +safe_add(1, print) + +// Test 3: unwinding — inner disrupts, outer catches +outer() + +// Test 4: disrupt from inside disruption clause +function test_nested() { + disrupt +} disruption { + print("test 4: first disruption") +} +test_nested() + +print("done")