streamline code generation with iterators and traits
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::cell::{Cell};
|
||||
use std::vec::{Vec};
|
||||
|
||||
pub type Var = String;
|
||||
@@ -12,24 +13,39 @@ pub enum TopLevel {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Term {
|
||||
Atom(Atom),
|
||||
Clause(Atom, Vec<Box<Term>>),
|
||||
Var(Var)
|
||||
Atom(Cell<usize>, Atom),
|
||||
Clause(Cell<usize>, Atom, Vec<Box<Term>>),
|
||||
Var(Cell<usize>, Var)
|
||||
}
|
||||
|
||||
pub enum MachineInstruction {
|
||||
pub enum FactInstruction {
|
||||
GetStructure(Atom, usize, usize),
|
||||
PutStructure(Atom, usize, usize),
|
||||
SetVariable(usize),
|
||||
SetValue(usize),
|
||||
UnifyVariable(usize),
|
||||
UnifyValue(usize)
|
||||
}
|
||||
|
||||
pub type Program = Vec<MachineInstruction>;
|
||||
pub enum QueryInstruction {
|
||||
PutStructure(Atom, usize, usize),
|
||||
SetVariable(usize),
|
||||
SetValue(usize),
|
||||
}
|
||||
|
||||
pub type CompiledFact = Vec<FactInstruction>;
|
||||
|
||||
pub type CompiledQuery = Vec<QueryInstruction>;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum Addr {
|
||||
HeapCell(usize),
|
||||
RegNum(usize)
|
||||
}
|
||||
|
||||
impl Term {
|
||||
pub fn set_cell(&self, cell_num: usize) {
|
||||
match self {
|
||||
&Term::Atom(ref cell, _) => cell.set(cell_num),
|
||||
&Term::Clause(ref cell, _, _) => cell.set(cell_num),
|
||||
&Term::Var(ref cell, _) => cell.set(cell_num)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user