mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
poor call implementation
This commit is contained in:
parent
aee41603e8
commit
26626fdc8d
83
Cargo.lock
generated
83
Cargo.lock
generated
@ -7,8 +7,8 @@ dependencies = [
|
||||
"fluence",
|
||||
"log",
|
||||
"serde",
|
||||
"serde-lexpr",
|
||||
"serde_derive",
|
||||
"serde_sexpr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -70,29 +70,6 @@ version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
|
||||
[[package]]
|
||||
name = "lexpr"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6b5eeb1dcf1c6a1fad8c1a88c4cc01618db83810c55cc64c1f86d73688fbfdc"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"lexpr-macros",
|
||||
"proc-macro-hack",
|
||||
"ryu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lexpr-macros"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd627fb38e19c00d8d068618259205f7a91c91aeade5c15bc35dbca037bb1c35"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.77"
|
||||
@ -108,23 +85,33 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "4.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.21"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
|
||||
checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
@ -194,16 +181,6 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-lexpr"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "143e5e658ac3a7374bdf285b9355cab74dd144293b86c9be27eab39452239d41"
|
||||
dependencies = [
|
||||
"lexpr",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.116"
|
||||
@ -227,10 +204,20 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.41"
|
||||
name = "serde_sexpr"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
|
||||
checksum = "5318bfeed779c64075ce317c81462ed54dc00021be1c6b34957d798e11a68bdb"
|
||||
dependencies = [
|
||||
"nom",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -252,6 +239,12 @@ dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
|
@ -8,9 +8,13 @@ edition = "2018"
|
||||
name = "aquamarine"
|
||||
path = "src/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "aqua_test_module"
|
||||
path = "test_module/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { path = "/Users/mike/dev/work/fluence/wasm/rust-sdk", features = ["logger"] }
|
||||
serde = "1.0.116"
|
||||
serde = { version = "1.0.116", features = ["derive"] }
|
||||
serde_derive = "1.0.116"
|
||||
serde-lexpr = "0.1.1"
|
||||
serde_sexpr = "0.1.0"
|
||||
log = "0.4.11"
|
||||
|
@ -1,6 +1,11 @@
|
||||
modules_dir = "artifacts/"
|
||||
modules_dir = "./target/wasm32-wasi/release/"
|
||||
|
||||
[[module]]
|
||||
name = "aquamarine"
|
||||
name = "aqua_test_module"
|
||||
mem_pages_count = 100
|
||||
logger_enabled = true
|
||||
|
||||
[[module]]
|
||||
name = "aquamarine"
|
||||
mem_pages_count = 100
|
||||
logger_enabled = true
|
||||
|
@ -14,12 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::hash_map::RandomState;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Call {
|
||||
pub peer_part: (String, Option<String>),
|
||||
pub fn_part: (Option<String>, String),
|
||||
pub args: String,
|
||||
pub args: Vec<u8>,
|
||||
pub result_name: String,
|
||||
}
|
||||
|
||||
impl super::ExecutableInstruction for Call {
|
||||
fn execute(self, _data: &mut HashMap<String, Vec<u8>, RandomState>) {
|
||||
let service_id = match (self.peer_part.1, self.fn_part.0) {
|
||||
(Some(service_id), None) => service_id,
|
||||
(None, Some(service_id)) => service_id,
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
let _result = unsafe { crate::call_service(service_id, self.fn_part.1, self.args) };
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,31 @@
|
||||
|
||||
mod call;
|
||||
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
pub(crate) use call::Call;
|
||||
|
||||
pub(self) use crate::stepper::ExecutableInstruction;
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::hash_map::RandomState;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub(crate) enum Instruction {
|
||||
Null,
|
||||
Call(call::Call),
|
||||
Call(Call),
|
||||
/*
|
||||
Par(Box<Instruction>, Box<Instruction>),
|
||||
Seq(Box<Instruction>, Box<Instruction>),
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
impl ExecutableInstruction for Instruction {
|
||||
fn execute(self, data: &mut HashMap<String, Vec<u8>, RandomState>) {
|
||||
match self {
|
||||
Instruction::Null => {},
|
||||
Instruction::Call(call) => call.execute(data),
|
||||
}
|
||||
}
|
||||
}
|
24
src/main.rs
24
src/main.rs
@ -15,6 +15,7 @@
|
||||
*/
|
||||
mod air;
|
||||
mod instructions;
|
||||
mod stepper;
|
||||
mod stepper_outcome;
|
||||
|
||||
use instructions::Instruction;
|
||||
@ -27,10 +28,12 @@ pub fn main() {
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn invoke(init_user_id: String, aqua: String, data: String) -> StepperOutcome {
|
||||
pub fn invoke(init_user_id: String, aqua: String, data: Vec<u8>) -> StepperOutcome {
|
||||
log::info!(
|
||||
"stepper invoked with user_id = {}, aqua = {:?}, data = {:?}",
|
||||
init_user_id, aqua, data
|
||||
init_user_id,
|
||||
aqua,
|
||||
data
|
||||
);
|
||||
|
||||
let outcome = StepperOutcome {
|
||||
@ -38,7 +41,7 @@ pub fn invoke(init_user_id: String, aqua: String, data: String) -> StepperOutcom
|
||||
next_peer_pks: vec![init_user_id],
|
||||
};
|
||||
|
||||
let parsed_aqua: Vec<Instruction> = match serde_lexpr::from_str(&aqua) {
|
||||
let parsed_aqua = match serde_sexpr::from_str::<Vec<Instruction>>(&aqua) {
|
||||
Ok(parsed) => parsed,
|
||||
Err(e) => {
|
||||
log::error!("supplied aqua script can't be parsed: {:?}", e);
|
||||
@ -46,8 +49,21 @@ pub fn invoke(init_user_id: String, aqua: String, data: String) -> StepperOutcom
|
||||
return outcome;
|
||||
}
|
||||
};
|
||||
|
||||
log::info!("parsed_aqua: {:?}", parsed_aqua);
|
||||
|
||||
crate::stepper::execute(parsed_aqua);
|
||||
|
||||
outcome
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct CallServiceResult {
|
||||
pub result: i32,
|
||||
pub outcome: Vec<u8>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "aqua_test_module")]
|
||||
extern "C" {
|
||||
pub fn call_service(service_id: String, fn_name: String, args: Vec<u8>) -> CallServiceResult;
|
||||
}
|
||||
|
31
src/stepper.rs
Normal file
31
src/stepper.rs
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::Instruction;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub(crate) trait ExecutableInstruction {
|
||||
fn execute(self, data: &mut HashMap<String, Vec<u8>>);
|
||||
}
|
||||
|
||||
pub(crate) fn execute(instructions: Vec<Instruction>) {
|
||||
let mut data = HashMap::new();
|
||||
|
||||
for instruction in instructions {
|
||||
instruction.execute(&mut data);
|
||||
}
|
||||
}
|
@ -18,6 +18,6 @@ use fluence::fce;
|
||||
|
||||
#[fce]
|
||||
pub struct StepperOutcome {
|
||||
pub data: String,
|
||||
pub data: Vec<u8>,
|
||||
pub next_peer_pks: Vec<String>,
|
||||
}
|
||||
}
|
||||
|
22
test_module/main.rs
Normal file
22
test_module/main.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub struct CallServiceResult {
|
||||
pub result: i32,
|
||||
pub outcome: Vec<u8>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn call_service(service_id: String, fn_name: String, args: Vec<u8>) -> CallServiceResult {
|
||||
println!(
|
||||
"call service invoked with:\n service_id: {}\n fn_name: {}\n args: {:?}",
|
||||
service_id, fn_name, args
|
||||
);
|
||||
|
||||
CallServiceResult {
|
||||
result: 0,
|
||||
outcome: vec![1, 2, 3],
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user