forked from Orchid/orchid
base and extension fully compiles, host in good shape
This commit is contained in:
@@ -9,3 +9,7 @@ edition = "2021"
|
||||
ordered-float = "4.6.0"
|
||||
orchid-api-traits = { version = "0.1.0", path = "../orchid-api-traits" }
|
||||
orchid-api-derive = { version = "0.1.0", path = "../orchid-api-derive" }
|
||||
async-std = "1.13.0"
|
||||
|
||||
[dev-dependencies]
|
||||
test_executors = "0.3.2"
|
||||
|
||||
@@ -120,6 +120,13 @@ impl Request for AtomPrint {
|
||||
type Response = String;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[extends(ExtHostReq)]
|
||||
pub struct ExtAtomPrint(pub Atom);
|
||||
impl Request for ExtAtomPrint {
|
||||
type Response = String;
|
||||
}
|
||||
|
||||
/// Requests that apply to an existing atom instance
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::num::NonZeroU64;
|
||||
use std::sync::Arc;
|
||||
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
use std::num::NonZeroU64;
|
||||
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_derive::{Coding, Decode, Encode, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
|
||||
use crate::{Comment, HostExtReq, OrcResult, SysId, TokenTree};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
|
||||
pub struct ParsId(pub NonZeroU64);
|
||||
|
||||
// impl orchid_api_traits::Decode for ParsId {
|
||||
// async fn decode<R: async_std::io::Read + ?Sized>(mut read:
|
||||
// std::pin::Pin<&mut R>) -> Self {
|
||||
// Self(orchid_api_traits::Decode::decode(read.as_mut()).await)
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct ParseLine {
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
//! be preserved. Toolkits must ensure that the client code is able to observe
|
||||
//! the ordering of messages.
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use std::pin::Pin;
|
||||
|
||||
use async_std::io::{Read, Write};
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::{Channel, Decode, Encode, MsgSet, Request, read_exact, write_exact};
|
||||
|
||||
@@ -34,15 +35,15 @@ pub struct HostHeader {
|
||||
pub log_strategy: logging::LogStrategy,
|
||||
}
|
||||
impl Decode for HostHeader {
|
||||
fn decode<R: Read + ?Sized>(read: &mut R) -> Self {
|
||||
read_exact(read, HOST_INTRO);
|
||||
Self { log_strategy: logging::LogStrategy::decode(read) }
|
||||
async fn decode<R: Read + ?Sized>(mut read: Pin<&mut R>) -> Self {
|
||||
read_exact(read.as_mut(), HOST_INTRO).await;
|
||||
Self { log_strategy: logging::LogStrategy::decode(read).await }
|
||||
}
|
||||
}
|
||||
impl Encode for HostHeader {
|
||||
fn encode<W: Write + ?Sized>(&self, write: &mut W) {
|
||||
write_exact(write, HOST_INTRO);
|
||||
self.log_strategy.encode(write)
|
||||
async fn encode<W: Write + ?Sized>(&self, mut write: Pin<&mut W>) {
|
||||
write_exact(write.as_mut(), HOST_INTRO).await;
|
||||
self.log_strategy.encode(write).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,16 +53,16 @@ pub struct ExtensionHeader {
|
||||
pub systems: Vec<system::SystemDecl>,
|
||||
}
|
||||
impl Decode for ExtensionHeader {
|
||||
fn decode<R: Read + ?Sized>(read: &mut R) -> Self {
|
||||
read_exact(read, EXT_INTRO);
|
||||
Self { name: String::decode(read), systems: Vec::decode(read) }
|
||||
async fn decode<R: Read + ?Sized>(mut read: Pin<&mut R>) -> Self {
|
||||
read_exact(read.as_mut(), EXT_INTRO).await;
|
||||
Self { name: String::decode(read.as_mut()).await, systems: Vec::decode(read).await }
|
||||
}
|
||||
}
|
||||
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)
|
||||
async fn encode<W: Write + ?Sized>(&self, mut write: Pin<&mut W>) {
|
||||
write_exact(write.as_mut(), EXT_INTRO).await;
|
||||
self.name.encode(write.as_mut()).await;
|
||||
self.systems.encode(write).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ pub enum ExtHostReq {
|
||||
Ping(Ping),
|
||||
IntReq(interner::IntReq),
|
||||
Fwd(atom::Fwd),
|
||||
ExtAtomPrint(atom::ExtAtomPrint),
|
||||
SysFwd(system::SysFwd),
|
||||
ExprReq(expr::ExprReq),
|
||||
SubLex(lexer::SubLex),
|
||||
@@ -150,32 +152,37 @@ impl MsgSet for HostMsgSet {
|
||||
mod tests {
|
||||
use orchid_api_traits::enc_vec;
|
||||
use ordered_float::NotNan;
|
||||
use test_executors::spin_on;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn host_header_enc() {
|
||||
let hh = HostHeader { log_strategy: logging::LogStrategy::File("SomeFile".to_string()) };
|
||||
let mut enc = &enc_vec(&hh)[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
HostHeader::decode(&mut enc);
|
||||
assert_eq!(enc, []);
|
||||
spin_on(async {
|
||||
let hh = HostHeader { log_strategy: logging::LogStrategy::File("SomeFile".to_string()) };
|
||||
let mut enc = &enc_vec(&hh).await[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
HostHeader::decode(Pin::new(&mut enc)).await;
|
||||
assert_eq!(enc, []);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_header_enc() {
|
||||
let eh = ExtensionHeader {
|
||||
name: "my_extension".to_string(),
|
||||
systems: vec![system::SystemDecl {
|
||||
id: system::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, [])
|
||||
spin_on(async {
|
||||
let eh = ExtensionHeader {
|
||||
name: "my_extension".to_string(),
|
||||
systems: vec![system::SystemDecl {
|
||||
id: system::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).await[..];
|
||||
eprintln!("Encoded to {enc:?}");
|
||||
ExtensionHeader::decode(Pin::new(&mut enc)).await;
|
||||
assert_eq!(enc, [])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user