New plans for macros
About to move them completely to stdlib
This commit is contained in:
@@ -27,7 +27,8 @@ use std::io::{Read, Write};
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::{read_exact, write_exact, Channel, Decode, Encode, MsgSet, Request};
|
||||
|
||||
use crate::{atom, error, expr, interner, logging::{self, LogStrategy}, parser, system, tree, vfs};
|
||||
use crate::logging::{self, LogStrategy};
|
||||
use crate::{atom, expr, interner, parser, system, tree, vfs};
|
||||
|
||||
static HOST_INTRO: &[u8] = b"Orchid host, binary API v0\n";
|
||||
pub struct HostHeader {
|
||||
@@ -48,17 +49,19 @@ impl Encode for HostHeader {
|
||||
|
||||
static EXT_INTRO: &[u8] = b"Orchid extension, binary API v0\n";
|
||||
pub struct ExtensionHeader {
|
||||
pub name: String,
|
||||
pub systems: Vec<system::SystemDecl>,
|
||||
}
|
||||
impl Decode for ExtensionHeader {
|
||||
fn decode<R: Read + ?Sized>(read: &mut R) -> Self {
|
||||
read_exact(read, EXT_INTRO);
|
||||
Self { systems: Vec::decode(read) }
|
||||
Self { name: String::decode(read), systems: Vec::decode(read) }
|
||||
}
|
||||
}
|
||||
impl Encode for ExtensionHeader {
|
||||
fn encode<W: Write + ?Sized>(&self, write: &mut W) {
|
||||
write_exact(write, EXT_INTRO);
|
||||
self.name.encode(write);
|
||||
self.systems.encode(write)
|
||||
}
|
||||
}
|
||||
@@ -78,7 +81,6 @@ pub enum ExtHostReq {
|
||||
Fwd(atom::Fwd),
|
||||
ExprReq(expr::ExprReq),
|
||||
SubLex(parser::SubLex),
|
||||
ProjErrReq(error::ProjErrReq),
|
||||
}
|
||||
|
||||
/// Notifications sent from the extension to the host
|
||||
@@ -87,7 +89,6 @@ pub enum ExtHostReq {
|
||||
#[extendable]
|
||||
pub enum ExtHostNotif {
|
||||
ExprNotif(expr::ExprNotif),
|
||||
AdviseSweep(interner::AdviseSweep),
|
||||
Log(logging::Log),
|
||||
}
|
||||
|
||||
@@ -102,9 +103,10 @@ impl Channel for ExtHostChannel {
|
||||
#[extendable]
|
||||
pub enum HostExtReq {
|
||||
Ping(Ping),
|
||||
NewSystem(system::NewSystem),
|
||||
SysReq(system::SysReq),
|
||||
Sweep(interner::Sweep),
|
||||
AtomReq(atom::AtomReq),
|
||||
DeserAtom(atom::DeserAtom),
|
||||
ParserReq(parser::ParserReq),
|
||||
GetMember(tree::GetMember),
|
||||
VfsReq(vfs::VfsReq),
|
||||
@@ -143,35 +145,35 @@ impl MsgSet for HostMsgSet {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ordered_float::NotNan;
|
||||
use system::{SysDeclId, SystemDecl};
|
||||
use orchid_api_traits::enc_vec;
|
||||
use ordered_float::NotNan;
|
||||
use system::{SysDeclId, SystemDecl};
|
||||
|
||||
use super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn host_header_enc() {
|
||||
let hh = HostHeader { log_strategy: LogStrategy::File("SomeFile".to_string()) };
|
||||
let mut enc = &hh.enc_vec()[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
HostHeader::decode(&mut enc);
|
||||
assert_eq!(enc, []);
|
||||
}
|
||||
#[test]
|
||||
fn host_header_enc() {
|
||||
let hh = HostHeader { log_strategy: LogStrategy::File("SomeFile".to_string()) };
|
||||
let mut enc = &enc_vec(&hh)[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
HostHeader::decode(&mut enc);
|
||||
assert_eq!(enc, []);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_header_enc() {
|
||||
let eh = ExtensionHeader {
|
||||
systems: vec![
|
||||
SystemDecl {
|
||||
id: SysDeclId(1.try_into().unwrap()),
|
||||
name: "misc".to_string(),
|
||||
depends: vec![ "std".to_string() ],
|
||||
priority: NotNan::new(1f64).unwrap()
|
||||
}
|
||||
]
|
||||
};
|
||||
let mut enc = &eh.enc_vec()[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
ExtensionHeader::decode(&mut enc);
|
||||
assert_eq!(enc, [])
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn ext_header_enc() {
|
||||
let eh = ExtensionHeader {
|
||||
name: "my_extension".to_string(),
|
||||
systems: vec![SystemDecl {
|
||||
id: SysDeclId(1.try_into().unwrap()),
|
||||
name: "misc".to_string(),
|
||||
depends: vec!["std".to_string()],
|
||||
priority: NotNan::new(1f64).unwrap(),
|
||||
}],
|
||||
};
|
||||
let mut enc = &enc_vec(&eh)[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
ExtensionHeader::decode(&mut enc);
|
||||
assert_eq!(enc, [])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user