use out of bounds exceptions
This commit is contained in:
parent
954f817437
commit
1e68b5340c
3 changed files with 29 additions and 10 deletions
|
@ -145,9 +145,10 @@ fn read_block(str_words: &[String], isfn: bool) -> Result<(Option<u32>, Words, u
|
||||||
types.push(str_words[i].to_owned());
|
types.push(str_words[i].to_owned());
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
let blk = read_block(&str_words[i..], false)?;
|
let blk = read_block(&str_words[i + 1..], false)?;
|
||||||
i += 2 + blk.2;
|
i += 1 + blk.2;
|
||||||
let ctch = read_block(&str_words[i..], false)?;
|
let ctch = read_block(&str_words[i + 1..], false)?;
|
||||||
|
i += 1 + ctch.2;
|
||||||
words.push(Word::Key(Keyword::Catch(types, blk.1, ctch.1)))
|
words.push(Word::Key(Keyword::Catch(types, blk.1, ctch.1)))
|
||||||
}
|
}
|
||||||
"with" => {
|
"with" => {
|
||||||
|
|
|
@ -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 {
|
pub fn print(stack: &mut Stack) -> OError {
|
||||||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("print".to_owned()))
|
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 {
|
let Value::Mega(i) = stack.pop().lock_ro().native.clone() else {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-get".to_owned()))
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +132,8 @@ pub fn array_set(stack: &mut Stack) -> OError {
|
||||||
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()))
|
return stack.err(ErrorKind::InvalidCall("array-set".to_owned()))
|
||||||
};
|
};
|
||||||
let o = stack.pop();
|
let o = stack.pop();
|
||||||
stack.push(a[i as usize].clone());
|
stack.push(a.get(i as usize).ok_or_else(array!(stack, i))?.clone());
|
||||||
a[i as usize] = o;
|
*a.get_mut(i as usize).ok_or_else(array!(stack, i))? = o;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
test.spl
12
test.spl
|
@ -112,11 +112,23 @@ func main { int | with args ;
|
||||||
{ | println } (" " "hello how are you" _:split):foreach
|
{ | println } (" " "hello how are you" _:split):foreach
|
||||||
"" println
|
"" println
|
||||||
|
|
||||||
|
catch {
|
||||||
use net:http:Request
|
use net:http:Request
|
||||||
"testing http" println
|
"testing http" println
|
||||||
def req "tudbut.de" 81 "GET" "/" Request:new =req
|
def req "tudbut.de" 81 "GET" "/" Request:new =req
|
||||||
req:send:body _str println
|
req:send:body _str println
|
||||||
|
}
|
||||||
|
with { with e ;
|
||||||
|
e:message println
|
||||||
|
"it seems the internet is not available" println
|
||||||
|
}
|
||||||
"" println
|
"" println
|
||||||
|
|
||||||
|
catch {
|
||||||
|
"heya" throw
|
||||||
|
} with { with e ;
|
||||||
|
e:object println
|
||||||
|
}
|
||||||
|
|
||||||
100
|
100
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue