Skip to content

Commit

Permalink
fix neg collab ids
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Sep 21, 2023
1 parent 163d6c0 commit e5eee59
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "netsblox-vm"
version = "0.2.7"
version = "0.2.8"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Devin Jean <[email protected]>"]
Expand Down
6 changes: 3 additions & 3 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ pub struct Locations {
#[allow(dead_code)] tag: MustBeU128<FINGERPRINT>,

prefix: String,
base_token: usize,
base_token: isize,
token_data: Vec<u8>,
locs: Vec<(usize, usize)>,
}
Expand Down Expand Up @@ -1165,7 +1165,7 @@ impl Locations {

let mut tokens = vec![];
for token in loc[prefix.len() + 1..].split('_') {
let v: usize = match token.parse() {
let v: isize = match token.parse() {
Ok(x) => x,
Err(_) => return Err(CompileError::InvalidLocation { loc }),
};
Expand Down Expand Up @@ -1223,7 +1223,7 @@ impl Locations {

start = aft;
res.push('_');
res.push_str(&(v as usize - 1 + self.base_token).to_string());
res.push_str(&(v as isize - 1 + self.base_token).to_string());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct Env<'gc, C: CustomTypes<StdSystem<C>>> {
type EnvArena<S> = Arena<Rootable![Env<'_, S>]>;

fn get_env<C: CustomTypes<StdSystem<C>>>(role: &ast::Role, system: Rc<StdSystem<C>>) -> Result<EnvArena<C>, FromAstError> {
let (bytecode, init_info, locs, _) = ByteCode::compile(role).unwrap();
let (bytecode, init_info, locs, _) = ByteCode::compile(role)?;
Ok(EnvArena::new(Default::default(), |mc| {
let proj = Project::from_init(mc, &init_info, Rc::new(bytecode), Settings::default(), system);
Env { proj: Gc::new(mc, RefLock::new(proj)), locs }
Expand Down
1 change: 1 addition & 0 deletions src/test/blocks/neg-collab-ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<blocks app="NetsBlox 1.33.3, http://netsblox.org" version="1.33.3"><block-definition collabId="item_2" s="main" type="command" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block collabId="item_4" s="doDeclareVariables"><list><l>test</l><l>trash</l></list></block><block collabId="item_-3" s="doSetVar"><l>test</l><block collabId="item_9" s="reportNumbers"><l>1</l><l>10</l></block></block><block collabId="item_15" s="doSetVar"><l>trash</l><block collabId="item_15_1" s="reportListItem"><l>9</l><block collabId="item_-15_2" var="test"/></block></block><block collabId="item_18" s="doSetVar"><l>trash</l><block collabId="item_18_-2" s="reportListItem"><l>10</l><block collabId="item_18_3" var="test"/></block></block><block collabId="item_18_1" s="doSetVar"><l>trash</l><block collabId="item_-18_4" s="reportListItem"><l>11</l><block collabId="item_18_5" var="test"/></block></block><block collabId="item_10" s="doSetVar"><l>trash</l><block collabId="item_12" s="reportListItem"><l>12</l><block collabId="item_-13" var="test"/></block></block><block collabId="item_21" s="doSetVar"><l>trash</l><block collabId="item_21_-101" s="reportListItem"><l>13</l><block collabId="item_21_2" var="test"/></block></block></script></block-definition></blocks>
23 changes: 23 additions & 0 deletions src/test/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,29 @@ fn test_proc_index_over_bounds() {
});
}

#[test]
fn test_proc_neg_collab_ids() {
let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, Config::default(), UtcOffset::UTC));
let (mut env, ins_locs) = get_running_proc(&format!(include_str!("templates/generic-static.xml"),
globals = "",
fields = "",
funcs = include_str!("blocks/neg-collab-ids.xml"),
methods = "",
), Settings::default(), system);

run_till_term(&mut env, |_, _, res| {
let res = res.unwrap_err();
match &res.cause {
ErrorCause::IndexOutOfBounds { index, len } => {
assert_eq!(*index, 11);
assert_eq!(*len, 10);
}
x => panic!("{x:?}"),
}
assert_eq!(ins_locs.lookup(res.pos).as_deref().unwrap(), "item_-18_4");
});
}

#[test]
fn test_proc_basic_motion() {
#[derive(PartialEq, Eq, Debug)]
Expand Down

0 comments on commit e5eee59

Please sign in to comment.