Skip to content

Commit a8854f8

Browse files
Update main.rs
1 parent e8a3742 commit a8854f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
println!("{}", output.unwrap());
1212
}
1313

14+
#[derive(Clone)]
1415
struct Compiler {
1516
lambda_id: usize,
1617
heap_addr: usize,
@@ -19,17 +20,20 @@ struct Compiler {
1920
}
2021

2122
impl Compiler {
23+
fn new() -> Self {
24+
Compiler {
25+
lambda_id: 0,
26+
heap_addr: 0,
27+
functions: Vec::new(),
28+
variables: IndexMap::new(),
29+
}
30+
}
2231
fn build(code: &str) -> Option<String> {
2332
let expr = tokenize(code)?
2433
.iter()
2534
.map(|code| Expr::parse(code))
2635
.collect::<Option<Vec<_>>>()?;
27-
let mut compiler = Compiler {
28-
lambda_id: 0,
29-
heap_addr: 0,
30-
functions: Vec::new(),
31-
variables: IndexMap::new(),
32-
};
36+
let mut compiler = Compiler::new();
3337
let code = expr
3438
.iter()
3539
.map(|x| x.compile(&mut compiler))

0 commit comments

Comments
 (0)