https://github.com/t-mullen/slash-a-js
Javascript/WASM bindings for the Slash/A interpreter.
https://github.com/t-mullen/slash-a-js
Last synced: 3 months ago
JSON representation
Javascript/WASM bindings for the Slash/A interpreter.
- Host: GitHub
- URL: https://github.com/t-mullen/slash-a-js
- Owner: t-mullen
- License: gpl-3.0
- Created: 2020-08-22T19:51:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-23T02:36:23.000Z (almost 5 years ago)
- Last Synced: 2025-01-25T08:48:11.916Z (4 months ago)
- Language: C++
- Size: 127 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# slash-a-js
Javascript/WASM bindings for the [Slash/A interpreter](https://github.com/arturadib/slash-a).
## Usage
```javascript
// manually create some source code
const source = 'input/0/save/input/add/output/.' // adds x+y// convert it into bytecode
const bytecode = SlashA.source2ByteCode(source)// setup the input buffer
const input = new SlashA.VectorDouble()
input.push_back(2)
input.push_back(3)// set limits on tape size (data and label)
const DATA_SIZE = 10
const LABEL_SIZE = 10// provide random seed (can be set to some constant for deterministic runs)
const RAND_SEED = Math.floor(Math.random() * 2147483647)// set limits on runtime and loop depth
const MAX_RUNTIME = 10
const MAX_LOOP_DEPTH = 10// run the bytecode
const output = SlashA.runByteCode(bytecode, input, DATA_SIZE, LABEL_SIZE, RAND_SEET, MAX_RUNTIME, MAX_LOOP_DEPTH)// check that the code did not fail (due to runtime or max loop depth being exceeded)
if (SlashA.checkFailed()) {
throw new Error('Code failed!')
}// examine output
console.log((new Array(output.size())).map(_, i) => output.get(i)) // [5]// cleanup
bytecode.delete()
input.delete()
output.delete()
```Bytecode can also be created directly, without any source code.
```javascript
const bytecode = new SlashA.ByteCode()
bytecode.push_back(1)
```## Installation
```htmlvar SlashA = {
onRuntimeInitialized: function () {
// ready to use
const bytecode = new SlashA.ByteCode()
}
}```