Struct jit::Type [] [src]

pub struct Type {
    // some fields omitted
}

An owned object that represents a native system type.

Each Type represents a basic system type, be it a primitive, a struct, a union, a pointer, or a function signature. The library uses this information to lay out values in memory.

Types are not attached to a context so they are reference-counted by LibJIT, so internally they are represented as Rc<Ty>.

Methods

impl Type

fn new_signature(abi: Abi, return_type: &Ty, params: &mut [&Ty]) -> Type

Create a type descriptor for a function signature.

fn new_struct(fields: &mut [&Ty]) -> Type

Create a type descriptor for a structure.

fn new_union(fields: &mut [&Ty]) -> Type

Create a type descriptor for a union.

fn new_pointer(pointee: &Ty) -> Type

Create a type descriptor for a pointer to another type.

Methods from Deref<Target=Ty>

fn get_size(&self) -> usize

Get the size of this type in bytes.

fn get_alignment(&self) -> usize

Get the alignment of this type in bytes.

fn get_kind(&self) -> TypeKind

Get a value that indicates the kind of this type. This allows callers to quickly classify a type to determine how it should be handled further.

fn get_ref(&self) -> Option<&Ty>

Get the type that is referred to by this pointer type.

fn get_return(&self) -> Option<&Ty>

Get the type returned by this function type.

fn set_names(&mut self, names: &[&str])

Set the field or parameter names of this struct or union type.

use jit::*;
let f64_t = get::<f64>();
let mut ty = Type::new_struct(&mut [&f64_t, &f64_t]);
ty.set_names(&["x", "y"]);
assert_eq!(ty.get_field("x").unwrap().get_type(), &f64_t as &Ty);
assert_eq!(ty.get_field("y").unwrap().get_type(), &f64_t as &Ty);

fn fields(&self) -> Fields

Iterate over the type's fields

use jit::*;
let pos_t = get::<(f64, f64)>();
let f64_t = get::<f64>();
for field in pos_t.fields() {
    assert_eq!(field.get_type(), &f64_t as &Ty);
}

fn params(&self) -> Params

Iterate over the function signature's parameters

use jit::*;
let sig_t = get::<fn(i32, i32) -> i32>();
let i32_t = get::<i32>();
for param in sig_t.params() {
    assert_eq!(param, &i32_t as &Ty);
}

fn get_field(&self, name: &str) -> Option<Field>

Find the field/parameter index for a particular name.

fn is_primitive(&self) -> bool

Check if this is a primitive

use jit::*;
assert!(get::<i16>().is_primitive());
assert!(!get::<(i16, i16)>().is_primitive());

fn is_float(&self) -> bool

Check if this is a floating-point number

use jit::*;
assert!(get::<f64>().is_float());
assert!(!get::<i16>().is_float());

fn is_int(&self) -> bool

Check if this is an integer

use jit::*;
assert!(get::<i16>().is_int());
assert!(!get::<f32>().is_int());

fn is_struct(&self) -> bool

Check if this is a struct

use jit::*;
assert!(get::<(i16, i16)>().is_struct());

fn is_union(&self) -> bool

Check if this is a union

fn is_signature(&self) -> bool

Check if this is a signature

use jit::*;
assert!(get::<fn(i16) -> i16>().is_signature());

fn is_pointer(&self) -> bool

Check if this is a pointer

use jit::*;
assert!(get::<&'static u8>().is_pointer());

fn is_tagged(&self) -> bool

Check if this is tagged

Trait Implementations

impl Debug for Type

fn fmt(&self, fmt: &mut Formatter) -> Result

impl Borrow<Ty> for Type

fn borrow(&self) -> &Ty

impl From<jit_type_t> for Type

fn from(ptr: jit_type_t) -> Type

impl Clone for Type

fn clone(&self) -> Type

fn clone_from(&mut self, source: &Self)

impl Drop for Type

fn drop(&mut self)

impl<'a> Deref for Type

type Target = Ty

fn deref(&self) -> &Ty

impl<'a> DerefMut for Type

fn deref_mut(&mut self) -> &mut Ty

impl Into<CowType<'static>> for Type

fn into(self) -> CowType<'static>

Derived Implementations

impl Eq for Type

impl PartialEq for Type

fn eq(&self, __arg_0: &Type) -> bool

fn ne(&self, __arg_0: &Type) -> bool