File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ use crate::token::Tokenizer;
44
55use std:: iter:: Peekable ;
66
7- pub type Bindings = [ String ] ; // vars
7+ pub struct Bindings {
8+ pub vars : Vec < String > ,
9+ }
10+
811pub type Wat = String ;
912pub 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}'" ) ;
Original file line number Diff line number Diff line change @@ -47,7 +47,8 @@ fn eval_wat(expr: &Expr) -> Result<i32> {
4747}
4848
4949fn 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) ?;
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ use std::str::Chars;
33
44#[ derive( Debug , PartialEq ) ]
55pub 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
You can’t perform that action at this time.
0 commit comments