use out of bounds exceptions

This commit is contained in:
Daniella / Tove 2023-03-06 15:11:29 +01:00
parent 954f817437
commit 1e68b5340c
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
3 changed files with 29 additions and 10 deletions

View file

@ -145,9 +145,10 @@ fn read_block(str_words: &[String], isfn: bool) -> Result<(Option<u32>, Words, u
types.push(str_words[i].to_owned());
i += 1;
}
let blk = read_block(&str_words[i..], false)?;
i += 2 + blk.2;
let ctch = read_block(&str_words[i..], false)?;
let blk = read_block(&str_words[i + 1..], false)?;
i += 1 + blk.2;
let ctch = read_block(&str_words[i + 1..], false)?;
i += 1 + ctch.2;
words.push(Word::Key(Keyword::Catch(types, blk.1, ctch.1)))
}
"with" => {

View file

@ -18,6 +18,12 @@ macro_rules! type_err {
};
}
macro_rules! array {
($stack:expr, $i:expr) => {
|| $stack.error(ErrorKind::PropertyNotFound("array".to_owned(), $i.to_string()))
};
}
pub fn print(stack: &mut Stack) -> OError {
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
return stack.err(ErrorKind::InvalidCall("print".to_owned()))
@ -113,7 +119,7 @@ pub fn array_get(stack: &mut Stack) -> OError {
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()))
};
stack.push(a[i as usize].clone());
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
Ok(())
}
@ -126,8 +132,8 @@ pub fn array_set(stack: &mut Stack) -> OError {
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()))
};
let o = stack.pop();
stack.push(a[i as usize].clone());
a[i as usize] = o;
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
*a.get_mut(i as usize).ok_or_else(array!(stack, i))? = o;
Ok(())
}

View file

@ -112,11 +112,23 @@ func main { int | with args ;
{ | println } (" " "hello how are you" _:split):foreach
"" println
catch {
use net:http:Request
"testing http" println
def req "tudbut.de" 81 "GET" "/" Request:new =req
req:send:body _str println
}
with { with e ;
e:message println
"it seems the internet is not available" println
}
"" println
catch {
"heya" throw
} with { with e ;
e:object println
}
100
}