Skip to content

Commit 83bd5a9

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents e5e1a19 + e5cf6b3 commit 83bd5a9

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/ast.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::token::Tokenizer;
44

55
use std::iter::Peekable;
66

7-
pub type Bindings = [String]; // vars
7+
pub struct Bindings {
8+
pub vars: Vec<String>,
9+
}
10+
811
pub type Wat = String;
912
pub type Wasm = Vec<u8>;
1013

@@ -163,7 +166,7 @@ impl ToWasm for Factor {
163166
},
164167
Self::Param(p) => {
165168
let mut out = vec![0x20]; // local.get
166-
if let Some(index) = bindings.iter().position(|b| b == p) {
169+
if let Some(index) = bindings.vars.iter().position(|b| b == p) {
167170
write_leb128(index as i128, &mut out);
168171
} else {
169172
panic!("Unknown binding for local '{p}'");

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fn eval_wat(expr: &Expr) -> Result<i32> {
4747
}
4848

4949
fn eval_wasm(expr: &Expr) -> Result<i32>{
50-
let bindings: &Bindings = &[ "x".to_string(), "yy".to_string() ];
50+
let vars = vec![ "x".to_string(), "yy".to_string() ];
51+
let bindings: &Bindings = &Bindings { vars };
5152
let wasm = generate_wasm(expr, bindings);
5253
let engine = Engine::default();
5354
let module = Module::new(&engine, wasm)?;

src/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::str::Chars;
33

44
#[derive(Debug,PartialEq)]
55
pub enum Token {
6+
Close(char),
67
Number(i32),
7-
Operator(char),
88
Open(char),
9-
Close(char),
9+
Operator(char),
1010
Variable(String),
1111
}
1212

0 commit comments

Comments
 (0)