feat: some shit
This commit is contained in:
39
app/src/lib/runtime/helpers.ts
Normal file
39
app/src/lib/runtime/helpers.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
export function logInt32ArrayChanges(
|
||||||
|
before: Int32Array,
|
||||||
|
after: Int32Array,
|
||||||
|
clamp = 10
|
||||||
|
): void {
|
||||||
|
if (before.length !== after.length) {
|
||||||
|
throw new Error('Arrays must have the same length');
|
||||||
|
}
|
||||||
|
|
||||||
|
let rangeStart: number | null = null;
|
||||||
|
let collected: number[] = [];
|
||||||
|
|
||||||
|
const flush = (endIndex: number) => {
|
||||||
|
if (rangeStart === null) return;
|
||||||
|
|
||||||
|
const preview = collected.slice(0, clamp);
|
||||||
|
const suffix = collected.length > clamp ? '...' : '';
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Change ${rangeStart}-${endIndex}: [${preview.join(', ')}${suffix}]`
|
||||||
|
);
|
||||||
|
|
||||||
|
rangeStart = null;
|
||||||
|
collected = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 0; i < before.length; i++) {
|
||||||
|
if (before[i] !== after[i]) {
|
||||||
|
if (rangeStart === null) {
|
||||||
|
rangeStart = i;
|
||||||
|
}
|
||||||
|
collected.push(after[i]);
|
||||||
|
} else {
|
||||||
|
flush(i - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flush(before.length - 1);
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { SettingsToStore } from '$lib/settings/app-settings.svelte';
|
||||||
import { RemoteNodeRegistry } from '@nodarium/registry';
|
import { RemoteNodeRegistry } from '@nodarium/registry';
|
||||||
import type {
|
import type {
|
||||||
Graph,
|
Graph,
|
||||||
@@ -13,6 +14,8 @@ import {
|
|||||||
encodeFloat,
|
encodeFloat,
|
||||||
type PerformanceStore
|
type PerformanceStore
|
||||||
} from '@nodarium/utils';
|
} from '@nodarium/utils';
|
||||||
|
import { DevSettingsType } from '../../routes/dev/settings.svelte';
|
||||||
|
import { logInt32ArrayChanges } from './helpers';
|
||||||
import type { RuntimeNode } from './types';
|
import type { RuntimeNode } from './types';
|
||||||
|
|
||||||
const log = createLogger('runtime-executor');
|
const log = createLogger('runtime-executor');
|
||||||
@@ -79,14 +82,14 @@ export type Pointer = {
|
|||||||
|
|
||||||
perf?: PerformanceStore;
|
perf?: PerformanceStore;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly registry: NodeRegistry,
|
private readonly registry: NodeRegistry,
|
||||||
public cache?: SyncCache<Int32Array>
|
public cache?: SyncCache<Int32Array>
|
||||||
) {
|
) {
|
||||||
this.cache = undefined;
|
this.cache = undefined;
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
log.info('MemoryRuntimeExecutor initialized');
|
log.info('MemoryRuntimeExecutor initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
private refreshView(): void {
|
private refreshView(): void {
|
||||||
this.memoryView = new Int32Array(this.memory.buffer);
|
this.memoryView = new Int32Array(this.memory.buffer);
|
||||||
@@ -409,10 +412,11 @@ export type Pointer = {
|
|||||||
const args = inputs.flatMap(p => [p.start * 4, p.end * 4]);
|
const args = inputs.flatMap(p => [p.start * 4, p.end * 4]);
|
||||||
|
|
||||||
log.info(`Executing node ${node.type}/${node.id}`);
|
log.info(`Executing node ${node.type}/${node.id}`);
|
||||||
|
const memoryBefore = this.memoryView.slice(0, this.offset);
|
||||||
const bytesWritten = nodeType.execute(this.offset * 4, args);
|
const bytesWritten = nodeType.execute(this.offset * 4, args);
|
||||||
if (bytesWritten === -1) {
|
this.refreshView();
|
||||||
throw new Error(`Failed to execute node`);
|
const memoryAfter = this.memoryView.slice(0, this.offset);
|
||||||
}
|
logInt32ArrayChanges(memoryBefore, memoryAfter);
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
|
|
||||||
const outLen = bytesWritten >> 2;
|
const outLen = bytesWritten >> 2;
|
||||||
@@ -427,6 +431,7 @@ export type Pointer = {
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
this.results[node.id] = inputs[0];
|
this.results[node.id] = inputs[0];
|
||||||
|
this.allPtrs.push(this.results[node.id]);
|
||||||
log.info(`Node ${node.id} result reused input memory`);
|
log.info(`Node ${node.id} result reused input memory`);
|
||||||
} else {
|
} else {
|
||||||
this.results[node.id] = {
|
this.results[node.id] = {
|
||||||
@@ -434,6 +439,7 @@ export type Pointer = {
|
|||||||
end: outputStart + outLen,
|
end: outputStart + outLen,
|
||||||
_title: `${node.id} ->`
|
_title: `${node.id} ->`
|
||||||
};
|
};
|
||||||
|
this.allPtrs.push(this.results[node.id]);
|
||||||
this.offset += outLen;
|
this.offset += outLen;
|
||||||
lastNodePtr = this.results[node.id];
|
lastNodePtr = this.results[node.id];
|
||||||
log.info(
|
log.info(
|
||||||
@@ -454,6 +460,7 @@ export type Pointer = {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
console.log('Final Memory', [...this.memoryView.slice(0, 20)]);
|
||||||
this.perf?.endPoint('runtime');
|
this.perf?.endPoint('runtime');
|
||||||
log.info('Executor state reset');
|
log.info('Executor state reset');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,8 +127,14 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<button
|
||||||
|
onclick={() => copyVisibleMemory(visibleRows, ptrs, start.value)}
|
||||||
|
class="flex items-center cursor-pointer absolute bottom-4 left-4 z-100 bg-gray-200 px-2 py-1 rounded hover:bg-gray-300"
|
||||||
|
>
|
||||||
|
Copy Visible Memory
|
||||||
|
</button>
|
||||||
<input
|
<input
|
||||||
class="absolute bottom-4 left-4 bg-white"
|
class="absolute bottom-4 right-4 bg-white"
|
||||||
bind:value={start.value}
|
bind:value={start.value}
|
||||||
min="0"
|
min="0"
|
||||||
type="number"
|
type="number"
|
||||||
@@ -144,6 +150,13 @@
|
|||||||
|
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
<Panel id="general" title="General" icon="i-[tabler--settings]">
|
<Panel id="general" title="General" icon="i-[tabler--settings]">
|
||||||
|
<h3 class="p-4 pb-0">Debug Settings</h3>
|
||||||
|
<NestedSettings
|
||||||
|
id="Debug"
|
||||||
|
bind:value={devSettings.value}
|
||||||
|
type={DevSettingsType}
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
<NestedSettings
|
<NestedSettings
|
||||||
id="general"
|
id="general"
|
||||||
bind:value={appSettings.value}
|
bind:value={appSettings.value}
|
||||||
|
|||||||
48
app/src/routes/dev/helpers.ts
Normal file
48
app/src/routes/dev/helpers.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import type { Pointer } from '$lib/runtime';
|
||||||
|
|
||||||
|
export function copyVisibleMemory(rows: Int32Array, currentPtrs: Pointer[], start: number) {
|
||||||
|
if (!rows?.length) return;
|
||||||
|
|
||||||
|
// Build an array of rows for the table
|
||||||
|
const tableRows = [...rows].map((value, i) => {
|
||||||
|
const index = start + i;
|
||||||
|
const ptr = currentPtrs[i];
|
||||||
|
return {
|
||||||
|
index,
|
||||||
|
ptr: ptr?._title ?? '',
|
||||||
|
value: value
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Compute column widths
|
||||||
|
const indexWidth = Math.max(
|
||||||
|
5,
|
||||||
|
...tableRows.map((r) => r.index.toString().length)
|
||||||
|
);
|
||||||
|
const ptrWidth = Math.max(
|
||||||
|
10,
|
||||||
|
...tableRows.map((r) => r.ptr.length)
|
||||||
|
);
|
||||||
|
const valueWidth = Math.max(
|
||||||
|
10,
|
||||||
|
...tableRows.map((r) => r.value.toString().length)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Build header
|
||||||
|
let output =
|
||||||
|
`| ${'Index'.padEnd(indexWidth)} | ${'Ptr'.padEnd(ptrWidth)} | ${'Value'.padEnd(valueWidth)
|
||||||
|
} |\n`
|
||||||
|
+ `|-${'-'.repeat(indexWidth)}-|-${'-'.repeat(ptrWidth)}-|-${'-'.repeat(valueWidth)}-|\n`;
|
||||||
|
|
||||||
|
// Add rows
|
||||||
|
for (const row of tableRows) {
|
||||||
|
output += `| ${row.index.toString().padEnd(indexWidth)} | ${row.ptr.padEnd(ptrWidth)} | ${row.value.toString().padEnd(valueWidth)
|
||||||
|
} |\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy to clipboard
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(output)
|
||||||
|
.then(() => console.log('Memory + metadata copied as table'))
|
||||||
|
.catch((err) => console.error('Failed to copy memory:', err));
|
||||||
|
}
|
||||||
15
app/src/routes/dev/settings.svelte.ts
Normal file
15
app/src/routes/dev/settings.svelte.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { localState } from '$lib/helpers/localState.svelte';
|
||||||
|
import { settingsToStore } from '$lib/settings/app-settings.svelte';
|
||||||
|
|
||||||
|
export const DevSettingsType = {
|
||||||
|
debugNode: {
|
||||||
|
type: 'boolean',
|
||||||
|
label: 'Debug Nodes',
|
||||||
|
value: true
|
||||||
|
}
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export let devSettings = localState(
|
||||||
|
'dev-settings',
|
||||||
|
settingsToStore(DevSettingsType)
|
||||||
|
);
|
||||||
@@ -2,11 +2,14 @@
|
|||||||
name = "float"
|
name = "float"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Max Richter <jim-x@web.de>"]
|
authors = ["Max Richter <jim-x@web.de>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
panic = "unwind"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||||
nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "noise"
|
name = "noise"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Max Richter <jim-x@web.de>"]
|
authors = ["Max Richter <jim-x@web.de>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ nodarium_definition_file!("src/input.json");
|
|||||||
|
|
||||||
#[nodarium_execute]
|
#[nodarium_execute]
|
||||||
pub fn execute(min: (i32, i32), max: (i32, i32), seed: (i32, i32)) -> Vec<i32> {
|
pub fn execute(min: (i32, i32), max: (i32, i32), seed: (i32, i32)) -> Vec<i32> {
|
||||||
|
nodarium_utils::log!("random execute start");
|
||||||
concat_arg_vecs(vec![
|
concat_arg_vecs(vec![
|
||||||
vec![1],
|
vec![1],
|
||||||
read_i32_slice(min),
|
read_i32_slice(min),
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use syn::parse_macro_input;
|
|||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
|
|
||||||
fn add_line_numbers(input: String) -> String {
|
fn add_line_numbers(input: String) -> String {
|
||||||
return input
|
input
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, line)| format!("{:2}: {}", i + 1, line))
|
.map(|(i, line)| format!("{:2}: {}", i + 1, line))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_node_definition(file_path: &Path) -> NodeDefinition {
|
fn read_node_definition(file_path: &Path) -> NodeDefinition {
|
||||||
@@ -72,7 +72,7 @@ pub fn nodarium_execute(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
let total_c_params = param_count * 2;
|
let total_c_params = param_count * 2;
|
||||||
|
|
||||||
let arg_names: Vec<_> = (0..total_c_params)
|
let arg_names: Vec<_> = (0..total_c_params)
|
||||||
.map(|i| syn::Ident::new(&format!("arg{}", i), input_fn.sig.span()))
|
.map(|i| syn::Ident::new(&format!("arg{i}"), input_fn.sig.span()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut tuple_args = Vec::new();
|
let mut tuple_args = Vec::new();
|
||||||
@@ -89,7 +89,20 @@ pub fn nodarium_execute(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn __nodarium_log(ptr: *const u8, len: usize);
|
fn __nodarium_log(ptr: *const u8, len: usize);
|
||||||
fn __nodarium_log_panic(ptr: *const u8, len: usize);
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
fn init_panic_hook() {
|
||||||
|
std::panic::set_hook(Box::new(|_info| {
|
||||||
|
unsafe {
|
||||||
|
__nodarium_log(b"PANIC\0".as_ptr(), 5);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn init_allocator() {
|
||||||
|
nodarium_utils::allocator::ALLOCATOR.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#fn_vis fn #inner_fn_name(#( #input_param_names: (i32, i32) ),*) -> Vec<i32> {
|
#fn_vis fn #inner_fn_name(#( #input_param_names: (i32, i32) ),*) -> Vec<i32> {
|
||||||
@@ -99,11 +112,14 @@ pub fn nodarium_execute(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#fn_vis extern "C" fn execute(output_pos: i32, #( #arg_names: i32 ),*) -> i32 {
|
#fn_vis extern "C" fn execute(output_pos: i32, #( #arg_names: i32 ),*) -> i32 {
|
||||||
|
|
||||||
|
nodarium_utils::allocator::ALLOCATOR.init();
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
init_panic_hook();
|
||||||
nodarium_utils::log!("before_fn");
|
nodarium_utils::log!("before_fn");
|
||||||
let result = #inner_fn_name(
|
let result = #inner_fn_name(
|
||||||
#( #tuple_args ),*
|
#( #tuple_args ),*
|
||||||
);
|
);
|
||||||
nodarium_utils::log!("after_fn");
|
nodarium_utils::log!("after_fn: result_len={}", result.len());
|
||||||
|
|
||||||
let len_bytes = result.len() * 4;
|
let len_bytes = result.len() * 4;
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -137,7 +153,7 @@ fn validate_signature(fn_sig: &syn::Signature, expected_inputs: usize, def: &Nod
|
|||||||
.map(|i| i.keys().collect::<Vec<_>>())
|
.map(|i| i.keys().collect::<Vec<_>>())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
(0..expected_inputs)
|
(0..expected_inputs)
|
||||||
.map(|i| format!("arg{}: (i32, i32)", i))
|
.map(|i| format!("arg{i}: (i32, i32)"))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ")
|
.join(", ")
|
||||||
);
|
);
|
||||||
@@ -155,9 +171,7 @@ fn validate_signature(fn_sig: &syn::Signature, expected_inputs: usize, def: &Nod
|
|||||||
.to_string();
|
.to_string();
|
||||||
if !clean_type.contains("(") && !clean_type.contains(",") {
|
if !clean_type.contains("(") && !clean_type.contains(",") {
|
||||||
panic!(
|
panic!(
|
||||||
"Parameter {} has type '{}' but should be a tuple (i32, i32) representing (start, end) positions in memory",
|
"Parameter {i} has type '{clean_type}' but should be a tuple (i32, i32) representing (start, end) positions in memory",
|
||||||
i,
|
|
||||||
clean_type
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,10 +211,7 @@ pub fn nodarium_definition_file(input: TokenStream) -> TokenStream {
|
|||||||
let full_path = Path::new(&project_dir).join(&file_path);
|
let full_path = Path::new(&project_dir).join(&file_path);
|
||||||
|
|
||||||
let json_content = fs::read_to_string(&full_path).unwrap_or_else(|err| {
|
let json_content = fs::read_to_string(&full_path).unwrap_or_else(|err| {
|
||||||
panic!(
|
panic!("Failed to read JSON file at '{project_dir}/{file_path}': {err}",)
|
||||||
"Failed to read JSON file at '{}/{}': {}",
|
|
||||||
project_dir, file_path, err
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let _: NodeDefinition = serde_json::from_str(&json_content).unwrap_or_else(|err| {
|
let _: NodeDefinition = serde_json::from_str(&json_content).unwrap_or_else(|err| {
|
||||||
|
|||||||
68
packages/utils/src/allocator.rs
Normal file
68
packages/utils/src/allocator.rs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
use core::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn __wasm_memory_size() -> usize;
|
||||||
|
fn __nodarium_manual_end() -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const WASM_PAGE_SIZE: usize = 64 * 1024;
|
||||||
|
|
||||||
|
pub struct DownwardBumpAllocator {
|
||||||
|
heap_top: AtomicUsize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DownwardBumpAllocator {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DownwardBumpAllocator {
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
heap_top: AtomicUsize::new(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn init(&self) {
|
||||||
|
let pages = unsafe { __wasm_memory_size() };
|
||||||
|
let mem_size = pages * WASM_PAGE_SIZE;
|
||||||
|
self.heap_top.store(mem_size, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
pub static ALLOCATOR: DownwardBumpAllocator = DownwardBumpAllocator::new();
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for DownwardBumpAllocator {
|
||||||
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
|
let align = layout.align();
|
||||||
|
let size = layout.size();
|
||||||
|
|
||||||
|
let mut current = self.heap_top.load(Ordering::Relaxed);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let aligned = (current - size) & !(align - 1);
|
||||||
|
|
||||||
|
let manual_end = unsafe { __nodarium_manual_end() };
|
||||||
|
if aligned < manual_end {
|
||||||
|
return core::ptr::null_mut();
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.heap_top.compare_exchange(
|
||||||
|
current,
|
||||||
|
aligned,
|
||||||
|
Ordering::SeqCst,
|
||||||
|
Ordering::Relaxed,
|
||||||
|
) {
|
||||||
|
Ok(_) => return aligned as *mut u8,
|
||||||
|
Err(next) => current = next,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, _: *mut u8, _: Layout) {}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::log;
|
||||||
|
|
||||||
pub fn encode_float(f: f32) -> i32 {
|
pub fn encode_float(f: f32) -> i32 {
|
||||||
// Convert f32 to u32 using to_bits, then safely cast to i32
|
// Convert f32 to u32 using to_bits, then safely cast to i32
|
||||||
let bits = f.to_bits();
|
let bits = f.to_bits();
|
||||||
@@ -12,6 +14,7 @@ pub fn decode_float(bits: i32) -> f32 {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_i32(ptr: i32) -> i32 {
|
pub fn read_i32(ptr: i32) -> i32 {
|
||||||
|
log!("read_i32 ptr: {:?}", ptr);
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ptr = ptr as *const i32;
|
let _ptr = ptr as *const i32;
|
||||||
*_ptr
|
*_ptr
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod allocator;
|
||||||
mod encoding;
|
mod encoding;
|
||||||
mod nodes;
|
mod nodes;
|
||||||
mod tree;
|
mod tree;
|
||||||
@@ -11,7 +12,7 @@ extern "C" {
|
|||||||
pub fn __nodarium_log(ptr: *const u8, len: usize);
|
pub fn __nodarium_log(ptr: *const u8, len: usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
// #[cfg(debug_assertions)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
($($t:tt)*) => {{
|
($($t:tt)*) => {{
|
||||||
@@ -25,13 +26,13 @@ macro_rules! log {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
// #[cfg(not(debug_assertions))]
|
||||||
#[macro_export]
|
// #[macro_export]
|
||||||
macro_rules! log {
|
// macro_rules! log {
|
||||||
($($arg:tt)*) => {{
|
// ($($arg:tt)*) => {{
|
||||||
// This will expand to nothing in release builds
|
// // This will expand to nothing in release builds
|
||||||
}};
|
// }};
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
interface NodariumExports extends WebAssembly.Exports {
|
interface NodariumExports extends WebAssembly.Exports {
|
||||||
memory: WebAssembly.Memory;
|
memory: WebAssembly.Memory;
|
||||||
execute: (outputPos: number, ...args: number[]) => number;
|
execute: (outputPos: number, ...args: number[]) => number;
|
||||||
|
init_allocator: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createWasmWrapper(buffer: ArrayBuffer, memory: WebAssembly.Memory) {
|
export function createWasmWrapper(buffer: ArrayBuffer, memory: WebAssembly.Memory) {
|
||||||
let exports: NodariumExports;
|
let exports: NodariumExports;
|
||||||
|
|
||||||
|
let end = 0;
|
||||||
const importObject = {
|
const importObject = {
|
||||||
env: {
|
env: {
|
||||||
memory: memory,
|
memory: memory,
|
||||||
@@ -25,14 +27,11 @@ export function createWasmWrapper(buffer: ArrayBuffer, memory: WebAssembly.Memor
|
|||||||
const module = new WebAssembly.Module(buffer);
|
const module = new WebAssembly.Module(buffer);
|
||||||
const instance = new WebAssembly.Instance(module, importObject);
|
const instance = new WebAssembly.Instance(module, importObject);
|
||||||
exports = instance.exports as NodariumExports;
|
exports = instance.exports as NodariumExports;
|
||||||
|
exports.init_allocator();
|
||||||
|
|
||||||
function execute(outputPos: number, args: number[]): number {
|
function execute(outputPos: number, args: number[]): number {
|
||||||
try {
|
end = outputPos;
|
||||||
return exports.execute(outputPos, ...args);
|
return exports.execute(outputPos, ...args);
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_definition() {
|
function get_definition() {
|
||||||
|
|||||||
Reference in New Issue
Block a user