Skip to content

porcelijn/wasm-expr-eval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WASM Expression Evaluator

License: NON-AI-CC0

A minimalist experiment messing around with WASM code generation and expression parsing in Rust.

cargo build
cargo run -- '1+2' '1+x*3' '(x+4) * 2' '(x*x - 10)/3'

With $x = 7 currently hard-code, we get:

Expression:     1+2
Tokenized:      [Number(1), Operator('+'), Number(2)]
WASM Text:      i32.const 1
                i32.const 2
                i32.add
Text result:    3
Binary result:  3

Expression:     1+x*3
Tokenized:      [Number(1), Operator('+'), Variable("x"), Operator('*'), Number(3)]
WASM Text:      i32.const 1
                local.get $x
                i32.const 3
                i32.mul
                i32.add
Text result:    22
Binary result:  22

Expression:     (x+4)*2
Tokenized:      [Open('('), Variable("x"), Operator('+'), Number(4), Close(')'), Operator('*'), Number(2)]
WASM Text:      local.get $x
                i32.const 4
                i32.add
                i32.const 2
                i32.mul
Text result:    22
Binary result:  22

Expression:     (x*x-10)/3
Tokenized:      [Open('('), Variable("x"), Operator('*'), Variable("x"), Operator('-'), Number(10), Close(')'), Operator('/'), Number(3)]
WASM Text:      local.get $x
                local.get $x
                i32.mul
                i32.const 10
                i32.sub
                i32.const 3
                i32.div_u
Text result:    13
Binary result:  13

About

Messing around with WASM runtime, parsing and code generation (downstream from codeberg)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages