Restructuring into multiple crates and projects
This commit is contained in:
14
hm-asm-web/Cargo.toml
Normal file
14
hm-asm-web/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "hm-asm-web"
|
||||
version = "0.1.0"
|
||||
authors = ["Henrik Böving <hargonix@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
hm-asm-simulator = { path = "../hm-asm-simulator", version = "0.1.0" }
|
||||
pest = "2.0"
|
||||
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
||||
20
hm-asm-web/README.md
Normal file
20
hm-asm-web/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# hm-asm-web
|
||||
|
||||
This is a WebAssembly based frontend for `hm-asm-simulator`. It expoes
|
||||
two functions to javascript.
|
||||
- `simulate(code: &str, cycles: usize)`, its return value is equivalent to the one of `hm_asm_simulator::simulate::simulate`
|
||||
- `assemble(code: &str)`, its return vlaue is equivalent to the one of `hm_asm_simulator::generate::generate_binary`
|
||||
|
||||
## Demo
|
||||
In `demo/` You'll find a demo app that compiles and simulates a simple program inside of the console.
|
||||
You can test it with
|
||||
|
||||
- `npm install`
|
||||
- `npm run start`
|
||||
|
||||
Afterwards you can visit the demo at `localhost:8080`.
|
||||
|
||||
## Using it
|
||||
|
||||
You can use this guide https://rustwasm.github.io/docs/book/game-of-life/setup.html
|
||||
to set up your own project. I'm not planning to publish to npm.org at this point.
|
||||
67
hm-asm-web/demo/README.md
Normal file
67
hm-asm-web/demo/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
<div align="center">
|
||||
|
||||
<h1><code>create-wasm-app</code></h1>
|
||||
|
||||
<strong>An <code>npm init</code> template for kick starting a project that uses NPM packages containing Rust-generated WebAssembly and bundles them with Webpack.</strong>
|
||||
|
||||
<p>
|
||||
<a href="https://travis-ci.org/rustwasm/create-wasm-app"><img src="https://img.shields.io/travis/rustwasm/create-wasm-app.svg?style=flat-square" alt="Build Status" /></a>
|
||||
</p>
|
||||
|
||||
<h3>
|
||||
<a href="#usage">Usage</a>
|
||||
<span> | </span>
|
||||
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
|
||||
</h3>
|
||||
|
||||
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
|
||||
</div>
|
||||
|
||||
## About
|
||||
|
||||
This template is designed for depending on NPM packages that contain
|
||||
Rust-generated WebAssembly and using them to create a Website.
|
||||
|
||||
* Want to create an NPM package with Rust and WebAssembly? [Check out
|
||||
`wasm-pack-template`.](https://github.com/rustwasm/wasm-pack-template)
|
||||
* Want to make a monorepo-style Website without publishing to NPM? Check out
|
||||
[`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
|
||||
and/or
|
||||
[`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
|
||||
|
||||
## 🚴 Usage
|
||||
|
||||
```
|
||||
npm init wasm-app
|
||||
```
|
||||
|
||||
## 🔋 Batteries Included
|
||||
|
||||
- `.gitignore`: ignores `node_modules`
|
||||
- `LICENSE-APACHE` and `LICENSE-MIT`: most Rust projects are licensed this way, so these are included for you
|
||||
- `README.md`: the file you are reading now!
|
||||
- `index.html`: a bare bones html document that includes the webpack bundle
|
||||
- `index.js`: example js file with a comment showing how to import and use a wasm pkg
|
||||
- `package.json` and `package-lock.json`:
|
||||
- pulls in devDependencies for using webpack:
|
||||
- [`webpack`](https://www.npmjs.com/package/webpack)
|
||||
- [`webpack-cli`](https://www.npmjs.com/package/webpack-cli)
|
||||
- [`webpack-dev-server`](https://www.npmjs.com/package/webpack-dev-server)
|
||||
- defines a `start` script to run `webpack-dev-server`
|
||||
- `webpack.config.js`: configuration file for bundling your js with webpack
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally
|
||||
submitted for inclusion in the work by you, as defined in the Apache-2.0
|
||||
license, shall be dual licensed as above, without any additional terms or
|
||||
conditions.
|
||||
5
hm-asm-web/demo/bootstrap.js
vendored
Normal file
5
hm-asm-web/demo/bootstrap.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// A dependency graph that contains any wasm must all be imported
|
||||
// asynchronously. This `bootstrap.js` file does the single async import, so
|
||||
// that no one else needs to worry about it again.
|
||||
import("./index.js")
|
||||
.catch(e => console.error("Error importing `index.js`:", e));
|
||||
11
hm-asm-web/demo/index.html
Normal file
11
hm-asm-web/demo/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Hello wasm-pack!</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
|
||||
<script src="./bootstrap.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
9
hm-asm-web/demo/index.js
Normal file
9
hm-asm-web/demo/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as wasm from "hm-asm-web";
|
||||
|
||||
|
||||
console.log("Welcome to hm-asm-web");
|
||||
const code = "LDA #1\nADD #3\nSTA (8)"
|
||||
console.log("Compiling:\n" + code)
|
||||
console.log(wasm.assemble(code));
|
||||
console.log("Simulating for four clock cycles:\n" + code )
|
||||
console.log(wasm.simulate(code, 4));
|
||||
5998
hm-asm-web/demo/package-lock.json
generated
Normal file
5998
hm-asm-web/demo/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
hm-asm-web/demo/package.json
Normal file
39
hm-asm-web/demo/package.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "create-wasm-app",
|
||||
"version": "0.1.0",
|
||||
"description": "create an app to consume rust-generated wasm packages",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"create-wasm-app": ".bin/create-wasm-app.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"start": "webpack-dev-server"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rustwasm/create-wasm-app.git"
|
||||
},
|
||||
"keywords": [
|
||||
"webassembly",
|
||||
"wasm",
|
||||
"rust",
|
||||
"webpack"
|
||||
],
|
||||
"author": "Henrik Boeving",
|
||||
"license": "GPlv3",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rustwasm/create-wasm-app/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rustwasm/create-wasm-app#readme",
|
||||
"dependencies": {
|
||||
"hm-asm-web": "file:../pkg"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hello-wasm-pack": "^0.1.0",
|
||||
"webpack": "^4.29.3",
|
||||
"webpack-cli": "^3.1.0",
|
||||
"webpack-dev-server": "^3.1.5",
|
||||
"copy-webpack-plugin": "^5.0.0"
|
||||
}
|
||||
}
|
||||
14
hm-asm-web/demo/webpack.config.js
Normal file
14
hm-asm-web/demo/webpack.config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: "./bootstrap.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "bootstrap.js",
|
||||
},
|
||||
mode: "development",
|
||||
plugins: [
|
||||
new CopyWebpackPlugin(['index.html'])
|
||||
],
|
||||
};
|
||||
1
hm-asm-web/hm-asm.js
Normal file
1
hm-asm-web/hm-asm.js
Normal file
@@ -0,0 +1 @@
|
||||
import { simulate, assemble } from "./pkg";
|
||||
28
hm-asm-web/src/lib.rs
Normal file
28
hm-asm-web/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use pest::Parser;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use hm_asm_simulator::{
|
||||
generate::generate_binary,
|
||||
parse::{parse_asm, AsmParser, Rule},
|
||||
};
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn simulate(code: &str, cycles: usize) -> JsValue {
|
||||
let instructions = parse_asm(
|
||||
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
|
||||
);
|
||||
let states = hm_asm_simulator::simulate::simulate(instructions, cycles);
|
||||
|
||||
JsValue::from_serde(&states).unwrap()
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn assemble(code: &str) -> JsValue {
|
||||
let instructions = parse_asm(
|
||||
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
|
||||
);
|
||||
let binary = generate_binary(instructions);
|
||||
JsValue::from_serde(&binary).unwrap()
|
||||
}
|
||||
Reference in New Issue
Block a user