Skip to content

Commit 31d49a0

Browse files
committed
Preliminary commit
1 parent 599f395 commit 31d49a0

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/target
3+
**/*.rs.bk
4+
Cargo.lock

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "nebulet_abi"
3+
version = "0.1.0"
4+
license = "MIT"
5+
authors = ["Lachlan Sneff <[email protected]>"]
6+
7+
[lib]
8+
name = "abi"
9+
10+
[dependencies]

src/call.rs

Whitespace-only changes.

src/error.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use core::{fmt, result};
2+
use core::option::NoneError;
3+
4+
pub type Result<T> = result::Result<T, Error>;
5+
6+
#[derive(Eq, PartialEq)]
7+
pub struct Error {
8+
pub errno: i32,
9+
}
10+
11+
impl Error {
12+
pub fn new(errno: i32) -> Error {
13+
Error {
14+
errno: errno,
15+
}
16+
}
17+
18+
pub fn mux(result: Result<usize>) -> usize {
19+
match result {
20+
Ok(value) => value,
21+
Err(error) => -error.errno as usize,
22+
}
23+
}
24+
25+
pub fn demux(value: usize) -> Result<usize> {
26+
let errno = -(value as i32);
27+
if errno > 0 && errno < ERROR_STR.len() as i32 {
28+
Err(Error::new(errno))
29+
} else {
30+
Ok(value)
31+
}
32+
}
33+
34+
pub fn text(&self) -> &str {
35+
if let Some(desc) = ERROR_STR.get(self.errno as usize) {
36+
desc
37+
} else {
38+
"Unknown error"
39+
}
40+
}
41+
}
42+
43+
impl fmt::Debug for Error {
44+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45+
f.write_str(self.text())
46+
}
47+
}
48+
49+
impl fmt::Display for Error {
50+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51+
f.write_str(self.text())
52+
}
53+
}
54+
55+
impl From<NoneError> for Error {
56+
fn from(error: NoneError) -> Error {
57+
Error::new(-1)
58+
}
59+
}
60+
61+
pub const EPERM: i32 = 1; // Operation not permitted
62+
/// ...
63+
/// TODO: Add more errors
64+
65+
pub static ERROR_STR: [&'static str; 2] = [
66+
"Success",
67+
"Operation not permitted",
68+
];

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_std]
2+
#![feature(try_trait)]
3+
4+
pub use self::call::*;
5+
pub use self::error::*;
6+
7+
/// ABI calls
8+
pub mod call;
9+
10+
/// All the errors that can be generated by abi calls
11+
pub mod error;

0 commit comments

Comments
 (0)