Skip to main content

Machine

Trait Machine 

Source
pub trait Machine: Send {
    // Required methods
    fn lang(&self) -> &str;
    fn feed(&mut self, kind: InnerKind, term: &QTerm) -> Result<Answer>;

    // Provided methods
    fn identity(&self) -> Option<&str> { ... }
    fn eval(&mut self, term: &QTerm) -> Result<Answer> { ... }
    fn type_of(&mut self, term: &QTerm) -> Result<Answer> { ... }
}
Expand description

A stateful evaluator of one language.

The message sorts are InnerKind — already the vocabulary “for communicating between parsers” (lang.rs), and equally the vocabulary for communicating with machines:

  • Item — a definition: extends the environment.
  • Stmt — an effect: runs against the environment.
  • Expr — a query: answers the value’s denotation.
  • File / Block — a batch.

The laws a well-behaved machine satisfies (asserted by the conformance battery as providers grow): denotation — evaluating a literal answers that literal; sequencing — feed(p1); feed(p2) behaves as feeding p1; p2 to a fresh machine; isolation — two machines share nothing.

Send is a supertrait because parked machines travel with their Multi (test harnesses hold one behind a Mutex); a machine is a handle to a process or connection, which sends fine.

The trait traffics in terms, like every other Quilt interface. Tenet 2 is about the end user writing plain source text rather than builder calls — it says nothing about internal APIs, and the parser that can turn user text into a term lives with the Language, not here. So the validated textual door is Multi::feed_on at the rim; a provider whose wire is text (a subprocess’s stdin) coparses internally, which is its business and no caller’s.

Required Methods§

Source

fn lang(&self) -> &str

The language this machine speaks (a registry key, e.g. "py").

Source

fn feed(&mut self, kind: InnerKind, term: &QTerm) -> Result<Answer>

Feed one term. Definitions and effects accumulate; queries answer.

Provided Methods§

Source

fn identity(&self) -> Option<&str>

Which machine this is, when that is known exactly: a name for everything it runs, such that two machines with the same identity are the same interpreter, libraries, arguments and environment. A pinned machine answers its content address.

None — the default — is the honest answer for an interpreter found on PATH: lang says what it speaks, and nothing says which build of it answered. A caller that records what a machine said (a cache, a log, a signed result) keys on this, and should refuse to when it is None.

Source

fn eval(&mut self, term: &QTerm) -> Result<Answer>

Query a term’s value: feed as InnerKind::Expr.

Source

fn type_of(&mut self, term: &QTerm) -> Result<Answer>

The typing judgment: answer the type of the term, as a literal of this language’s type spellings (int, 42 : ℕ, unsat). An evaluator asks “what value”; a checker — Lean, a solver, an LSP — asks this instead, and a proof language’s machine may support only this and Item-checking. Defaults to an honest error, the same pattern as the operator spellings on MetaLanguage.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§