hm-asm-web should not panic if it receives invalid asm code
This commit is contained in:
@@ -9,9 +9,10 @@ use hm_asm_simulator::{
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simulate(code: &str, cycles: usize) -> JsValue {
|
||||
let instructions = parse_asm(
|
||||
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
|
||||
);
|
||||
let instructions = parse_asm(match AsmParser::parse(Rule::program, &code) {
|
||||
Ok(instructions) => instructions,
|
||||
Err(e) => return JsValue::from_str(&format!("{}", e))
|
||||
});
|
||||
let states = hm_asm_simulator::simulate::simulate(instructions, cycles);
|
||||
|
||||
JsValue::from_serde(&states).unwrap()
|
||||
@@ -20,9 +21,12 @@ pub fn simulate(code: &str, cycles: usize) -> JsValue {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn assemble(code: &str) -> JsValue {
|
||||
let instructions = parse_asm(
|
||||
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
|
||||
);
|
||||
let instructions = parse_asm(match AsmParser::parse(Rule::program, &code) {
|
||||
Ok(instructions) => instructions,
|
||||
Err(e) => return JsValue::from_str(&format!("{}", e))
|
||||
});
|
||||
|
||||
|
||||
let binary = generate_binary(instructions);
|
||||
JsValue::from_serde(&binary).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user