September-october commit
- manual parser - stl refinements - all language constructs are now Send
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use super::flow::IOCmdHandlePack;
|
||||
use super::instances::{BRead, ReadCmd, SRead, Sink, Source, WriteCmd};
|
||||
use crate::error::RuntimeError;
|
||||
use crate::foreign::cps_box::init_cps;
|
||||
use crate::foreign::{xfn_1ary, xfn_2ary, Atom, Atomic, XfnResult};
|
||||
use crate::foreign::{xfn_1ary, xfn_2ary, Atomic, XfnResult, Atom};
|
||||
use crate::interpreted::Clause;
|
||||
use crate::representations::OrcString;
|
||||
use crate::systems::scheduler::SharedHandle;
|
||||
use crate::systems::stl::Binary;
|
||||
use crate::systems::RuntimeError;
|
||||
use crate::{ast, ConstTree, Interner, Primitive};
|
||||
use crate::{ConstTree, Interner, ast};
|
||||
|
||||
type WriteHandle = SharedHandle<Sink>;
|
||||
type ReadHandle = SharedHandle<Source>;
|
||||
@@ -21,11 +21,11 @@ pub fn read_line(handle: ReadHandle) -> XfnResult<Clause> {
|
||||
pub fn read_bin(handle: ReadHandle) -> XfnResult<Clause> {
|
||||
Ok(init_cps(3, IOCmdHandlePack { handle, cmd: ReadCmd::RBytes(BRead::All) }))
|
||||
}
|
||||
pub fn read_bytes(handle: ReadHandle, n: u64) -> XfnResult<Clause> {
|
||||
let cmd = ReadCmd::RBytes(BRead::N(n.try_into().unwrap()));
|
||||
pub fn read_bytes(handle: ReadHandle, n: usize) -> XfnResult<Clause> {
|
||||
let cmd = ReadCmd::RBytes(BRead::N(n));
|
||||
Ok(init_cps(3, IOCmdHandlePack { cmd, handle }))
|
||||
}
|
||||
pub fn read_until(handle: ReadHandle, pattern: u64) -> XfnResult<Clause> {
|
||||
pub fn read_until(handle: ReadHandle, pattern: usize) -> XfnResult<Clause> {
|
||||
let delim = pattern.try_into().map_err(|_| {
|
||||
let msg = "greater than 255".to_string();
|
||||
RuntimeError::ext(msg, "converting number to byte")
|
||||
@@ -63,8 +63,7 @@ pub fn io_bindings<'a>(
|
||||
std_streams
|
||||
.into_iter()
|
||||
.map(|(n, at)| {
|
||||
let expr = ast::Clause::P(Primitive::Atom(Atom(at))).into_expr();
|
||||
(i.i(n), ConstTree::Const(expr))
|
||||
(i.i(n), ConstTree::clause(ast::Clause::Atom(Atom(at))))
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::interpreted::ExprInst;
|
||||
use crate::systems::codegen::call;
|
||||
use crate::systems::scheduler::{Canceller, SharedHandle};
|
||||
use crate::systems::stl::Binary;
|
||||
use crate::Literal;
|
||||
use crate::OrcString;
|
||||
|
||||
/// Any type that we can read controlled amounts of data from
|
||||
pub type Source = BufReader<Box<dyn Read + Send>>;
|
||||
@@ -63,10 +63,14 @@ impl IOCmd for ReadCmd {
|
||||
Self::RStr(sread) => {
|
||||
let mut buf = String::new();
|
||||
let sresult = match &sread {
|
||||
SRead::All => stream.read_to_string(&mut buf),
|
||||
SRead::Line => stream.read_line(&mut buf),
|
||||
SRead::All => stream.read_to_string(&mut buf).map(|_| ()),
|
||||
SRead::Line => stream.read_line(&mut buf).map(|_| {
|
||||
if buf.ends_with('\n') {
|
||||
buf.pop();
|
||||
}
|
||||
}),
|
||||
};
|
||||
ReadResult::RStr(sread, sresult.map(|_| buf))
|
||||
ReadResult::RStr(sread, sresult.map(|()| buf))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -88,14 +92,14 @@ impl ReadResult {
|
||||
vec![call(succ, [arg]).wrap()]
|
||||
},
|
||||
ReadResult::RStr(_, Ok(text)) => {
|
||||
vec![call(succ, [Literal::Str(text.into()).into()]).wrap()]
|
||||
vec![call(succ, [OrcString::from(text).atom_exi()]).wrap()]
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Function to convert [io::Error] to Orchid data
|
||||
pub fn wrap_io_error(_e: io::Error) -> ExprInst { Literal::Uint(0u64).into() }
|
||||
pub fn wrap_io_error(_e: io::Error) -> ExprInst { 0usize.atom_exi() }
|
||||
|
||||
/// Writing command (string or binary)
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -2,7 +2,7 @@ import std::panic
|
||||
import system::io
|
||||
import system::async::yield
|
||||
|
||||
export const print := \text.\ok. (
|
||||
export const print := \text. \ok. (
|
||||
io::write_str io::stdout text
|
||||
(io::flush io::stdout
|
||||
ok
|
||||
@@ -13,7 +13,7 @@ export const print := \text.\ok. (
|
||||
\_. yield
|
||||
)
|
||||
|
||||
export const println := \line.\ok. (
|
||||
export const println := \line. \ok. (
|
||||
print (line ++ "\n") ok
|
||||
)
|
||||
|
||||
|
||||
@@ -113,6 +113,8 @@ impl<'a, ST: IntoIterator<Item = (&'a str, Stream)>> IntoSystem<'static>
|
||||
name: None,
|
||||
}]),
|
||||
}],
|
||||
lexer_plugin: None,
|
||||
line_parser: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user