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:
2026-03-13 16:48:42 +01:00
parent cdcca694c5
commit 09cfcb1839
146 changed files with 3582 additions and 2822 deletions

View File

@@ -49,16 +49,16 @@ pub struct Atom {
/// Construction is always explicit and atoms are never cloned.
///
/// Atoms with `drop == None` are also known as trivial, they can be
/// duplicated and stored with no regard to expression lifetimes. NOTICE
/// duplicated and stored with no regard to expression lifetimes. Note
/// that this only applies to the atom. If it's referenced with an
/// [ExprTicket], the ticket itself can still expire.
///
/// Notice also that the atoms still expire when the system is dropped, and
/// Note also that the atoms still expire when the system is dropped, and
/// are not portable across instances of the same system, so this doesn't
/// imply that the atom is serializable.
pub drop: Option<AtomId>,
/// Data stored in the atom. This could be a key into a map, or the raw data
/// of the atom if it isn't too big.
/// Data stored in the atom. This could be a key into a map, the raw data
/// of the atom if it isn't too big, or even a pointer.
pub data: AtomData,
}
@@ -91,7 +91,7 @@ impl Request for SerializeAtom {
#[extends(HostExtReq)]
pub struct DeserAtom(pub SysId, pub Vec<u8>, pub Vec<ExprTicket>);
impl Request for DeserAtom {
type Response = Atom;
type Response = LocalAtom;
}
/// A request blindly routed to the system that provides an atom.
@@ -109,10 +109,24 @@ impl Request for Fwd {
type Response = Option<Vec<u8>>;
}
/// What to do after a command has finished executing
#[derive(Clone, Debug, Coding)]
pub enum NextStep {
Continue(Expression),
Halt,
/// Add more work. Parallel work is fairly executed in parallel, so different
/// command chains can block on each other. When the command queue is empty,
/// the interpreter may exit without waiting for timers.
Continue {
/// Run these commands immediately. Since timers don't keep the interpreter
/// alive, this should usually be non-empty, but this is not required.
immediate: Vec<Expression>,
/// Schedule these commands after the specified number of milliseconds, if
/// the interpreter had not exited by then.
delayed: Vec<(NonZeroU64, Expression)>,
},
/// Discard the rest of the queue and exit. It is possible to fail the program
/// without raising an error because the convention on most OSes is to
/// separate error reporting from a failure exit.
Exit { success: bool },
}
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(AtomReq, HostExtReq)]

View File

@@ -69,8 +69,10 @@ pub struct SpawnerBin {
pub data: *const (),
/// `self`
pub drop: extern "C" fn(*const ()),
/// `&self` Add a future to this extension's task
pub spawn: extern "C" fn(*const (), FutureBin),
/// `&self` Add a future to this extension's task after a configurable delay
/// measured in milliseconds. By itself, a pending timer never prevents
/// extension shutdown.
pub spawn: extern "C" fn(*const (), u64, FutureBin),
}
/// Extension context.

View File

@@ -1,4 +1,5 @@
use std::num::NonZeroU16;
use std::rc::Rc;
use std::sync::Arc;
use orchid_api_derive::Coding;
@@ -28,7 +29,7 @@ pub struct OrcError {
pub description: TStr,
/// Specific information about the exact error, preferably containing concrete
/// values.
pub message: Arc<String>,
pub message: Rc<String>,
/// Specific code fragments that have contributed to the emergence of the
/// error.
pub locations: Vec<ErrLocation>,

View File

@@ -4,7 +4,7 @@ use std::num::NonZeroU64;
use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::Request;
use crate::{Atom, ExtHostNotif, ExtHostReq, Location, OrcError, SysId, TStrv};
use crate::{Atom, ExtHostNotif, ExtHostReq, LocalAtom, Location, OrcError, SysId, TStrv};
/// An arbitrary ID associated with an expression on the host side. Incoming
/// tickets always come with some lifetime guarantee, which can be extended with
@@ -65,8 +65,7 @@ pub enum ExpressionKind {
/// Insert a new atom in the tree. When the clause is used in the const tree,
/// the atom must be trivial. This is always a newly constructed atom, if you
/// want to reference an existing atom, use the corresponding [ExprTicket].
/// Because the atom is newly constructed, it also must belong to this system.
NewAtom(Atom),
NewAtom(LocalAtom),
/// A reference to a constant
Const(TStrv),
/// A static runtime error.
@@ -123,7 +122,7 @@ pub enum ExprNotif {
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExprReq, ExtHostReq)]
pub struct Create(pub Expression);
pub struct Create(pub SysId, pub Expression);
impl Request for Create {
type Response = ExprTicket;
}

View File

@@ -29,7 +29,7 @@ use futures::{AsyncRead, AsyncWrite, AsyncWriteExt};
use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::{Channel, Decode, Encode, MsgSet, Request, read_exact};
use crate::{Sweeped, atom, expr, interner, lexer, logging, parser, system, tree};
use crate::{atom, expr, interner, lexer, logging, parser, system, tree};
static HOST_INTRO: &[u8] = b"Orchid host, binary API v0\n";
#[derive(Clone, Debug)]
@@ -97,7 +97,7 @@ pub enum ExtHostReq {
pub enum ExtHostNotif {
ExprNotif(expr::ExprNotif),
Log(logging::Log),
Sweeped(Sweeped),
Sweeped(interner::Sweeped),
}
pub struct ExtHostChannel;