mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-23 11:41:45 +00:00
Update nbody example for Rust (#528)
This commit is contained in:
2
examples/n-body/rust/Cargo.lock
generated
2
examples/n-body/rust/Cargo.lock
generated
@ -1,3 +1,5 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "rust_nbody"
|
||||
version = "0.1.0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
### Build
|
||||
|
||||
```bash
|
||||
cargo build --release --target=wasm32-unknown-unknown
|
||||
cargo +nightly build --release --target wasm32-unknown-unknown
|
||||
```
|
||||
|
||||
***Next step optimize target wasm via wasm-opt.***
|
||||
***Next step optimize target wasm via wasm-gc***
|
||||
|
@ -8,8 +8,8 @@ const compiled = new WebAssembly.Module(
|
||||
const imports = {
|
||||
env: {
|
||||
memory: new WebAssembly.Memory({ initial: 17 }),
|
||||
abort: (filename, line, column) => {
|
||||
throw Error("abort called at " + line + ":" + colum);
|
||||
abort: (_filename, line, column) => {
|
||||
throw Error("abort called at " + line + ":" + column);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code adopted from https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-rust-1.html
|
||||
|
||||
#![feature(core_intrinsics, panic_implementation)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![no_std]
|
||||
|
||||
use core::intrinsics;
|
||||
@ -156,18 +156,18 @@ fn offset_momentum(bodies: &mut [Planet; N_BODIES]) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn init() {
|
||||
pub unsafe extern fn init() {
|
||||
offset_momentum(&mut BODIES);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn step() -> f64 {
|
||||
pub unsafe extern fn step() -> f64 {
|
||||
advance(&mut BODIES, 0.01);
|
||||
energy(&BODIES)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn bench(steps: i32) {
|
||||
pub unsafe extern fn bench(steps: i32) {
|
||||
for _ in 0..steps {
|
||||
advance(&mut BODIES, 0.01);
|
||||
}
|
||||
|
Reference in New Issue
Block a user