-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
- Loading branch information
1 parent
64606e0
commit 54c1b75
Showing
11 changed files
with
141 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::Result; | ||
use alloc::{ | ||
collections::BTreeMap, | ||
string::{String, ToString}, | ||
}; | ||
use tinywasm_types::{Global, GlobalType, WasmValue}; | ||
|
||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
/// An external value | ||
pub enum Extern { | ||
/// A global value | ||
Global(Global), | ||
// Func(HostFunc), | ||
// Table(Table), | ||
} | ||
|
||
impl Extern { | ||
/// Create a new global import | ||
pub fn global(val: WasmValue, mutable: bool) -> Self { | ||
Self::Global(Global { | ||
ty: GlobalType { | ||
ty: val.val_type(), | ||
mutable, | ||
}, | ||
init: val.const_instr(), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] | ||
/// Name of an import | ||
pub struct ExternName { | ||
module: String, | ||
name: String, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
/// Imports for a module instance | ||
pub struct Imports { | ||
values: BTreeMap<ExternName, Extern>, | ||
} | ||
|
||
impl Imports { | ||
/// Create a new empty import set | ||
pub fn new() -> Self { | ||
Imports { | ||
values: BTreeMap::new(), | ||
} | ||
} | ||
|
||
/// Define an import | ||
pub fn define(&mut self, module: &str, name: &str, value: Extern) -> Result<&mut Self> { | ||
self.values.insert( | ||
ExternName { | ||
module: module.to_string(), | ||
name: name.to_string(), | ||
}, | ||
value, | ||
); | ||
Ok(self) | ||
} | ||
|
||
pub(crate) fn get(&self, module: &str, name: &str) -> Option<&Extern> { | ||
self.values.get(&ExternName { | ||
module: module.to_string(), | ||
name: name.to_string(), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.