staging for wasm

This commit is contained in:
damirka 2021-09-16 17:20:37 +03:00
parent 49a1ffbdff
commit 63cc0b7d05
5 changed files with 107 additions and 1 deletions

13
Cargo.lock generated
View File

@ -1449,6 +1449,19 @@ dependencies = [
"structopt",
]
[[package]]
name = "leo-wasm"
version = "1.5.3"
dependencies = [
"leo-asg",
"leo-ast",
"leo-ast-passes",
"leo-errors",
"leo-parser",
"serde",
"wasm-bindgen",
]
[[package]]
name = "lexical-core"
version = "0.7.6"

View File

@ -40,7 +40,8 @@ members = [
"parser",
"state",
"synthesizer",
"test-framework"
"test-framework",
"wasm"
]
[dependencies.leo-ast]

1
wasm/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
pkg

54
wasm/Cargo.toml Normal file
View File

@ -0,0 +1,54 @@
[package]
name = "leo-wasm"
authors = [ "The Aleo Team <hello@aleo.org>" ]
description = "Leo compiler as WASM"
version = "1.5.3"
edition = "2018"
homepage = "https://aleo.org"
repository = "https://github.com/AleoHQ/leo"
keywords = [
"aleo",
"cryptography",
"leo",
"programming-language",
"zero-knowledge",
"wasm"
]
categories = [ "cryptography::cryptocurrencies", "web-programming" ]
include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies.leo-parser]
version = "1.5.3"
path = "../parser"
[dependencies.leo-errors]
version = "1.5.3"
path = "../errors"
[dependencies.leo-asg]
version = "1.5.3"
path = "../asg"
[dependencies.leo-ast]
version = "1.5.3"
path = "../ast"
[dependencies.leo-ast-passes]
version = "1.5.3"
path = "../ast-passes"
[dependencies.serde]
version = "1.0"
features = [ "derive" ]
[dependencies.wasm-bindgen]
version = "0.2"
# Crate metadata
[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

37
wasm/src/lib.rs Normal file
View File

@ -0,0 +1,37 @@
// Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
// Currently does not support crate `leo-compiler` because it has a dependency in its tree
// which is not wasm compatible. All compiler passes (such as TypeInference)
use leo_ast::AstPass;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(method, catch)]
pub fn parse(program: &str) -> Result<String, JsValue> {
Ok(parse_program(program).map_err(|err| JsValue::from_str(&err.to_string()))?)
}
/// Parse the program and pass the Canonicalization phase;
/// Asg is useless without compiler passes, so we need to add them once the compatibility problem in
/// snarkvm is solved.
fn parse_program(program: &str) -> leo_errors::Result<String> {
let ast = leo_parser::parse_ast("", program)?;
let ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?.to_json_string()?;
Ok(ast)
}