-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add no_std support #122
Add no_std support #122
Changes from 9 commits
704f96e
606c006
ffe54f9
f4173ad
33a0e6e
d38d268
3c75f65
3b82da1
99eabd7
86b1d3c
cf67b16
2a6103c
0a0f870
8854754
baa89af
5a54374
21bff51
03d427b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use std::rc::Rc; | ||
use std::cell::Cell; | ||
use alloc::rc::Rc; | ||
use core::cell::Cell; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing we do in Cranelift is to remap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would have made rebasing a lot nicer, too 🙃 |
||
use value::RuntimeValue; | ||
use Error; | ||
use types::ValueType; | ||
|
@@ -13,7 +13,7 @@ use parity_wasm::elements::{ValueType as EValueType}; | |
#[derive(Clone, Debug)] | ||
pub struct GlobalRef(Rc<GlobalInstance>); | ||
|
||
impl ::std::ops::Deref for GlobalRef { | ||
impl ::core::ops::Deref for GlobalRef { | ||
type Target = GlobalInstance; | ||
fn deref(&self) -> &GlobalInstance { | ||
&self.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
use std::u32; | ||
use std::ops::Range; | ||
use std::cmp; | ||
use std::fmt; | ||
use std::rc::Rc; | ||
use std::cell::{Cell, RefCell}; | ||
#[allow(unused_imports)] | ||
use alloc::prelude::*; | ||
use alloc::rc::Rc; | ||
use core::u32; | ||
use core::ops::Range; | ||
use core::cmp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. core imports might be grouped |
||
use core::fmt; | ||
use core::cell::{Cell, RefCell}; | ||
use parity_wasm::elements::ResizableLimits; | ||
use Error; | ||
use memory_units::{RoundUpTo, Pages, Bytes}; | ||
|
@@ -28,7 +30,7 @@ const LINEAR_MEMORY_MAX_PAGES: Pages = Pages(65536); | |
#[derive(Clone, Debug)] | ||
pub struct MemoryRef(Rc<MemoryInstance>); | ||
|
||
impl ::std::ops::Deref for MemoryRef { | ||
impl ::core::ops::Deref for MemoryRef { | ||
type Target = MemoryInstance; | ||
fn deref(&self) -> &MemoryInstance { | ||
&self.0 | ||
|
@@ -172,7 +174,7 @@ impl MemoryInstance { | |
/// Get value from memory at given offset. | ||
pub fn get_value<T: LittleEndianConvert>(&self, offset: u32) -> Result<T, Error> { | ||
let mut buffer = self.buffer.borrow_mut(); | ||
let region = self.checked_region(&mut buffer, offset as usize, ::std::mem::size_of::<T>())?; | ||
let region = self.checked_region(&mut buffer, offset as usize, ::core::mem::size_of::<T>())?; | ||
Ok(T::from_little_endian(&buffer[region.range()]).expect("Slice size is checked")) | ||
} | ||
|
||
|
@@ -216,7 +218,7 @@ impl MemoryInstance { | |
/// Copy value in the memory at given offset. | ||
pub fn set_value<T: LittleEndianConvert>(&self, offset: u32, value: T) -> Result<(), Error> { | ||
let mut buffer = self.buffer.borrow_mut(); | ||
let range = self.checked_region(&mut buffer, offset as usize, ::std::mem::size_of::<T>())?.range(); | ||
let range = self.checked_region(&mut buffer, offset as usize, ::core::mem::size_of::<T>())?.range(); | ||
value.into_little_endian(&mut buffer[range]); | ||
Ok(()) | ||
} | ||
|
@@ -254,7 +256,7 @@ impl MemoryInstance { | |
} | ||
|
||
fn checked_region<B>(&self, buffer: &mut B, offset: usize, size: usize) -> Result<CheckedRegion, Error> | ||
where B: ::std::ops::DerefMut<Target=Vec<u8>> | ||
where B: ::core::ops::DerefMut<Target=Vec<u8>> | ||
{ | ||
let end = offset.checked_add(size) | ||
.ok_or_else(|| Error::Memory(format!("trying to access memory block of size {} from offset {}", size, offset)))?; | ||
|
@@ -275,7 +277,7 @@ impl MemoryInstance { | |
|
||
fn checked_region_pair<B>(&self, buffer: &mut B, offset1: usize, size1: usize, offset2: usize, size2: usize) | ||
-> Result<(CheckedRegion, CheckedRegion), Error> | ||
where B: ::std::ops::DerefMut<Target=Vec<u8>> | ||
where B: ::core::ops::DerefMut<Target=Vec<u8>> | ||
{ | ||
let end1 = offset1.checked_add(size1) | ||
.ok_or_else(|| Error::Memory(format!("trying to access memory block of size {} from offset {}", size1, offset1)))?; | ||
|
@@ -314,7 +316,7 @@ impl MemoryInstance { | |
|
||
let (read_region, write_region) = self.checked_region_pair(&mut buffer, src_offset, len, dst_offset, len)?; | ||
|
||
unsafe { ::std::ptr::copy( | ||
unsafe { ::core::ptr::copy( | ||
buffer[read_region.range()].as_ptr(), | ||
buffer[write_region.range()].as_ptr() as *mut _, | ||
len, | ||
|
@@ -343,7 +345,7 @@ impl MemoryInstance { | |
return Err(Error::Memory(format!("non-overlapping copy is used for overlapping regions"))) | ||
} | ||
|
||
unsafe { ::std::ptr::copy_nonoverlapping( | ||
unsafe { ::core::ptr::copy_nonoverlapping( | ||
buffer[read_region.range()].as_ptr(), | ||
buffer[write_region.range()].as_ptr() as *mut _, | ||
len, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those comments outdated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. They match the readme section about
no_std
.