Skip to content

Commit

Permalink
Fix 0-args return; fix idle_seconds builtin.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Jul 23, 2023
1 parent a91adec commit 9720768
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
9 changes: 8 additions & 1 deletion moor-lib/src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl CodegenState {
self.pop_stack(1);
}
None => {
self.emit(Op::Return);
self.emit(Op::Return0);
}
},
Stmt::Expr(e) => {
Expand Down Expand Up @@ -2150,4 +2150,11 @@ mod tests {
]
)
}

#[test]
fn test_0_arg_return() {
let program = r#"return;"#;
let binary = compile(program).unwrap();
assert_eq!(binary.main_vector, vec![Return0, Done])
}
}
4 changes: 2 additions & 2 deletions moor-lib/src/var/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Var {
};

match l.iter().position(|x| x == v) {
None => v_int(0),
None => v_int(0),
Some(i) => v_int(i as i64 + 1),
}
}
Expand Down Expand Up @@ -425,7 +425,7 @@ impl Var {
if to < from {
return Ok(v_list(Vec::new()));
}
if from <= 0 || from > len + 1 || to < 1 || to > len {
if from <= 0 || from > len + 1 || to < 1 || to > len {
return Ok(v_err(E_RANGE));
}
let mut res = Vec::with_capacity((to - from + 1) as usize);
Expand Down
2 changes: 1 addition & 1 deletion moor-lib/src/vm/bf_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async fn bf_idle_seconds(
_sess: Arc<RwLock<dyn Sessions>>,
args: &[Var],
) -> Result<Var, anyhow::Error> {
if !args.is_empty() {
if args.len() != 1 {
return Ok(v_err(E_INVARG));
}

Expand Down
17 changes: 8 additions & 9 deletions moor-lib/src/vm/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,11 @@ impl VM {
// above)
if let FinallyReason::Return(value) = why {
self.push(&value);
trace!("Unwinding stack, pushing return value: {} back to verb {}",
value, self.top().verb_name());
trace!(
"Unwinding stack, pushing return value: {} back to verb {}",
value,
self.top().verb_name()
);
return Ok(ExecutionResult::More);
}
}
Expand Down Expand Up @@ -918,12 +921,10 @@ impl VM {
(Variant::Int(to), Variant::Int(from)) => {
// MOO is 1-indexed. Adjust.
match base.range(*from, *to) {
Err(e) => {
return self.push_error(e)
},
Err(e) => return self.push_error(e),
Ok(v) => self.push(&v),
}
},
}
(_, _) => return self.push_error(E_TYPE),
};
}
Expand All @@ -932,9 +933,7 @@ impl VM {
match (to.variant(), from.variant()) {
(Variant::Int(to), Variant::Int(from)) => {
match base.rangeset(value, *from, *to) {
Err(e) => {
return self.push_error(e)
},
Err(e) => return self.push_error(e),
Ok(v) => self.push(&v),
}
}
Expand Down

0 comments on commit 9720768

Please sign in to comment.