partway towards commands
I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
This commit is contained in:
37
orchid-std/src/std/stream/stream_lib.rs
Normal file
37
orchid-std/src/std/stream/stream_lib.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use orchid_base::{is, mk_errv};
|
||||
use orchid_extension::ForeignAtom;
|
||||
use orchid_extension::expr::Expr;
|
||||
use orchid_extension::func_atom::get_arg;
|
||||
use orchid_extension::gen_expr::new_atom;
|
||||
use orchid_extension::stream_reqs::ReadLimit;
|
||||
use orchid_extension::tree::{GenMember, comments, fun, prefix};
|
||||
|
||||
use crate::Int;
|
||||
use crate::std::stream::stream_cmds::ReadStreamCmd;
|
||||
|
||||
pub fn gen_stream_lib() -> Vec<GenMember> {
|
||||
prefix("std", [comments(
|
||||
["Read from and write to byte streams"],
|
||||
prefix("stream", [
|
||||
fun(true, "read_bin", async |hand: ForeignAtom, succ: Expr, fail: Expr| {
|
||||
new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::End })
|
||||
}),
|
||||
fun(true, "read_until", async |hand: ForeignAtom, delim: Int, succ: Expr, fail: Expr| {
|
||||
let Ok(end) = delim.0.try_into() else {
|
||||
return Err(mk_errv(
|
||||
is("Byte out of range").await,
|
||||
format!(
|
||||
"{} doesn't fit into a byte and cannot be used as a delimiter for reading",
|
||||
delim.0
|
||||
),
|
||||
[get_arg(1).pos().await],
|
||||
));
|
||||
};
|
||||
Ok(new_atom(ReadStreamCmd { hand, succ, fail, limit: ReadLimit::Delimiter(end) }))
|
||||
}),
|
||||
fun(true, "read_bytes", async |hand: ForeignAtom, count: Int, succ: Expr, fail: Expr| {
|
||||
Int(todo!())
|
||||
}),
|
||||
]),
|
||||
)])
|
||||
}
|
||||
Reference in New Issue
Block a user