77 lines
2.7 KiB
Rust
77 lines
2.7 KiB
Rust
use crate::runtime::{Reference, type_key};
|
|
use crate::tag;
|
|
|
|
mod builder; pub use builder::*;
|
|
mod util; pub use util::*;
|
|
|
|
mod varying; pub use varying::Varying;
|
|
mod boolean; pub use boolean::Boolean;
|
|
mod natural; pub use natural::Natural;
|
|
mod integer; pub use integer::Integer;
|
|
mod decimal; pub use decimal::Decimal;
|
|
mod signficant; pub use signficant::Significant;
|
|
mod block; pub use block::Block;
|
|
mod sequence; pub use sequence::Sequence;
|
|
mod array; pub use array::Array;
|
|
mod list; pub use list::List;
|
|
mod sparse; pub use sparse::Sparse;
|
|
mod schema; pub use schema::Schema;
|
|
mod record; pub use record::Record;
|
|
|
|
pub enum Object {
|
|
Null,
|
|
Varying(Varying),
|
|
Boolean(Boolean),
|
|
Natural(Natural),
|
|
Integer(Integer),
|
|
Decimal(Decimal),
|
|
Significant(Significant),
|
|
Block(Block),
|
|
Sequence(Sequence),
|
|
Array(Array),
|
|
List(List),
|
|
Sparse(Sparse),
|
|
Record(Record),
|
|
Schema(Schema),
|
|
}
|
|
impl Object {
|
|
pub fn from(addr:Reference) -> Self
|
|
{
|
|
match unsafe {type_key(addr.class)} {
|
|
tag::NULL => Object::Null,
|
|
tag::VARYING => Object::Varying(Varying::try_from(addr).unwrap()),
|
|
tag::BOOLEAN => Object::Boolean(Boolean::try_from(addr).unwrap()),
|
|
tag::NATURAL => Object::Natural(Natural::try_from(addr).unwrap()),
|
|
tag::INTEGER => Object::Integer(Integer::try_from(addr).unwrap()),
|
|
tag::DECIMAL => Object::Decimal(Decimal::try_from(addr).unwrap()),
|
|
tag::SIGNIFICANT => Object::Significant(Significant::try_from(addr).unwrap()),
|
|
tag::BLOCK => Object::Block(Block::try_from(addr).unwrap()),
|
|
tag::SEQUENCE => Object::Sequence(Sequence::try_from(addr).unwrap()),
|
|
tag::ARRAY => Object::Array(Array::try_from(addr).unwrap()),
|
|
tag::LIST => Object::List(List::try_from(addr).unwrap()),
|
|
tag::SPARSE => Object::Sparse(Sparse::try_from(addr).unwrap()),
|
|
tag::RECORD => Object::Record(Record::try_from(addr).unwrap()),
|
|
_ => Object::Null,
|
|
}
|
|
}
|
|
|
|
pub fn get(&self) -> Reference
|
|
{
|
|
match &self {
|
|
Object::Varying(obj) => **obj,
|
|
Object::Boolean(obj) => **obj,
|
|
Object::Natural(obj) => **obj,
|
|
Object::Integer(obj) => **obj,
|
|
Object::Decimal(obj) => **obj,
|
|
Object::Significant(obj) => **obj,
|
|
Object::Block(obj) => **obj,
|
|
Object::Sequence(obj) => **obj,
|
|
Object::Array(obj) => **obj,
|
|
Object::List(obj) => **obj,
|
|
Object::Sparse(obj) => **obj,
|
|
Object::Record(obj) => **obj,
|
|
_ => Reference::null(),
|
|
}
|
|
}
|
|
}
|