Skip to content

Commit

Permalink
rename some to_* methods to as_*
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Oct 16, 2023
1 parent f4f4bb1 commit 2d16fce
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 141 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.12"
version = "0.2.13"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Devin Jean <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ impl BinaryWrite for Instruction<'_> {
/// Generated [`ByteCode`] is highly optimized for size and sees frequent breaking changes.
/// Because of this, there is currently no support for touching the actual bytecode itself.
/// If you wish to view the generated bytecode, you may use the [`ByteCode::dump_code`] and [`ByteCode::dump_data`] utilities,
/// a wrapper for which is included in the standard `netsblox-vm` [`cli`](crate::cli).
/// a wrapper for which is included in the standard `netsblox-vm` [`cli`].
///
/// This type supports serde serialization if the `serde` feature flag is enabled.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() {
Request::Syscall { name, args } => match name.as_str() {
"open" => {
let (path, mode) = match args.as_slice() {
[path, mode] => match (path.to_string(), mode.to_string()) {
[path, mode] => match (path.as_string(), mode.as_string()) {
(Ok(path), Ok(mode)) => (path, mode),
_ => {
key.complete(Err(format!("syscall open - expected 2 string args, received {:?} and {:?}", path.get_type(), mode.get_type())));
Expand Down Expand Up @@ -201,8 +201,8 @@ fn main() {
}
}
"writeLine" => match args.as_slice() {
[file, content] => match (file, content.to_string()) {
(Value::Native(x), Ok(content)) => match &**x {
[file, content] => match file {
Value::Native(x) => match &**x {
NativeValue::OutputFile { handle } => match handle.borrow_mut().as_mut() {
Some(handle) => match writeln!(*handle, "{content}") {
Ok(_) => {
Expand Down
118 changes: 59 additions & 59 deletions src/process.rs

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions src/runtime.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/std_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<C: CustomTypes<StdSystem<C>>> Key<Result<C::Intermediate, String>> for Requ
/// A value of [`Ok`] denotes a successful request, whose value will be returned to the system
/// after conversion under [`CustomTypes::from_intermediate`].
/// A value of [`Err`] denotes a failed request, which will be returned as an error to the runtime,
/// subject to the caller's [`ErrorScheme`](crate::runtime::ErrorScheme) setting.
/// subject to the caller's [`ErrorScheme`] setting.
fn complete(self, value: Result<C::Intermediate, String>) {
assert!(self.0.lock().unwrap().complete(value).is_ok())
}
Expand All @@ -91,7 +91,7 @@ impl Key<Result<(), String>> for CommandKey {
/// Completes the command.
/// A value of [`Ok`] denotes a successful command.
/// A value of [`Err`] denotes a failed command, which will be returned as an error to the runtime,
/// subject to the caller's [`ErrorScheme`](crate::runtime::ErrorScheme) setting.
/// subject to the caller's [`ErrorScheme`] setting.
fn complete(self, value: Result<(), String>) {
assert!(self.0.lock().unwrap().complete(value).is_ok())
}
Expand Down
34 changes: 17 additions & 17 deletions src/test/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ fn test_proc_syscall() {
false => {
let mut buffer = buffer_cpy.borrow_mut();
for value in args {
buffer.push_str(value.to_string().unwrap().as_ref());
buffer.push_str(value.as_string().unwrap().as_ref());
}
key.complete(Ok(Intermediate::from_json(json!(buffer.len() as f64))));
RequestStatus::Handled
Expand Down Expand Up @@ -1789,7 +1789,7 @@ fn test_proc_basic_motion() {
Some(Rc::new(move |_, _, key, command, _| {
match command {
Command::Forward { distance } => sequence.borrow_mut().push(Action::Forward(to_i32(distance))),
Command::ChangeProperty { prop: Property::Heading, delta } => sequence.borrow_mut().push(Action::Turn(to_i32(delta.to_number().unwrap()))),
Command::ChangeProperty { prop: Property::Heading, delta } => sequence.borrow_mut().push(Action::Turn(to_i32(delta.as_number().unwrap()))),
_ => return CommandStatus::UseDefault { key, command },
}
key.complete(Ok(()));
Expand Down Expand Up @@ -1948,7 +1948,7 @@ fn test_proc_rand_str_char_cache() {
), Settings::default(), system);

run_till_term(&mut env, |_, _, res| {
let res = res.unwrap().0.unwrap().to_string().unwrap().into_owned();
let res = res.unwrap().0.unwrap().as_string().unwrap().into_owned();
assert_eq!(res.len(), 8192);
let mut counts: BTreeMap<char, usize> = BTreeMap::new();
for ch in res.chars() {
Expand Down Expand Up @@ -2090,14 +2090,14 @@ fn test_proc_wall_time() {
let res = res.borrow();
assert_eq!(res.len(), 8);

assert!((res[0].to_number().unwrap().get() - (t.unix_timestamp_nanos() / 1000000) as f64).abs() < 10.0);
assert_eq!(res[1].to_number().unwrap().get(), t.year() as f64);
assert_eq!(res[2].to_number().unwrap().get(), t.month() as u8 as f64);
assert_eq!(res[3].to_number().unwrap().get(), t.day() as f64);
assert_eq!(res[4].to_number().unwrap().get(), t.date().weekday().number_from_sunday() as f64);
assert_eq!(res[5].to_number().unwrap().get(), t.hour() as f64);
assert_eq!(res[6].to_number().unwrap().get(), t.minute() as f64);
assert_eq!(res[7].to_number().unwrap().get(), t.second() as f64);
assert!((res[0].as_number().unwrap().get() - (t.unix_timestamp_nanos() / 1000000) as f64).abs() < 10.0);
assert_eq!(res[1].as_number().unwrap().get(), t.year() as f64);
assert_eq!(res[2].as_number().unwrap().get(), t.month() as u8 as f64);
assert_eq!(res[3].as_number().unwrap().get(), t.day() as f64);
assert_eq!(res[4].as_number().unwrap().get(), t.date().weekday().number_from_sunday() as f64);
assert_eq!(res[5].as_number().unwrap().get(), t.hour() as f64);
assert_eq!(res[6].as_number().unwrap().get(), t.minute() as f64);
assert_eq!(res[7].as_number().unwrap().get(), t.second() as f64);
});
}

Expand Down Expand Up @@ -2205,39 +2205,39 @@ fn test_proc_extra_blocks() {
match name.as_str() {
"tuneScopeSetInstrument" => {
assert_eq!(args.len(), 1);
let ins = args[0].to_string().unwrap();
let ins = args[0].as_string().unwrap();
actions_clone.borrow_mut().push(vec!["set ins".to_owned(), ins.into_owned()]);
key.complete(Ok(Intermediate::from_json(json!("OK"))));
}
"tuneScopeSetVolume" => {
assert_eq!(args.len(), 1);
let vol = args[0].to_number().unwrap().get();
let vol = args[0].as_number().unwrap().get();
actions_clone.borrow_mut().push(vec!["set vol".to_owned(), vol.to_string()]);
key.complete(Ok(Intermediate::from_json(json!("OK"))));
}
"tuneScopePlayChordForDuration" => {
assert_eq!(args.len(), 2);
let notes = args[0].to_json().unwrap();
let duration = args[1].to_string().unwrap();
let duration = args[1].as_string().unwrap();
actions_clone.borrow_mut().push(vec!["play chord".to_owned(), notes.to_string(), duration.into_owned()]);
key.complete(Ok(Intermediate::from_json(json!("OK"))));
}
"tuneScopePlayTracks" => {
assert_eq!(args.len(), 2);
let time = args[0].to_string().unwrap();
let time = args[0].as_string().unwrap();
let tracks = args[1].to_json().unwrap();
actions_clone.borrow_mut().push(vec!["play tracks".to_owned(), time.into_owned(), tracks.to_string()]);
key.complete(Ok(Intermediate::from_json(json!("OK"))));
}
"tuneScopeNote" => {
assert_eq!(args.len(), 1);
let note = args[0].to_string().unwrap();
let note = args[0].as_string().unwrap();
actions_clone.borrow_mut().push(vec!["get note".to_owned(), note.as_ref().to_owned()]);
key.complete(Ok(Intermediate::from_json(json!(format!("nte {note}")))));
}
"tuneScopeDuration" => {
assert_eq!(args.len(), 1);
let duration = args[0].to_string().unwrap();
let duration = args[0].as_string().unwrap();
actions_clone.borrow_mut().push(vec!["get duration".to_owned(), duration.as_ref().to_owned()]);
key.complete(Ok(Intermediate::from_json(json!(format!("drt {duration}")))));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ fn test_proj_parallel_rpcs() {

assert_eq!(global_context.globals.lookup("input").unwrap().get().as_list().unwrap().borrow().len(), 0);

let meta: Vec<_> = global_context.globals.lookup("meta").unwrap().get().as_list().unwrap().borrow().iter().map(|x| x.to_number().unwrap()).collect();
let meta: Vec<_> = global_context.globals.lookup("meta").unwrap().get().as_list().unwrap().borrow().iter().map(|x| x.as_number().unwrap()).collect();
if meta.len() != 4 || meta.iter().map(|x| x.get()).sum::<f64>() != 216.0 || !meta.iter().all(|&x| x.get() >= 30.0) {
panic!("{meta:?}");
}

let mut output: Vec<_> = global_context.globals.lookup("output").unwrap().get().as_list().unwrap().borrow().iter().map(|row| {
let vals: Vec<_> = row.as_list().unwrap().borrow().iter().map(|x| {
let v = x.to_number().unwrap().get();
let v = x.as_number().unwrap().get();
assert_eq!(v as i64 as f64, v);
v as i64
}).collect();
Expand Down

0 comments on commit 2d16fce

Please sign in to comment.