Skip to content

Commit f083d27

Browse files
committed
Name pooling addition #48
1 parent 3670cf6 commit f083d27

File tree

9 files changed

+30
-86
lines changed

9 files changed

+30
-86
lines changed

src/mango/io/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::HashMap;
55

66
// TODO: Use regex! instead of Regex::new to check at compile time. (Also its not on heap). This is actually slower according to 2y old benchmark though. But semantically makes more sense.
77
thread_local!{
8-
static re: Regex = Regex::new("abc");
8+
static re: Regex = Regex::new("abc").unwrap();
99
}
1010

1111
pub struct RegexCache {

src/mango/towasm/scope/function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Parameter {
3737

3838
impl Wasm for Parameter {
3939
fn as_wat(&self) -> String {
40-
format!("(param {} {})", self.name().as_wat(), self.typ().as_wat())
40+
format!("(param {} {})", self.name().borrow().as_wat(), self.typ().as_wat())
4141
}
4242

4343
fn write_wasm(&self, file: &mut File) -> io::Result<()> {
@@ -82,8 +82,8 @@ impl Wasm for FunctionSignature {
8282
fn as_wat(&self) -> String {
8383
format!(
8484
"func {} (export \"{}\") {} {}",
85-
self.name.as_wat(),
86-
self.name.pure_name(),
85+
self.name.borrow().as_wat(),
86+
self.name.borrow().pure_name(),
8787
self.parameters.iter().map(|func| func.as_wat()).collect::<Vec<_>>().join("\n"),
8888
self.results.iter().map(|func| func.as_wat()).collect::<Vec<_>>().join("\n")
8989
)

src/mango/towasm/scope/module.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use mango::towasm::scope::Function;
2-
use mango::towasm::util::NamePool;
2+
use mango::towasm::util::pool::new_name_pool;
3+
use mango::towasm::util::pool::NamePool;
34
use mango::towasm::Wasm;
45
use std::fs::File;
56
use std::io;
@@ -35,7 +36,7 @@ pub struct Scope {
3536

3637
impl Scope {
3738
pub fn new(parent: &mut Scope) -> Self {
38-
let names = NamePool::new(parent.names);
39+
let names = new_name_pool(&mut parent.names);
3940
Scope { names }
4041
}
4142
}

src/mango/towasm/util/anonymous.rs

-45
This file was deleted.

src/mango/towasm/util/given_name.rs

-32
This file was deleted.

src/mango/towasm/util/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
mod name;
99
pub use self::name::{KnownName, Name, PendingName, RawName};
1010

11-
mod pool;
12-
pub use self::pool::NamePool;
11+
pub mod pool;

src/mango/towasm/util/name.rs

+15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ pub enum RawName {
3636
Pending(PendingName),
3737
}
3838

39+
impl RawName {
40+
pub fn resolved(&self) -> &KnownName {
41+
match self {
42+
RawName::Known(name) => &name,
43+
RawName::Pending(name) => {
44+
self = RawName::Known(KnownName {
45+
// TODO: can I just use choose_name, or need pool to take prefix into account? (do I need id in that case?)
46+
name: format!("{}", self.id), // format!("{}{}", name.prefix, 1)
47+
});
48+
&name
49+
}
50+
}
51+
}
52+
}
53+
3954
impl RawName {}
4055

4156
pub type Name = Rc<RefCell<RawName>>;

src/mango/towasm/util/pool.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ impl RawNamePool {
5454

5555
pub type NamePool = Rc<RefCell<RawNamePool>>;
5656

57-
impl NamePool {}
57+
pub fn new_name_pool(parent: &mut NamePool) -> NamePool {
58+
Rc::new(RefCell::new(RawNamePool::new(parent)))
59+
}

src/mango/towasm/util/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
pub fn choose_name(nr: i32) -> String {
3+
4+
}

0 commit comments

Comments
 (0)