Lexer test mode works

This commit is contained in:
2024-08-04 23:24:32 +02:00
parent 9d35ba8040
commit 11951ede43
36 changed files with 687 additions and 115 deletions

View File

@@ -104,6 +104,13 @@ impl Request for Command {
#[extends(HostExtNotif)]
pub struct AtomDrop(pub Atom);
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[extends(AtomReq, HostExtReq)]
pub struct AtomPrint(pub Atom);
impl Request for AtomPrint {
type Response = String;
}
/// Requests that apply to an existing atom instance
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[extends(HostExtReq)]
@@ -114,6 +121,7 @@ pub enum AtomReq {
AtomSame(AtomSame),
Fwded(Fwded),
Command(Command),
AtomPrint(AtomPrint),
}
impl AtomReq {
/// Obtain the first [Atom] argument of the request. All requests in this
@@ -124,7 +132,8 @@ impl AtomReq {
| Self::CallRef(CallRef(a, ..))
| Self::Command(Command(a))
| Self::FinalCall(FinalCall(a, ..))
| Self::Fwded(Fwded(a, ..)) => a,
| Self::Fwded(Fwded(a, ..))
| Self::AtomPrint(AtomPrint(a)) => a,
}
}
}

View File

@@ -8,3 +8,4 @@ pub mod proto;
pub mod system;
pub mod tree;
pub mod vfs;
pub mod logging;

13
orchid-api/src/logging.rs Normal file
View File

@@ -0,0 +1,13 @@
use orchid_api_derive::{Coding, Hierarchy};
use crate::proto::ExtHostNotif;
#[derive(Clone, Debug, Coding)]
pub enum LogStrategy {
StdErr,
File(String)
}
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExtHostNotif)]
pub struct Log(pub String);

View File

@@ -27,18 +27,23 @@ 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, parser, system, tree, vfs};
use crate::{atom, error, expr, interner, logging::{self, LogStrategy}, parser, system, tree, vfs};
static HOST_INTRO: &[u8] = b"Orchid host, binary API v0\n";
pub struct HostHeader;
pub struct HostHeader {
pub log_strategy: LogStrategy,
}
impl Decode for HostHeader {
fn decode<R: Read + ?Sized>(read: &mut R) -> Self {
read_exact(read, HOST_INTRO);
Self
Self { log_strategy: LogStrategy::decode(read) }
}
}
impl Encode for HostHeader {
fn encode<W: Write + ?Sized>(&self, write: &mut W) { write_exact(write, HOST_INTRO) }
fn encode<W: Write + ?Sized>(&self, write: &mut W) {
write_exact(write, HOST_INTRO);
self.log_strategy.encode(write)
}
}
static EXT_INTRO: &[u8] = b"Orchid extension, binary API v0\n";
@@ -83,6 +88,7 @@ pub enum ExtHostReq {
pub enum ExtHostNotif {
ExprNotif(expr::ExprNotif),
AdviseSweep(interner::AdviseSweep),
Log(logging::Log),
}
pub struct ExtHostChannel;
@@ -134,3 +140,38 @@ impl MsgSet for HostMsgSet {
type In = ExtHostChannel;
type Out = HostExtChannel;
}
#[cfg(test)]
mod tests {
use ordered_float::NotNan;
use system::{SysDeclId, SystemDecl};
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 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, [])
}
}

View File

@@ -64,7 +64,7 @@ pub struct Placeholder {
pub enum PlaceholderKind {
Scalar,
Name,
Vector { nonzero: bool, priority: u8 },
Vector { nz: bool, prio: u8 },
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]