EYG is an intermediate representation for programs that never crash and can run in all kinds of environments.
Running EYG programs in JavaScript environments is now possible using the eyg-run
package published to npm.
This interpreter can be used on node.js and in the browser.
EYG programs can be run on node, using npx, as follows:
echo '{"0":"a","f":{"0":"p","l":"Log"},"a":{"0":"s","v":"Hello, World!"}}' > hello.json
cat hello.json | npx eyg-run
The default node runner includes only the Log
effect.
To implement other external effects, follow the browser instructions.
To run in the browser requires building a runner.
In this example the Log
effect is handled by the window.alert
API.
import { exec, Record, native } from "https://esm.run/eyg-run";
const extrinsic = {
Log(message) {
window.alert(message)
return (Record())
}
}
async function run() {
let source = {"0":"a","f":{"0":"p","l":"Log"},"a":{"0":"s","v":"Hello, World!"}}
let result = await exec(source, extrinsic)
console.log(native(result))
}
run()
Documentation describing the JSON format for EYG programs is now available on github.
That's all for this update, I hope you have enjoyed it.
This issue is available, and shareable, at https://eyg.run/news/editions/1