1use common::Interner;
3
4pub type TypeContext = Interner<Type>;
5
6impl Type {
7 pub fn int_size(&self) -> u32 {
8 match *self {
9 Type::Integer(size) => size,
10 }
11 }
12}
13
14#[derive(Debug, PartialEq, Eq, Hash)]
15pub enum Type {
16 Integer(u32),
17 }
25
26#[derive(Clone, Debug, Hash, PartialEq, Eq)]
27pub struct Function<'t> {
28 pub inputs: Box<[&'t Type]>,
29 pub output: &'t Type,
30}
31
32mod fmt {
33 use std::fmt::{Display, Formatter, Error};
34 use super::{Type, Function};
35 impl Display for Type {
36 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
37 match *self {
38 Type::Integer(n) => write!(f, "i{}", n),
39 }
55 }
56 }
57
58 impl<'a> Display for Function<'a> {
59 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
60 try!(write!(f, "("));
61 if !self.inputs.is_empty() {
62 for input in &self.inputs[..self.inputs.len() - 1] {
63 try!(write!(f, "{}, ", input));
64 }
65 try!(write!(f, "{}", self.inputs[self.inputs.len() - 1]));
66 }
67 write!(f, ") -> {}", self.output)
68 }
69 }
70}
71