feat: some moving around
This commit is contained in:
@@ -18,6 +18,8 @@ wasm-bindgen = "0.2.84"
|
||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||
# code size when deploying.
|
||||
utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
web-sys = { version = "0.3.69", features = ["console"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
|
||||
10
nodes/max/plantarium/array/src/input.json
Normal file
10
nodes/max/plantarium/array/src/input.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"value": {
|
||||
"type": "float",
|
||||
"value": 4.2
|
||||
},
|
||||
"amount": {
|
||||
"type": "integer",
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,33 @@
|
||||
use macros::generate_input_types_file;
|
||||
use utils::{evaluate_args, generate_outputs, get_args};
|
||||
use wasm_bindgen::prelude::*;
|
||||
// use web_sys::console;
|
||||
|
||||
// lifted from the `console_log` example
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
}
|
||||
generate_outputs!(["float"]);
|
||||
|
||||
generate_input_types_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
utils::set_panic_hook();
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
r#"{
|
||||
"length": { "type": "float", "value": 2 }
|
||||
}"#
|
||||
.to_string()
|
||||
}
|
||||
let args = get_args(input);
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(var_length: i32) -> Vec<f64> {
|
||||
let value_encoded = evaluate_args(args[0]);
|
||||
// let value = decode_float(value_encoded[0], value_encoded[1]);
|
||||
let length = args[1];
|
||||
|
||||
let length = var_length;//evaluate_parameters(var_length);
|
||||
// console::log_1(&format!("WASM(array_node): args {:?} ", args).into());
|
||||
// console::log_1(&format!("WASM(array_node): value: {:?} length: {:?}", value, length).into());
|
||||
|
||||
// construct array of length
|
||||
let mut res = Vec::new();
|
||||
for _ in 0..length as usize {
|
||||
res.push(2.0);
|
||||
let mut res: Vec<i32> = Vec::with_capacity(length[0] as usize * 2 + 2);
|
||||
res.push(0);
|
||||
res.push((length[0]) * 2 + 2);
|
||||
for _ in 0..length[0] as usize {
|
||||
res.push(value_encoded[0]);
|
||||
res.push(value_encoded[1])
|
||||
}
|
||||
|
||||
log("executing array");
|
||||
|
||||
res
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ wasm-bindgen = "0.2.84"
|
||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||
# code size when deploying.
|
||||
utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
|
||||
7
nodes/max/plantarium/float/src/input.json
Normal file
7
nodes/max/plantarium/float/src/input.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"value": {
|
||||
"type": "float",
|
||||
"value": 0.1,
|
||||
"internal": true
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
use macros::generate_input_types_file;
|
||||
use utils::generate_outputs;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
r#"{
|
||||
"value": { "type": "float", "value": 0.1, "internal": true }
|
||||
}"#
|
||||
.to_string()
|
||||
}
|
||||
generate_outputs!(["float"]);
|
||||
generate_input_types_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
|
||||
@@ -16,6 +16,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
web-sys = { version = "0.3.69", features = ["console"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
27
nodes/max/plantarium/math/src/input.json
Normal file
27
nodes/max/plantarium/math/src/input.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"op_type": {
|
||||
"label": "type",
|
||||
"type": "select",
|
||||
"labels": [
|
||||
"add",
|
||||
"subtract",
|
||||
"multiply",
|
||||
"divide"
|
||||
],
|
||||
"internal": true,
|
||||
"value": 0
|
||||
},
|
||||
"a": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"b": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"clip": {
|
||||
"type": "boolean",
|
||||
"value": 0,
|
||||
"setting": "math.clipping"
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,13 @@
|
||||
use macros::generate_input_types_file;
|
||||
use utils::generate_outputs;
|
||||
use wasm_bindgen::prelude::*;
|
||||
// use web_sys::console;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
generate_outputs!(["float"]);
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
r#"{
|
||||
"op_type": { "label": "type", "type": "select", "labels": ["add", "subtract", "multiply", "divide"], "internal": true, "value": 0 },
|
||||
"a": { "type": "float", "value": 2 },
|
||||
"b": { "type": "float", "value": 2 }
|
||||
}"#.to_string()
|
||||
}
|
||||
generate_input_types_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
// let d = args
|
||||
// .iter()
|
||||
// .map(|&num| num.to_string()) // Convert each integer to a String
|
||||
// .collect::<Vec<String>>() // Collect all Strings into a Vec
|
||||
// .join(","); // Join all Strings in the Vec with a dot
|
||||
// console::log_1(&format!("Math: {:?}", d).into());
|
||||
|
||||
let mut result = Vec::with_capacity(args.len() + 3);
|
||||
result.push(0); // encoding the [ bracket
|
||||
result.push(args[1] + 1);
|
||||
@@ -31,6 +15,5 @@ pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
result.extend_from_slice(&args[2..]);
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn get_input_types() -> String {
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
// utils::set_panic_hook();
|
||||
utils::set_panic_hook();
|
||||
|
||||
// console::log_1(&format!("WASM(output_node): input: {:?}", args).into());
|
||||
|
||||
|
||||
6
nodes/max/plantarium/stem/.gitignore
vendored
Normal file
6
nodes/max/plantarium/stem/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
bin/
|
||||
pkg/
|
||||
wasm-pack.log
|
||||
23
nodes/max/plantarium/stem/Cargo.toml
Normal file
23
nodes/max/plantarium/stem/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "stem"
|
||||
version = "0.1.0"
|
||||
authors = ["Max Richter <jim-x@web.de>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = ["console_error_panic_hook"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
web-sys = { version = "0.3.69", features = ["console"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.34"
|
||||
5
nodes/max/plantarium/stem/package.json
Normal file
5
nodes/max/plantarium/stem/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "wasm-pack build --release --out-name index --no-default-features"
|
||||
}
|
||||
}
|
||||
27
nodes/max/plantarium/stem/src/input.json
Normal file
27
nodes/max/plantarium/stem/src/input.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"op_type": {
|
||||
"label": "type",
|
||||
"type": "select",
|
||||
"labels": [
|
||||
"add",
|
||||
"subtract",
|
||||
"multiply",
|
||||
"divide"
|
||||
],
|
||||
"internal": true,
|
||||
"value": 0
|
||||
},
|
||||
"a": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"b": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"clip": {
|
||||
"type": "boolean",
|
||||
"value": 0,
|
||||
"setting": "math.clipping"
|
||||
}
|
||||
}
|
||||
20
nodes/max/plantarium/stem/src/lib.rs
Normal file
20
nodes/max/plantarium/stem/src/lib.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use macros::generate_input_types_file;
|
||||
use utils::generate_outputs;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
generate_outputs!(["stem"]);
|
||||
|
||||
generate_input_types_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
let mut result = Vec::with_capacity(args.len() + 3);
|
||||
result.push(0); // encoding the [ bracket
|
||||
result.push(args[1] + 1);
|
||||
result.push(0); // adding the node-type, math: 0
|
||||
result.extend_from_slice(&args[2..]);
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
|
||||
result
|
||||
}
|
||||
13
nodes/max/plantarium/stem/tests/web.rs
Normal file
13
nodes/max/plantarium/stem/tests/web.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
//! Test suite for the Web and headless browsers.
|
||||
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
extern crate wasm_bindgen_test;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn pass() {
|
||||
assert_eq!(1 + 1, 2);
|
||||
}
|
||||
@@ -21,6 +21,8 @@ utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.4"
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
web-sys = { version = "0.3.69", features = ["console"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.34"
|
||||
|
||||
7
nodes/max/plantarium/sum/src/input.json
Normal file
7
nodes/max/plantarium/sum/src/input.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"array": {
|
||||
"type": "float",
|
||||
"value": 2,
|
||||
"external": true
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,31 @@
|
||||
use macros::generate_input_types_file;
|
||||
use utils::{decode_float, encode_float, generate_outputs};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// lifted from the `console_log` example
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
}
|
||||
generate_outputs!(["float"]);
|
||||
|
||||
generate_input_types_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_outputs() -> Vec<String> {
|
||||
vec!["float".to_string()]
|
||||
}
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
utils::set_panic_hook();
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_input_types() -> String {
|
||||
r#"{
|
||||
"array": { "type": "float", "value": 2, "external": true }
|
||||
}"#
|
||||
.to_string()
|
||||
}
|
||||
let mut sum = 0.0;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(array: &[i32]) -> Vec<i32> {
|
||||
let mut sum = 0;
|
||||
array.iter().for_each(|x| sum += x);
|
||||
vec![1, sum]
|
||||
// console::log_1(&format!("WASM(sum_node): args: {:?}", input).into());
|
||||
|
||||
let length = (input.len() - 2) / 2;
|
||||
|
||||
(0..length).for_each(|i| {
|
||||
let mantissa = input[2 + i * 2];
|
||||
let exponent = input[2 + i * 2 + 1];
|
||||
// console::log_1(&format!("WASM(sum_node): i: {} sum: {:?}", i, sum).into());
|
||||
sum += decode_float(mantissa, exponent);
|
||||
});
|
||||
|
||||
let encoded_sum = encode_float(sum);
|
||||
|
||||
// console::log_1(&format!("WASM(sum_node): result: {:?}", sum).into());
|
||||
|
||||
vec![0, 3, encoded_sum.0, encoded_sum.1]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user