From 3c641313cddc4a0baaba13443bc74ee4d344ae5a Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sun, 7 Jun 2026 19:35:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20throw=20=E6=9C=AA?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=9D=99=E9=BB=98=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_compiler/src/counter.rs | 3 +++ crates/oxide_compiler/src/emitter.rs | 1 + crates/oxide_compiler/src/hash.rs | 3 +++ crates/oxide_vm/tests/regression_tests.rs | 8 ++++++++ 4 files changed, 15 insertions(+) diff --git a/crates/oxide_compiler/src/counter.rs b/crates/oxide_compiler/src/counter.rs index 220b7af6..b5a0abde 100644 --- a/crates/oxide_compiler/src/counter.rs +++ b/crates/oxide_compiler/src/counter.rs @@ -195,6 +195,9 @@ impl Compiler { // FD emits LOAD_CONST(BytecodeFunc) + STORE_VAR ctx.projected_pc += 2; } + Statement::ThrowStatement(_) => { + // throw not yet implemented; emit pass will error + } _ => {} } } diff --git a/crates/oxide_compiler/src/emitter.rs b/crates/oxide_compiler/src/emitter.rs index 2a7b4e91..75688bd5 100644 --- a/crates/oxide_compiler/src/emitter.rs +++ b/crates/oxide_compiler/src/emitter.rs @@ -371,6 +371,7 @@ impl Compiler { Ok(None) } + Statement::ThrowStatement(_) => Err("throw statement not supported".into()), _ => Ok(None), } } diff --git a/crates/oxide_compiler/src/hash.rs b/crates/oxide_compiler/src/hash.rs index 71d1d6c4..421d00ba 100644 --- a/crates/oxide_compiler/src/hash.rs +++ b/crates/oxide_compiler/src/hash.rs @@ -116,6 +116,9 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) { } } } + Statement::ThrowStatement(_ts) => { + 14u8.hash(h); + } _ => { std::mem::discriminant(stmt).hash(h); } diff --git a/crates/oxide_vm/tests/regression_tests.rs b/crates/oxide_vm/tests/regression_tests.rs index 6414396b..82f031a2 100644 --- a/crates/oxide_vm/tests/regression_tests.rs +++ b/crates/oxide_vm/tests/regression_tests.rs @@ -56,3 +56,11 @@ fn regression_recursion_depth_limit() { "vm error: RangeError: Maximum call stack size exceeded" ); } + +#[test] +fn regression_throw_statement_errors() { + assert_eq!( + eval("throw 'error'"), + "compile error: throw statement not supported" + ); +}