remove unused wasm package

This commit is contained in:
collin 2022-07-12 16:31:19 -07:00
parent a9992bc6d4
commit ca0c34ea42
9 changed files with 0 additions and 400 deletions

View File

@ -1 +0,0 @@
pkg

View File

@ -1,54 +0,0 @@
[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-ast]
path = "../ast"
version = "1.5.3"
[dependencies.leo-ast-passes]
path = "../ast-passes"
version = "1.5.3"
[dependencies.leo-errors]
path = "../../leo/errors"
version = "1.5.3"
[dependencies.leo-parser]
path = "../parser"
version = "1.5.3"
[dependencies.serde]
version = "1.0"
features = [ "derive" ]
[dependencies.serde_json]
version = "1.0"
[dependencies.wasm-bindgen]
version = "0.2"
features = [ "serde-serialize" ]
# Crate metadata
[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

View File

@ -1,34 +0,0 @@
# Leo WASM
<!-- [![Crates.io](https://img.shields.io/crates/v/leo-wasm.svg?color=neon)](https://crates.io/crates/leo-wasm) -->
[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS)
[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md)
This directory contains WASM bindings for the Leo compiler.
## Limitations
Currently, WASM target of the compiler supports parsing and canonicalization stages.
## API
This is a list of the supported methods and their signatures.
### leo.parse
Method takes in a Leo program as string and returns JSON string with the resulting AST or throws a LeoError.
```ts
export interface LeoError {
text: string, // Full error text (including span)
code: string, // Leo error identifier (e.g. "EPAR0370005")
exitCode: number // Exit code for an error (e.g. 370005)
}
/**
* @param {String} program Leo program text to parse and produce AST
* @return {String} Resulting AST as a JSON string.
* @throws {LeoError} When program contains invalid Leo code.
*/
export function parse(program: string): string;
```

View File

@ -1,56 +0,0 @@
// Copyright (C) 2019-2022 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 leo_errors::LeoError;
use serde_json::json;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
export interface LeoError { text: string, code: string, exitCode: number }
"#;
/// Publicly accessible method.
/// Parse the code and return an AST as JSON or an error object.
#[wasm_bindgen(method, catch)]
pub fn parse(program: &str) -> Result<String, JsValue> {
parse_program(program).map_err(error_to_value)
}
/// 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)
}
/// Make a pretty-print JS object for the thrown error.
fn error_to_value(err: LeoError) -> JsValue {
JsValue::from_serde(&json!({
"error": err.to_string(),
"code": err.error_code(),
"exitCode": err.exit_code()
}))
.expect("Unable to create an error object from JSON")
}

View File

@ -1 +0,0 @@
node_modules

View File

@ -1,36 +0,0 @@
{
"name": "parser-wasm-tests",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/js-yaml": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.3.tgz",
"integrity": "sha512-5t9BhoORasuF5uCPr+d5/hdB++zRFUTMIZOzbNkr+jZh3yQht4HYbRDyj9fY8n2TZT30iW9huzav73x4NikqWg=="
},
"@types/node": {
"version": "16.9.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.4.tgz",
"integrity": "sha512-KDazLNYAGIuJugdbULwFZULF9qQ13yNWEBFnfVpqlpgAAo6H/qnM9RjBgh0A0kmHf3XxAKLdN5mTIng9iUvVLA=="
},
"argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"requires": {
"argparse": "^2.0.1"
}
},
"typescript": {
"version": "3.9.10",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q=="
}
}
}

View File

@ -1,26 +0,0 @@
{
"name": "parser-wasm-tests",
"version": "0.1.0",
"description": "Test Framework implementation for compiler tests in WASM",
"main": "dist/index.js",
"scripts": {
"compile": "tsc -p ./",
"test": "npm run compile && node dist/index.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/aleohq/leo.git"
},
"author": "The Aleo Team <hello@aleo.org>",
"license": "GNU",
"bugs": {
"url": "https://github.com/aleohq/leo/issues"
},
"homepage": "https://github.com/aleohq/leo#readme",
"dependencies": {
"@types/js-yaml": "^4.0.3",
"@types/node": "^16.9.4",
"js-yaml": "^4.1.0",
"typescript": "^3.9.10"
}
}

View File

