Rename interner to prototyper
This commit is contained in:
parent
a2a89ccaf2
commit
d657328487
18
src/main.rs
18
src/main.rs
@ -37,8 +37,8 @@ impl Value {
|
|||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
struct Object { index: u32 }
|
struct Object { index: u32 }
|
||||||
struct Program {
|
struct Program {
|
||||||
blocks: Interner<BlockData>,
|
blocks: Prototyper<BlockData>,
|
||||||
types: Interner<TypeData>,
|
types: Prototyper<TypeData>,
|
||||||
}
|
}
|
||||||
struct BlockData { instructions: Vec<Instruction> }
|
struct BlockData { instructions: Vec<Instruction> }
|
||||||
|
|
||||||
@ -312,8 +312,8 @@ impl Op21 {
|
|||||||
impl Program {
|
impl Program {
|
||||||
fn new() -> Program {
|
fn new() -> Program {
|
||||||
let mut p = Self {
|
let mut p = Self {
|
||||||
blocks: Interner::<BlockData>::new(),
|
blocks: Prototyper::<BlockData>::new(),
|
||||||
types: Interner::<TypeData>::new(),
|
types: Prototyper::<TypeData>::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty_null = p.type_prototype("null");
|
let ty_null = p.type_prototype("null");
|
||||||
@ -431,13 +431,13 @@ impl<'p> Heap<'p> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Interner<T> {
|
struct Prototyper<T> {
|
||||||
by_name: HashMap<String, u32>,
|
by_name: HashMap<String, u32>,
|
||||||
names: Vec<String>,
|
names: Vec<String>,
|
||||||
values: Vec<Option<T>>
|
values: Vec<Option<T>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Interner<T> {
|
impl<T> Prototyper<T> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
by_name: HashMap::new(),
|
by_name: HashMap::new(),
|
||||||
@ -459,7 +459,7 @@ impl<T> Interner<T> {
|
|||||||
pub fn instantiate(&mut self, handle: u32, value: T) -> Result<(), &'static str> {
|
pub fn instantiate(&mut self, handle: u32, value: T) -> Result<(), &'static str> {
|
||||||
let slot = self.values
|
let slot = self.values
|
||||||
.get_mut(handle as usize)
|
.get_mut(handle as usize)
|
||||||
.ok_or("handle was not prototyped on this interner")?;
|
.ok_or("handle was not prototyped on this prototyper")?;
|
||||||
if slot.is_some() {
|
if slot.is_some() {
|
||||||
return Err("can't instantiate handle twice")
|
return Err("can't instantiate handle twice")
|
||||||
}
|
}
|
||||||
@ -471,7 +471,7 @@ impl<T> Interner<T> {
|
|||||||
match self.values.get(handle as usize) {
|
match self.values.get(handle as usize) {
|
||||||
Some(Some(h)) => Ok(h),
|
Some(Some(h)) => Ok(h),
|
||||||
Some(_) => Err("handle was prototyped but not instantiated"),
|
Some(_) => Err("handle was prototyped but not instantiated"),
|
||||||
_ => Err("handle was not prototyped on this interner"),
|
_ => Err("handle was not prototyped on this prototyper"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,7 +479,7 @@ impl<T> Interner<T> {
|
|||||||
match self.values.get_mut(handle as usize) {
|
match self.values.get_mut(handle as usize) {
|
||||||
Some(Some(h)) => Ok(h),
|
Some(Some(h)) => Ok(h),
|
||||||
Some(_) => Err("handle was prototyped but not instantiated"),
|
Some(_) => Err("handle was prototyped but not instantiated"),
|
||||||
_ => Err("handle was not prototyped on this interner"),
|
_ => Err("handle was not prototyped on this prototyper"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user