-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed compilation without "wasm-bindgen" feature (#236)
* Fixed compilation without "wasm-bindgen" feature * updating clippy rules on all files (#238) * Fixed compilation without "wasm-bindgen" feature Co-authored-by: Jason Williams <936006+jasonwilliams@users.noreply.github.com>
- Loading branch information
1 parent
33490e1
commit 6947122
Showing
2 changed files
with
51 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{ | ||
exec::{Executor, Interpreter}, | ||
realm::Realm, | ||
syntax::{ast::expr::Expr, lexer::Lexer, parser::Parser}, | ||
}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
// WASM | ||
#[wasm_bindgen] | ||
extern "C" { | ||
// Use `js_namespace` here to bind `console.log(..)` instead of just | ||
// `log(..)` | ||
#[wasm_bindgen(js_namespace = console)] | ||
fn log(s: &str); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn evaluate(src: &str) -> String { | ||
let mut lexer = Lexer::new(&src); | ||
match lexer.lex() { | ||
Ok(_v) => (), | ||
Err(v) => log(&v.to_string()), | ||
} | ||
|
||
let tokens = lexer.tokens; | ||
|
||
// Setup executor | ||
let expr: Expr; | ||
|
||
match Parser::new(tokens).parse_all() { | ||
Ok(v) => { | ||
expr = v; | ||
} | ||
Err(_v) => { | ||
log("parsing fail"); | ||
return String::from("parsing failed"); | ||
} | ||
} | ||
// Create new Realm | ||
let realm = Realm::create(); | ||
let mut engine: Interpreter = Executor::new(realm); | ||
let result = engine.run(&expr); | ||
match result { | ||
Ok(v) => v.to_string(), | ||
Err(v) => format!("{}: {}", "error", v.to_string()), | ||
} | ||
} |