1
0

Pass all tests

This commit is contained in:
Jeff 2024-03-24 15:47:23 -04:00
parent 966983920e
commit 2871fd125a
5 changed files with 27 additions and 16 deletions

View File

@ -113,7 +113,18 @@ impl Type {
return_type: right_return,
},
) => {
if left_return == right_return && left_parameters == right_parameters {
if left_return.node == right_return.node {
for (left_parameter, right_parameter) in
left_parameters.iter().zip(right_parameters.iter())
{
if left_parameter.node != right_parameter.node {
return Err(TypeConflict {
actual: other.clone(),
expected: self.clone(),
});
}
}
return Ok(());
}
}

View File

@ -19,7 +19,8 @@ pub use value::Value;
pub fn interpret<'src>(source_id: &str, source: &str) -> Result<Option<Value>, InterpreterError> {
let mut interpreter = Interpreter::new(Context::new());
interpreter.run(Rc::new(source_id.to_string()), Rc::from(source))
interpreter.load_std()?;
interpreter.run(Rc::from(source_id), Rc::from(source))
}
pub fn interpret_without_std(
@ -28,12 +29,12 @@ pub fn interpret_without_std(
) -> Result<Option<Value>, InterpreterError> {
let mut interpreter = Interpreter::new(Context::new());
interpreter.run(Rc::new(source_id.to_string()), Rc::from(source))
interpreter.run(Rc::from(source_id.to_string()), Rc::from(source))
}
pub struct Interpreter {
context: Context,
sources: Rc<RefCell<Vec<(Rc<String>, Rc<str>)>>>,
sources: Rc<RefCell<Vec<(Rc<str>, Rc<str>)>>>,
}
impl Interpreter {
@ -46,7 +47,7 @@ impl Interpreter {
pub fn run(
&mut self,
source_id: Rc<String>,
source_id: Rc<str>,
source: Rc<str>,
) -> Result<Option<Value>, InterpreterError> {
let tokens = lex(source.as_ref()).map_err(|errors| InterpreterError {
@ -69,7 +70,7 @@ impl Interpreter {
Ok(value_option)
}
pub fn run_all<T: IntoIterator<Item = (Rc<String>, Rc<str>)>>(
pub fn run_all<T: IntoIterator<Item = (Rc<str>, Rc<str>)>>(
&mut self,
sources: T,
) -> Result<Option<Value>, InterpreterError> {
@ -85,24 +86,24 @@ impl Interpreter {
pub fn load_std(&mut self) -> Result<Option<Value>, InterpreterError> {
self.run_all([
(
Rc::new("std/io.ds".to_string()),
Rc::from("std/io.ds"),
Rc::from(include_str!("../../std/io.ds")),
),
(
Rc::new("std/thread.ds".to_string()),
Rc::from("std/thread.ds"),
Rc::from(include_str!("../../std/thread.ds")),
),
])
}
pub fn sources(&self) -> vec::IntoIter<(Rc<String>, Rc<str>)> {
pub fn sources(&self) -> vec::IntoIter<(Rc<str>, Rc<str>)> {
self.sources.borrow().clone().into_iter()
}
}
#[derive(Debug, PartialEq)]
pub struct InterpreterError {
source_id: Rc<String>,
source_id: Rc<str>,
errors: Vec<Error>,
}
@ -113,7 +114,7 @@ impl InterpreterError {
}
impl InterpreterError {
pub fn build_reports<'a>(self) -> Vec<Report<'a, (Rc<String>, Range<usize>)>> {
pub fn build_reports<'a>(self) -> Vec<Report<'a, (Rc<str>, Range<usize>)>> {
let mut reports = Vec::new();
for error in self.errors {

View File

@ -80,8 +80,7 @@ pub fn run_shell(context: Context) -> Result<(), io::Error> {
continue;
}
let run_result =
interpreter.run(Rc::new("input".to_string()), Rc::from(buffer.as_str()));
let run_result = interpreter.run(Rc::from("input"), Rc::from(buffer.as_str()));
match run_result {
Ok(Some(value)) => {

View File

@ -49,9 +49,9 @@ fn main() {
let (source_id, source) = if let Some(path) = args.path {
let source = read_to_string(&path).unwrap();
(Rc::new(path.to_string()), source)
(Rc::from(path), source)
} else if let Some(command) = args.command {
(Rc::new("input".to_string()), command)
(Rc::from("input"), command)
} else {
match run_shell(context) {
Ok(_) => {}

View File

@ -3,7 +3,7 @@ io = {
__READ_LINE__()
}
write_line = (T)(output: T) none {
write_line = (output: str) none {
__WRITE_LINE__(output)
}
}