@ -1,179 +0,0 @@
// Copyright (C) 2019-2022 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/>.
import * as fs from 'fs';
import * as path from 'path';
import * as leo from '../../pkg/leo_wasm';
import * as yaml from 'js-yaml';
// Path to the parser tests folder
const TESTS_PATH: string = path.join(__dirname, '../../../tests/parser');
// Path to the test expectations for parser tests
const EXPECTATIONS_PATH: string = path.join(__dirname, '../../../tests/expectations/parser/parser');
// List of folders containing parser tests
const TEST_FOLDERS: string[] = fs.readdirSync(TESTS_PATH);
// Test expectations enum, maps to string values: Pass and Fail
enum Expectation {
Pass = "Pass",
Fail = "Fail"
}
interface TestHeader {
expectation: Expectation,
namespace: string
}
interface TestResult {
filePath: string,
expectation: Expectation,
received: Expectation,
error: string|null
}
// Main function for the tests
(function runTests() {
let results: TestResult[] = [];
for (let folder of TEST_FOLDERS) {
results.push(...walkDir(folder));
}
if (results.length !== 0) {
results.forEach((result) => {
console.log(
'Test failed. Path: %s; Expected: %s; Received: %s',
result.filePath,
result.expectation,
result.received
);
});
process.exit(1);
} else {
console.log('All tests successfully passed.');
process.exit(0);
}
})();
/**
* Test specific file an compare its outputs to the test expectations.
*
* @param filePath Path to the tested file
* @param outFile Contents of the expectation file of there is one
* @returns {TestResult[]} Tests that failed execution, empty means success
*/
function test(filePath: string, outFile: string|null): TestResult[] {
const text = fs.readFileSync(filePath).toString();
// Process the test's contents by cutting off the header
const header = text.slice(text.indexOf('/*') + 2, text.indexOf('*/'));
const testBody = text.slice(text.indexOf('*/') + 2);
const {expectation /* , namespace */} = readHeader(header);
const mismatches: TestResult[] = [];
const outputs: string[] = [];
// Get the tests by splitting by 2 newlines and sanitize each sample.
const samples = testBody
.split('\n\n')
.map((el) => el.trim())
.filter((el) => el.length !== 0);
// Go through each test and run WASM parse function. Check the results agains expectations
// and collect outputs to later compare to saved .out expectations.
for (const sample of samples) {
try {
outputs.push(JSON.parse(leo.parse(sample))); // Parser outputs JSON
if (expectation === Expectation.Fail) { // If expectation was Fail and it passed
mismatches.push({
filePath,
expectation: Expectation.Fail,
received: Expectation.Pass,
error: null
});
}
} catch (error) {
outputs.push(error.toString());
if (expectation === Expectation.Pass) { // If expectation was Pass and it failed
mismatches.push({
error,
filePath,
expectation: Expectation.Pass,
received: Expectation.Fail,
});
}
}
}
// Todo: After AST spans are removed, figure out a way to canonicalize strings
// and get them to the same format as serde's. For now comparing the outputs as
// strings is impossible.
//
// const formedOut = yaml.dump({
// expectation: expectation,
// namespace: namespace,
// outputs: outputs
// }, {schema: DEFAULT_SCHEMA});
return mismatches;
}
/**
* Recursively go through each directory. If a file is met,
* then run test function for this file.
*
* @param fileOrDir
*/
function walkDir(fileOrDir: string): TestResult[] {
const currTarget = path.join(TESTS_PATH, fileOrDir);
let results: TestResult[] = []; // collect test results from sub calls
if (fs.lstatSync(currTarget).isDirectory()) {
for (const entry of fs.readdirSync(currTarget)) {
results.push(...walkDir(path.join(fileOrDir, entry)));
}
} else {
const outFilePath = path.join(EXPECTATIONS_PATH, fileOrDir + '.out');
const outFile = fs.existsSync(outFilePath) ? fs.readFileSync(outFilePath).toString() : null;
return results.concat(test(currTarget, outFile));
}
return results;
}
/**
* Read a test header yaml and transform it into an Object.
*
* @param header
* @returns {TestHeader}
*/
function readHeader(header: string): TestHeader {
const parsed: any = yaml.load(header);
if (!parsed || parsed.constructor !== Object) {
throw "Unable to read test expectations: " + header;
}
return {
expectation: parsed.namespace,
namespace: parsed.expectation,
};
}

View File

@ -1,13 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2019",
"allowJs": true,
"lib": ["ES2019"],
"outDir": "dist",
"sourceMap": true,
"strict": true
},
"exclude": ["node_modules", ".vscode-test"],
"include": ["./src/**/*"]
}