From 85e625b32c1aa7c2af63049d3f44df6b05d61b73 Mon Sep 17 00:00:00 2001 From: Devin Jean Date: Tue, 14 Nov 2023 23:18:57 -0600 Subject: [PATCH] add stop fn block --- src/bytecode.rs | 4 ++++ src/test/blocks/stop-fn.xml | 1 + src/test/process.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/test/blocks/stop-fn.xml diff --git a/src/bytecode.rs b/src/bytecode.rs index 46a0840..e95a951 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -1712,6 +1712,10 @@ impl<'a: 'b, 'b> ByteCodeBuilder<'a, 'b> { ast::StmtKind::NextCostume => self.ins.push(Instruction::NextCostume.into()), ast::StmtKind::PenClear => self.ins.push(Instruction::ClearDrawings.into()), ast::StmtKind::Stop { mode: ast::StopMode::ThisScript } => self.ins.push(Instruction::Abort { mode: AbortMode::Current }.into()), + ast::StmtKind::Stop { mode: ast::StopMode::ThisBlock } => { + self.ins.push(Instruction::PushString { value: "" }.into()); + self.ins.push(Instruction::Return.into()); + } ast::StmtKind::SetCostume { costume } => match costume { Some(x) => self.append_simple_ins(entity, &[x], Instruction::SetCostume)?, None => { diff --git a/src/test/blocks/stop-fn.xml b/src/test/blocks/stop-fn.xml new file mode 100644 index 0000000..425766f --- /dev/null +++ b/src/test/blocks/stop-fn.xml @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/src/test/process.rs b/src/test/process.rs index 411f6df..2e95e39 100644 --- a/src/test/process.rs +++ b/src/test/process.rs @@ -2275,6 +2275,41 @@ fn test_proc_extra_cmp_tests() { }); } +#[test] +fn test_proc_stop_fn() { + let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, Config::default(), Arc::new(Clock::new(UtcOffset::UTC, None)))); + let (mut env, _) = get_running_proc(&format!(include_str!("templates/generic-static.xml"), + globals = "", + fields = "", + funcs = include_str!("blocks/stop-fn.xml"), + methods = "", + ), Settings { rpc_error_scheme: ErrorScheme::Soft, ..Default::default() }, system, |_| SymbolTable::default()); + + run_till_term(&mut env, |mc, _, res| { + let expect = Value::from_simple(mc, SimpleValue::from_json(json!([ + ["1", 1], + ["1", 2], + ["1", 3], + ["1", 4], + "", + ["2", 1], + ["2", 2], + "", + ["3", 1], + ["3", 2], + ["3", 3], + ["3", 4], + ["3", 5], + "", + ["4", 1], + ["4", 2], + ["4", 3], + "", + ])).unwrap()); + assert_values_eq(&res.unwrap().0, &expect, 1e-5, "stop fn"); + }); +} + #[test] fn test_proc_extra_blocks() { let actions = Rc::new(RefCell::new(vec![]));