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 spl::{lexer::lex, runtime::*};
|
||||||
|
|
||||||
use std::{fs, env::args};
|
use std::{env::args, fs};
|
||||||
|
|
||||||
fn main() -> OError {
|
fn main() -> OError {
|
||||||
let rt = Runtime::new();
|
let rt = Runtime::new();
|
||||||
|
@ -17,23 +17,34 @@ fn main() -> 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("read_file".to_owned()))
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
stack.define_func("argv".to_owned(), AFunc::new(Func {
|
stack.define_func(
|
||||||
ret_count: 1,
|
"argv".to_owned(),
|
||||||
to_call: FuncImpl::Native(argv),
|
AFunc::new(Func {
|
||||||
origin: stack.get_frame(),
|
ret_count: 1,
|
||||||
fname: None,
|
to_call: FuncImpl::Native(argv),
|
||||||
name: "argv".to_owned(),
|
origin: stack.get_frame(),
|
||||||
}));
|
fname: None,
|
||||||
stack.define_func("read-file".to_owned(), AFunc::new(Func {
|
name: "argv".to_owned(),
|
||||||
ret_count: 1,
|
}),
|
||||||
to_call: FuncImpl::Native(read_file),
|
);
|
||||||
origin: stack.get_frame(),
|
stack.define_func(
|
||||||
fname: None,
|
"read-file".to_owned(),
|
||||||
name: "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 {
|
let words = lex(fs::read_to_string("std.spl").unwrap()).map_err(|x| Error {
|
||||||
kind: ErrorKind::LexError(format!("{x:?}")),
|
kind: ErrorKind::LexError(format!("{x:?}")),
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
|
|
|
@ -455,7 +455,10 @@ impl Stack {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn peek_frame(&self, index: usize) -> Arc<Frame> {
|
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> {
|
pub unsafe fn pop_frame(&mut self, index: usize) -> Arc<Frame> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue