Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy_static replaced by std::sync::OnceLock #30

Merged
merged 8 commits into from
Sep 7, 2024
1 change: 0 additions & 1 deletion vm-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
wasm-bindgen-futures = "0.4.37"
js-sys = "0.3.64"
binary-reader = "0.4.5"
lazy_static = "1.4.0"
num = "0.4.1"
num-derive = "0.4.0"
num-traits = "0.2.16"
Expand Down
34 changes: 18 additions & 16 deletions vm-rust/src/director/chunks/handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use binary_reader::BinaryReader;
use fxhash::FxHashMap;

use crate::director::lingo::{constants::OPCODE_NAMES, opcode::OpCode, script::ScriptContext};
use crate::director::lingo::{constants::opcode_names, opcode::OpCode, script::ScriptContext};

#[allow(dead_code)]
pub struct HandlerRecord {
Expand Down Expand Up @@ -43,35 +43,35 @@ impl Bytecode {

let mut writer = String::new();
writer.push_str(&Self::pos_to_str(self.pos).as_str());
writer.push_str(" ");
writer.push_str(&opcode_name);
writer.push(' ');
writer.push_str(opcode_name);
match self.opcode {
OpCode::Jmp | OpCode::JmpIfZ => {
writer.push_str(" ");
writer.push(' ');
writer.push_str(&Self::pos_to_str(self.pos + self.obj as usize));
}
OpCode::EndRepeat => {
writer.push_str(" ");
writer.push(' ');
writer.push_str(&Self::pos_to_str(self.pos - self.obj as usize));
}
OpCode::ObjCall | OpCode::ExtCall | OpCode::GetObjProp | OpCode::SetObjProp | OpCode::PushSymb | OpCode::GetProp | OpCode::GetChainedProp => {
let name = lctx.names.get(self.obj as usize).unwrap();
writer.push_str(" ");
writer.push(' ');
writer.push_str(name);
}
OpCode::SetLocal | OpCode::GetLocal => {
let name_id = handler.local_name_ids.get(self.obj as usize).map(|x| *x as usize);
let name = name_id.and_then(|name_id| lctx.names.get(name_id).map(|x| x.as_str())).unwrap_or("UNKOWN_LOCAL");
writer.push_str(" ");
writer.push(' ');
writer.push_str(name);
}
OpCode::PushFloat32 => {
writer.push_str(" ");
writer.push(' ');
writer.push_str("[TODO pushfloat32]");
}
_ => {
if op_id > 0x40 {
writer.push_str(" ");
writer.push(' ');
writer.push_str(self.obj.to_string().as_str())
}
}
Expand All @@ -83,14 +83,16 @@ impl Bytecode {
}
}

pub fn get_opcode_name(id: u16) -> String {
let real_id = if id >= 0x40 {
0x40 + (id % 0x40)
pub fn get_opcode_name(mut id: u16) -> &'static str {
if id >= 0x40 {
id = 0x40 + (id % 0x40);
}

if let Some(r) = opcode_names().get(&OpCode::from(id)) {
r.as_ref()
} else {
id
};
let it = OPCODE_NAMES.get(&OpCode::from(real_id));
return it.unwrap_or(&"UNKOWN_BYTECODE".to_string()).to_owned()
"UNKOWN_BYTECODE"
}
}

#[derive(Clone)]
Expand Down
Loading