Skip to content

Commit

Permalink
add stop fn block
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Nov 15, 2023
1 parent 2d5f307 commit 85e625b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions src/test/blocks/stop-fn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<blocks app="NetsBlox 2.1.6, http://netsblox.org" version="2.1.6"><block-definition collabId="item_-1_2" s="main" type="reporter" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block collabId="item_1" s="doDeclareVariables"><list><l>res</l></list></block><block collabId="item_3" s="doSetVar"><l>res</l><block collabId="item_5" s="reportNewList"><list></list></block></block><block collabId="item_65" s="doAddToList"><custom-block collabId="item_67" s="thing %l %n %n"><block collabId="item_68" var="res"/><l>1</l><l>4</l></custom-block><block collabId="item_66" var="res"/></block><block collabId="item_71" s="doAddToList"><custom-block collabId="item_71_1" s="thing %l %n %n"><block collabId="item_71_3" var="res"/><l>2</l><l>2</l></custom-block><block collabId="item_71_2" var="res"/></block><block collabId="item_74" s="doAddToList"><custom-block collabId="item_74_1" s="thing %l %n %n"><block collabId="item_74_3" var="res"/><l>3</l><l>5</l></custom-block><block collabId="item_74_2" var="res"/></block><block collabId="item_77" s="doAddToList"><custom-block collabId="item_77_1" s="thing %l %n %n"><block collabId="item_77_3" var="res"/><l>4</l><l>3</l></custom-block><block collabId="item_77_2" var="res"/></block><block collabId="item_80" s="doReport"><block collabId="item_82" var="res"/></block></script></block-definition><block-definition collabId="item_38" s="thing %&apos;v&apos; %&apos;id&apos; %&apos;k&apos;" type="reporter" category="custom"><header></header><code></code><translations></translations><inputs><input type="%l"></input><input type="%n"></input><input type="%n"></input></inputs><script><block collabId="item_48" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_48_1" s="doAddToList"><block collabId="item_48_3" s="reportNewList"><list><block collabId="item_48_5" var="id"/><block collabId="item_48_6" var="i"/></list></block><block collabId="item_48_4" var="v"/></block><block collabId="item_48_2" s="doIf"><block collabId="item_48_7" s="reportEquals"><block collabId="item_48_9" var="i"/><block collabId="item_48_10" var="k"/></block><script><block collabId="item_48_8" s="doStopThis"><l><option>this block</option></l></block></script></block></script></block></script></block-definition></blocks>
35 changes: 35 additions & 0 deletions src/test/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]));
Expand Down

0 comments on commit 85e625b

Please sign in to comment.