-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aya JavaScript Runtime #112
Conversation
…en building JS version)
I think I'm happy with where this implementation is now. It is still quite limited compared to the desktop version so I think it is worth noting what the goals of this runtime are: Goals
Not Goals
What next?After we merge the main change in, I'll be working through updating the manual using this repo. I'll move it over to github.com/aya-lang. Eventually we should have a nice new aya website with interactive documentation and an Aya "pad" so new users can try out the language. @BlazingTwist, If you have a chance, can you take a look at the (Also worth noting that I'm playing around with #111 on the side as well. I'm super excited to try building a package manager for aya that allows for using custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the changes from #103 have gone missing (during a merge conflict maybe?) which caused 'package-ayastdlib-js' to fail for me.
I'm also getting a warning: [WARNING] Parameter 'mainPageIncluded' is unknown for plugin 'teavm-maven-plugin:0.10.2:compile (default)'
Odd, since the teaVM docs include the parameter as well.
I've tinkered with the pom
for a bit and got it to run both profiles by keeping teavm / the web classes during compilation and excluding them from the fat jar instead.
PRs: #119 OR #120
Personally, I like the added configurability of the profiles.
However that might introduce unwanted complexity.
src/web/AyaWeb.java
Outdated
exportRunIsolated(new ExportFunctionRunIsolated() { | ||
@Override | ||
public String call(String s) { | ||
return runIsolated(s); | ||
StandaloneAya.runIsolated(input, StaticData.IO); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems input
is never defined.
…files + opinionated AyaWeb.java changes
Build restructure option 2 : optional execution using profiles
Thanks for the PR with the pom cleanup, this branch looks all good to me! |
TL;DR: This PR creates a JS build of aya using maven (#106) and TeaVM. You can try the demo here. The editor can be used directly in documentation or examples
The demos above come in two parts:
aya.js
, a library that exposes a functionaya.runIsolated(string)
that takes aya source code and produces a result.Even though the editor is not directly a part of this PR, it has many cool features so lets cover that first.
The Editor
Features
You can write and run aya code directly in your browser. The editor is based off of CodeMirror and has a bunch of cool features already such as
Syntax highlighting & standard library support:
Documentation on hover:
Linting:
Dark Mode:
Editor Details
The editor is implemented as a react component using CodeMirror. For the demo, the editor is embedded in a docusaurus project.
Aya Runtime (This PR)
The aya runtime is a custom aya library built using TeaVM. The
aya.js
runtime is relatively lightweight and loads quickly. However, execution is pretty slow if you are doing anything serious and I have already run into a few bugs (see below).What works in the JS runtime:
What does not work yet:
:{...}
are not supported yet. Some of them should be easy to support while others may take a bit more work.Virtual IO and Filesystem
In order to build this runtime, I had to remove any system, I/O, or filesystem dependencies from the build. My solution was to create an abstract class for filesystem and I/O operations. The standard desktop implementation uses an implementation that exposes the standard file and IO functions. The web version uses an implementation that creates a virtual filesystem and I/O. Full disclosure: this solution is a messy hack at the moment and needs to be cleaned up and thoroughly tested before merging.
The other benefit of using a virtual filesystem is that we can expose library functions to allow JavaScript to create and read files. Currently
aya.js
exposes a functionaddFile
that takes a path and a string and creates a file available to aya. This is how the standard library is loaded.To load the standard library, there is an aya script that reads all standard library files and writes them to a JSON object (
aya-stdlib.js
). The JSON object is read in by the JavaScript host which callsaya.addFile
on each item.Maven
Warning: This uses an old version of #106 and also need to be cleaned up. I was just focued on getting anything working for the first pass. I configured maven to build the JS runtime separate from the desktop runtime using build profiles. Use the following to build the JS version:
Known Bugs
Overall, I'm pretty happy with how well everything works. There are some strange new bugs with TeaVM that break some of the examples though:
This should throw an index error but returns NaN:
Runtime exception with
J
Runtime exception using
.=
on stringsTODO