Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
WIP some changes, unsure how to go about something
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasky committed May 16, 2016
1 parent 821419a commit 637bb83
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
3 changes: 3 additions & 0 deletions kernel_serialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ authors = ["Jerome Rasky <jyrome.112@gmail.com>"]

[dependencies]
uuid = "*"
byteorder = { version = "*", deafult-features = false }
serde = { version = "*", git = "https://github.com/serde-rs/serde", default-features = false, features = ["collections"] }
serde_marcos = { version = "*", git = "https://github.com/serde-rs/serde" }
log = { path = "../log" }
constants = { path = "../constants" }
24 changes: 2 additions & 22 deletions kernel_serialize/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use uuid::Uuid;

use collections::{String, Vec};

use serde::{Serialize, Deserialize};

use super::{Resource, ResourceData};

#[derive(Debug, Clone, Copy)]
Expand All @@ -14,37 +16,15 @@ pub enum ProgramType {
}

pub struct Program {
id: Uuid,
variant: ProgramType,
base: Option<u64>,
align: u64,
bytes: Vec<u8>
}

pub struct Symbol {
id: Uuid,
name: String,
version: u64,
program: Resource<Program>,
offset: u64,
}

impl ResourceData for Program {
fn ty() -> Uuid {
Uuid::from_str("64ca5221-56e9-413b-8f3d-debf832d5d38").unwrap()
}

fn id(&self) -> Option<Uuid> {
Some(self.id)
}
}

impl ResourceData for Symbol {
fn ty() -> Uuid {
Uuid::from_str("18cf39e6-4507-4108-92cb-4b16f916bfda").unwrap()
}

fn id(&self) -> Option<Uuid> {
Some(self.id)
}
}
44 changes: 27 additions & 17 deletions kernel_serialize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![feature(custom_derive)]
#![feature(plugin)]
#![feature(collections)]
#![feature(alloc)]
#![feature(coerce_unsized)]
#![feature(raw)]
#![feature(unsize)]
#![plugin(serde_macros)]
#![no_std]
extern crate core as std;
extern crate constants;
Expand All @@ -11,6 +14,8 @@ extern crate log;
extern crate uuid;
extern crate collections;
extern crate alloc;
extern crate serde;
extern crate byteorder;

use std::any::Any;

Expand All @@ -30,42 +35,47 @@ use std::char;

use uuid::Uuid;

use serde::{Serialize, Deserialize};

pub use executable::*;

mod executable;

pub struct Resource<T: ResourceData + ?Sized> {
inner: Arc<RefCell<T>>
pub struct Resource<T: Data + ?Sized> {
id: Uuid,
inner: Option<Arc<RefCell<T>>>
}

pub trait ResourceData: Any {
pub trait Data: Any + Serialize + Deserialize {
fn ty() -> Uuid;

fn id(&self) -> Option<Uuid> {
None
}
}

impl<T: ?Sized + ResourceData + Unsize<U>, U: ?Sized + ResourceData> CoerceUnsized<Resource<U>> for Resource<T> {}

impl<T: ?Sized + ResourceData> Deref for Resource<T> {
type Target = RefCell<T>;
pub trait Group: Data {

}

fn deref(&self) -> &RefCell<T> {
&self.inner
impl<T: ?Sized + Data> Serialize for Resource {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer {
if let Some(id) = self.id() {
id.serialize(serializer)
} else {
Err(S::Error::custom("Resource cannot be serialized"))
}
}
}

impl<T: ResourceData> Clone for Resource<T> {
impl<T: Data> Clone for Resource<T> {
fn clone(&self) -> Self {
Resource {
id: self.id,
inner: self.inner.clone()
}
}
}

impl<T: ?Sized + ResourceData> Resource<T> {
pub fn downcast<U: ResourceData>(self) -> Result<Resource<U>, Self> {
impl<T: ?Sized + Data> Resource<T> {
pub fn downcast<U: Data>(self) -> Result<Resource<U>, Self> {
if Any::is::<Resource<U>>(&self) {
unsafe {
let raw: TraitObject = mem::transmute(&self as &Any);
Expand All @@ -77,7 +87,7 @@ impl<T: ?Sized + ResourceData> Resource<T> {
}
}

impl<T: ResourceData> Resource<T> {
impl<T: Data> Resource<T> {
pub fn new(data: T) -> Resource<T> {
Resource {
inner: Arc::new(RefCell::new(data))
Expand Down
8 changes: 8 additions & 0 deletions kernel_std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ mod include;
mod allocator;
mod map;

pub trait Error: Debug + Display + Reflect {
fn descripton(&self) -> &str;

fn cause(&self) -> Option<&Error> {
None
}
}

#[derive(Debug)]
pub struct MemoryInfo {
pub available: Vec<Region>,
Expand Down

0 comments on commit 637bb83

Please sign in to comment.