@raviqqe/stak 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Stak
2
+
3
+ [![GitHub Action](https://img.shields.io/github/actions/workflow/status/raviqqe/stak/test.yaml?branch=main&style=flat-square)](https://github.com/raviqqe/stak/actions)
4
+ [![Crate](https://img.shields.io/crates/v/stak.svg?style=flat-square)](https://crates.io/crates/stak)
5
+ [![Codecov](https://img.shields.io/codecov/c/github/raviqqe/stak.svg?style=flat-square)](https://codecov.io/gh/raviqqe/stak)
6
+ [![License](https://img.shields.io/github/license/raviqqe/stak.svg?style=flat-square)](LICENSE)
7
+
8
+ No-`std` and no-`alloc` Scheme implementation in Rust
9
+
10
+ The documentation is [here](https://raviqqe.github.io/stak).
11
+
12
+ ## License
13
+
14
+ [MIT](LICENSE)
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@raviqqe/stak",
3
+ "private": false,
4
+ "description": "Stak Scheme VM in WebAssembly",
5
+ "version": "0.1.0",
6
+ "license": "SEE LICENSE IN ../LICENSE",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/raviqqe/stak"
10
+ },
11
+ "files": [
12
+ "stak_wasm_bg.wasm",
13
+ "stak_wasm.js",
14
+ "stak_wasm_bg.js",
15
+ "stak_wasm.d.ts"
16
+ ],
17
+ "module": "stak_wasm.js",
18
+ "types": "stak_wasm.d.ts",
19
+ "sideEffects": ["./stak_wasm.js", "./snippets/*"],
20
+ "keywords": ["interpreter", "language", "scheme"]
21
+ }
package/stak_wasm.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {string} source
5
+ * @returns {Uint8Array}
6
+ */
7
+ export function compile(source: string): Uint8Array;
8
+ /**
9
+ * @param {Uint8Array} bytecodes
10
+ * @param {Uint8Array} input
11
+ * @param {number} heap_size
12
+ * @returns {Uint8Array}
13
+ */
14
+ export function run(bytecodes: Uint8Array, input: Uint8Array, heap_size: number): Uint8Array;
package/stak_wasm.js ADDED
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./stak_wasm_bg.wasm";
2
+ import { __wbg_set_wasm } from "./stak_wasm_bg.js";
3
+ __wbg_set_wasm(wasm);
4
+ export * from "./stak_wasm_bg.js";
@@ -0,0 +1,191 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
8
+
9
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
10
+
11
+ cachedTextDecoder.decode();
12
+
13
+ let cachedUint8Memory0 = null;
14
+
15
+ function getUint8Memory0() {
16
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
17
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
18
+ }
19
+ return cachedUint8Memory0;
20
+ }
21
+
22
+ function getStringFromWasm0(ptr, len) {
23
+ ptr = ptr >>> 0;
24
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
25
+ }
26
+
27
+ const heap = new Array(128).fill(undefined);
28
+
29
+ heap.push(undefined, null, true, false);
30
+
31
+ let heap_next = heap.length;
32
+
33
+ function addHeapObject(obj) {
34
+ if (heap_next === heap.length) heap.push(heap.length + 1);
35
+ const idx = heap_next;
36
+ heap_next = heap[idx];
37
+
38
+ heap[idx] = obj;
39
+ return idx;
40
+ }
41
+
42
+ let WASM_VECTOR_LEN = 0;
43
+
44
+ const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
45
+
46
+ let cachedTextEncoder = new lTextEncoder('utf-8');
47
+
48
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
49
+ ? function (arg, view) {
50
+ return cachedTextEncoder.encodeInto(arg, view);
51
+ }
52
+ : function (arg, view) {
53
+ const buf = cachedTextEncoder.encode(arg);
54
+ view.set(buf);
55
+ return {
56
+ read: arg.length,
57
+ written: buf.length
58
+ };
59
+ });
60
+
61
+ function passStringToWasm0(arg, malloc, realloc) {
62
+
63
+ if (realloc === undefined) {
64
+ const buf = cachedTextEncoder.encode(arg);
65
+ const ptr = malloc(buf.length, 1) >>> 0;
66
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
67
+ WASM_VECTOR_LEN = buf.length;
68
+ return ptr;
69
+ }
70
+
71
+ let len = arg.length;
72
+ let ptr = malloc(len, 1) >>> 0;
73
+
74
+ const mem = getUint8Memory0();
75
+
76
+ let offset = 0;
77
+
78
+ for (; offset < len; offset++) {
79
+ const code = arg.charCodeAt(offset);
80
+ if (code > 0x7F) break;
81
+ mem[ptr + offset] = code;
82
+ }
83
+
84
+ if (offset !== len) {
85
+ if (offset !== 0) {
86
+ arg = arg.slice(offset);
87
+ }
88
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
89
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
90
+ const ret = encodeString(arg, view);
91
+
92
+ offset += ret.written;
93
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
94
+ }
95
+
96
+ WASM_VECTOR_LEN = offset;
97
+ return ptr;
98
+ }
99
+
100
+ let cachedInt32Memory0 = null;
101
+
102
+ function getInt32Memory0() {
103
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
104
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
105
+ }
106
+ return cachedInt32Memory0;
107
+ }
108
+
109
+ function getObject(idx) { return heap[idx]; }
110
+
111
+ function dropObject(idx) {
112
+ if (idx < 132) return;
113
+ heap[idx] = heap_next;
114
+ heap_next = idx;
115
+ }
116
+
117
+ function takeObject(idx) {
118
+ const ret = getObject(idx);
119
+ dropObject(idx);
120
+ return ret;
121
+ }
122
+
123
+ function getArrayU8FromWasm0(ptr, len) {
124
+ ptr = ptr >>> 0;
125
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
126
+ }
127
+ /**
128
+ * @param {string} source
129
+ * @returns {Uint8Array}
130
+ */
131
+ export function compile(source) {
132
+ try {
133
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
134
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
135
+ const len0 = WASM_VECTOR_LEN;
136
+ wasm.compile(retptr, ptr0, len0);
137
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
138
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
139
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
140
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
141
+ if (r3) {
142
+ throw takeObject(r2);
143
+ }
144
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
145
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
146
+ return v2;
147
+ } finally {
148
+ wasm.__wbindgen_add_to_stack_pointer(16);
149
+ }
150
+ }
151
+
152
+ function passArray8ToWasm0(arg, malloc) {
153
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
154
+ getUint8Memory0().set(arg, ptr / 1);
155
+ WASM_VECTOR_LEN = arg.length;
156
+ return ptr;
157
+ }
158
+ /**
159
+ * @param {Uint8Array} bytecodes
160
+ * @param {Uint8Array} input
161
+ * @param {number} heap_size
162
+ * @returns {Uint8Array}
163
+ */
164
+ export function run(bytecodes, input, heap_size) {
165
+ try {
166
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
167
+ const ptr0 = passArray8ToWasm0(bytecodes, wasm.__wbindgen_malloc);
168
+ const len0 = WASM_VECTOR_LEN;
169
+ const ptr1 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
170
+ const len1 = WASM_VECTOR_LEN;
171
+ wasm.run(retptr, ptr0, len0, ptr1, len1, heap_size);
172
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
173
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
174
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
175
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
176
+ if (r3) {
177
+ throw takeObject(r2);
178
+ }
179
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
180
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
181
+ return v3;
182
+ } finally {
183
+ wasm.__wbindgen_add_to_stack_pointer(16);
184
+ }
185
+ }
186
+
187
+ export function __wbindgen_error_new(arg0, arg1) {
188
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
189
+ return addHeapObject(ret);
190
+ };
191
+
Binary file