Watasu
(Japanese: 渡す; English: pass on) is a simple JavaScript abstraction, that simply passes on a function call from a safe run context to the outside. This allows for a quick execution, as the program will only describe the order and values of calls in native JavaScript.
This is a screenshot of the example that can be found in
./index.html
. It is deployed atoltdaniel.eu/watasu
.
The project is compiled as an esmodule
. So you can use it like:
<script type="module">
import Watasu from 'http://cdn.jsdelivr.net/gh/oltdaniel/watasu/dist/watasu.js';
const watasu = new Watasu();
watasu.loadProgram(`
set(sum, 0);
inc(sum);
print("current sum is ", sum);
`);
watasu.registerCall('set', function set(name, value) {
if (name.name === 'dataReference') {
this._context[name.value] = this.resolveParameterValue(value);
} else {
throw new Error('invalid set call');
}
})
watasu.registerCall('inc', function inc(name) {
if (name.name === 'dataReference') {
this._context[name.value]++;
} else {
throw new Error('invalid inc call');
}
})
watasu.registerCall('print', function print(...args) {
console.log(...this.resolveParametersValues(args));
})
while(!watasu._runner.isDone) {
watasu.step();
}
</script>
We use
esbuild
because it is easy and supports exactly what we need to build a simple library.
# get the repo
git clone https://github.com/oltdaniel/watasu.git
cd watasu
# start live rebuild
yarn watch
# fix all eslint errors
yarn eslint . --fix
# all changes done. do production build
yarn build
# commit
Do what you'd like to do. But keep sharing it publicly.