Initial stack typing

This commit is contained in:
2019-04-29 15:21:37 +02:00
parent 1381ce7b48
commit ba0fca8755
6 changed files with 106 additions and 59 deletions

30
src/value.rs Normal file
View File

@@ -0,0 +1,30 @@
use Result;
use std::convert::TryInto;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Value {
Int(i32),
HeapRef(usize),
}
impl TryInto<i32> for Value {
type Error = &'static str;
fn try_into(self) -> Result<i32> {
match self {
Value::Int(a) => Ok(a),
Value::HeapRef(_) => Err("Cannot use HeapRef as i32"),
}
}
}
impl TryInto<i32> for &Value {
type Error = &'static str;
fn try_into(self) -> Result<i32> {
match self {
&Value::Int(a) => Ok(a),
&Value::HeapRef(_) => Err("Cannot use HeapRef as i32"),
}
}
}