cargo fix
This commit is contained in:
parent
901a5cb734
commit
75a0de04b6
2 changed files with 31 additions and 17 deletions
43
src/main.rs
43
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use spl::{lexer::lex, runtime::*};
|
||||
|
||||
use std::{fs, env::args};
|
||||
use std::{env::args, fs};
|
||||
|
||||
fn main() -> OError {
|
||||
let rt = Runtime::new();
|
||||
|
@ -17,23 +17,34 @@ fn main() -> OError {
|
|||
let Value::Str(s) = stack.pop().lock_ro().native.clone() else {
|
||||
return stack.err(ErrorKind::InvalidCall("read_file".to_owned()))
|
||||
};
|
||||
stack.push(Value::Str(fs::read_to_string(s).map_err(|x| stack.error(ErrorKind::IO(format!("{x:?}"))))?).spl());
|
||||
stack.push(
|
||||
Value::Str(
|
||||
fs::read_to_string(s).map_err(|x| stack.error(ErrorKind::IO(format!("{x:?}"))))?,
|
||||
)
|
||||
.spl(),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
stack.define_func("argv".to_owned(), AFunc::new(Func {
|
||||
ret_count: 1,
|
||||
to_call: FuncImpl::Native(argv),
|
||||
origin: stack.get_frame(),
|
||||
fname: None,
|
||||
name: "argv".to_owned(),
|
||||
}));
|
||||
stack.define_func("read-file".to_owned(), AFunc::new(Func {
|
||||
ret_count: 1,
|
||||
to_call: FuncImpl::Native(read_file),
|
||||
origin: stack.get_frame(),
|
||||
fname: None,
|
||||
name: "read-file".to_owned(),
|
||||
}));
|
||||
stack.define_func(
|
||||
"argv".to_owned(),
|
||||
AFunc::new(Func {
|
||||
ret_count: 1,
|
||||
to_call: FuncImpl::Native(argv),
|
||||
origin: stack.get_frame(),
|
||||
fname: None,
|
||||
name: "argv".to_owned(),
|
||||
}),
|
||||
);
|
||||
stack.define_func(
|
||||
"read-file".to_owned(),
|
||||
AFunc::new(Func {
|
||||
ret_count: 1,
|
||||
to_call: FuncImpl::Native(read_file),
|
||||
origin: stack.get_frame(),
|
||||
fname: None,
|
||||
name: "read-file".to_owned(),
|
||||
}),
|
||||
);
|
||||
let words = lex(fs::read_to_string("std.spl").unwrap()).map_err(|x| Error {
|
||||
kind: ErrorKind::LexError(format!("{x:?}")),
|
||||
stack: Vec::new(),
|
||||
|
|
|
@ -455,7 +455,10 @@ impl Stack {
|
|||
}
|
||||
|
||||
pub fn peek_frame(&self, index: usize) -> Arc<Frame> {
|
||||
self.frames.get(self.frames.len() - index - 1).unwrap().clone()
|
||||
self.frames
|
||||
.get(self.frames.len() - index - 1)
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub unsafe fn pop_frame(&mut self, index: usize) -> Arc<Frame> {
|
||||
|
|
Loading…
Add table
Reference in a new issue