mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Minor refactoring; Fix n-body TS build
This commit is contained in:
@ -175,7 +175,7 @@ function asmFunc(global, env, buffer) {
|
||||
function assembly_index_NBodySystem_constructor($0, $1) {
|
||||
$0 = $0 | 0;
|
||||
$1 = $1 | 0;
|
||||
var $2 = 0, $3 = 0, $4 = 0.0, $5 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0, $8 = 0, $10 = 0;
|
||||
var $2 = 0, $3 = 0, $4 = 0.0, $5 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0, $9 = 0;
|
||||
$2 = $1;
|
||||
$8 = HEAP32[($2 + 4 | 0) >> 2] | 0;
|
||||
continue_0 : do {
|
||||
@ -193,17 +193,16 @@ function asmFunc(global, env, buffer) {
|
||||
} while (1);
|
||||
$2 = $1;
|
||||
$2 = HEAPU32[$2 >> 2] | 0;
|
||||
if (0 >>> 0 < ((HEAP32[$2 >> 2] | 0) >>> 2 | 0) >>> 0) $10 = HEAPU32[(($2 + 0 | 0) + 8 | 0) >> 2] | 0; else abort();
|
||||
$2 = $10;
|
||||
if (0 >>> 0 < ((HEAP32[$2 >> 2] | 0) >>> 2 | 0) >>> 0) $9 = HEAPU32[(($2 + 0 | 0) + 8 | 0) >> 2] | 0; else abort();
|
||||
$2 = $9;
|
||||
HEAPF64[($2 + 24 | 0) >> 3] = -$5 / 39.47841760435743;
|
||||
HEAPF64[($2 + 32 | 0) >> 3] = -$6 / 39.47841760435743;
|
||||
HEAPF64[($2 + 40 | 0) >> 3] = -$7 / 39.47841760435743;
|
||||
if ($0) $8 = $0; else {
|
||||
if (($0 | 0) == (0 | 0)) {
|
||||
$0 = $lib_allocator_arena_allocate_memory(4 | 0) | 0;
|
||||
HEAP32[$0 >> 2] = $1;
|
||||
$8 = $0;
|
||||
}
|
||||
return $8 | 0;
|
||||
return $0 | 0;
|
||||
}
|
||||
|
||||
function assembly_index_init() {
|
||||
|
@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("allocator/arena");
|
||||
// From The Computer Language Benchmarks Game
|
||||
// http://benchmarksgame.alioth.debian.org
|
||||
const SOLAR_MASS = 4.0 * Math.PI * Math.PI;
|
||||
const DAYS_PER_YEAR = 365.24;
|
||||
class Body {
|
||||
@ -37,25 +39,27 @@ function Neptune() {
|
||||
}
|
||||
class NBodySystem {
|
||||
constructor(bodies) {
|
||||
this.bodies = bodies;
|
||||
var px = 0.0;
|
||||
var py = 0.0;
|
||||
var pz = 0.0;
|
||||
var size = bodies.length;
|
||||
for (let i = 0; i < size; i++) {
|
||||
let b = bodies[i];
|
||||
let b = unchecked(bodies[i]);
|
||||
let m = b.mass;
|
||||
px += b.vx * m;
|
||||
py += b.vy * m;
|
||||
pz += b.vz * m;
|
||||
}
|
||||
this.bodies = bodies;
|
||||
this.bodies[0].offsetMomentum(px, py, pz);
|
||||
bodies[0].offsetMomentum(px, py, pz);
|
||||
}
|
||||
advance(dt) {
|
||||
var bodies = this.bodies;
|
||||
var size = bodies.length;
|
||||
// var buffer = changetype<usize>(bodies.buffer_);
|
||||
for (let i = 0; i < size; ++i) {
|
||||
let bodyi = bodies[i];
|
||||
let bodyi = unchecked(bodies[i]);
|
||||
// let bodyi = load<Body>(buffer + i * sizeof<Body>(), 8);
|
||||
let ix = bodyi.x;
|
||||
let iy = bodyi.y;
|
||||
let iz = bodyi.z;
|
||||
@ -64,7 +68,8 @@ class NBodySystem {
|
||||
let bivz = bodyi.vz;
|
||||
let bodyim = bodyi.mass;
|
||||
for (let j = i + 1; j < size; ++j) {
|
||||
let bodyj = bodies[j];
|
||||
let bodyj = unchecked(bodies[j]);
|
||||
// let bodyj = load<Body>(buffer + j * sizeof<Body>(), 8);
|
||||
let dx = ix - bodyj.x;
|
||||
let dy = iy - bodyj.y;
|
||||
let dz = iz - bodyj.z;
|
||||
@ -91,9 +96,8 @@ class NBodySystem {
|
||||
energy() {
|
||||
var e = 0.0;
|
||||
var bodies = this.bodies;
|
||||
var size = bodies.length;
|
||||
for (let i = 0; i < size; ++i) {
|
||||
let bodyi = bodies[i];
|
||||
for (let i = 0, size = bodies.length; i < size; ++i) {
|
||||
let bodyi = unchecked(bodies[i]);
|
||||
let ix = bodyi.x;
|
||||
let iy = bodyi.y;
|
||||
let iz = bodyi.z;
|
||||
|
Binary file not shown.
@ -706,21 +706,20 @@
|
||||
(f64.const 39.47841760435743)
|
||||
)
|
||||
)
|
||||
(if (result i32)
|
||||
(get_local $0)
|
||||
(get_local $0)
|
||||
(block (result i32)
|
||||
(i32.store
|
||||
(tee_local $0
|
||||
(call $~lib/allocator/arena/allocate_memory
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.store
|
||||
(tee_local $0
|
||||
(call $~lib/allocator/arena/allocate_memory
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
(func $assembly/index/init (; 6 ;) (type $v)
|
||||
(local $0 i32)
|
||||
|
@ -25,7 +25,12 @@ var nbodyASMJS = eval("0," + src)({
|
||||
|
||||
// Load JS version
|
||||
var src = fs.readFileSync(__dirname + "/../build/index.js", "utf8");
|
||||
var nbodyJS = (new Function("require", "exports", src + " return exports;"))(function() {}, {});
|
||||
var scopeJS = {
|
||||
require: function() {},
|
||||
exports: {},
|
||||
unchecked: function(expr) { return expr }
|
||||
};
|
||||
var nbodyJS = new Function(...Object.keys(scopeJS).concat(src + "\nreturn exports"))(...Object.values(scopeJS));
|
||||
|
||||
function test(nbody, steps) {
|
||||
nbody.init();
|
||||
|
Reference in New Issue
Block a user