Skip to content
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

Merged
merged 22 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fd1d464
Add abstract HTTP downloader class
nick-paul Nov 6, 2024
303c32b
Remove .U operator (quick dialog)
nick-paul Nov 6, 2024
ac59bca
Add abstract filesystem
nick-paul Nov 6, 2024
c81e22c
Update fileutils with abstract filesystem
nick-paul Nov 6, 2024
763b57a
Add abstract stdio
nick-paul Nov 6, 2024
9cb5e37
Create web library and update maven to build
nick-paul Nov 6, 2024
754896a
Create aya script to build standard library into JSON object
nick-paul Nov 6, 2024
ddb4d1c
Add minimal index.html for testing aya.js build
nick-paul Nov 6, 2024
7e8d906
Merge branch 'master' into aya-js
nick-paul Nov 10, 2024
f5e2ff6
Merge branch 'master' into aya-js
nick-paul Nov 11, 2024
273de7d
Add missing imports
nick-paul Nov 11, 2024
94ddf9c
Use resolvePath for :{sys.readdir}
nick-paul Nov 11, 2024
332f4e1
Handle null return case in listFiles()
nick-paul Nov 11, 2024
a0cf536
Re-add resultCode to AyaIDE and InteractiveAya (previously removed wh…
nick-paul Nov 11, 2024
73d75d4
Add maven build script to automatically package standard library into…
nick-paul Nov 11, 2024
4a9ea84
Merge branch 'master' into aya-js
nick-paul Nov 14, 2024
f5837f7
Update workflow to java 11
nick-paul Nov 29, 2024
04091db
Merge branch 'master' into aya-js
nick-paul Nov 29, 2024
291196d
Clean up code for web implementation
nick-paul Nov 29, 2024
ce3e858
fix undeclared variable | fix startup script path
BlazingTwist Dec 1, 2024
9273006
build restructure : make the fat-jar and web files optional using pro…
BlazingTwist Dec 1, 2024
f2f7c41
Merge pull request #120 from BlazingTwist/aya-js-pom-profiles
nick-paul Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/aya/StandaloneAya.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import aya.parser.SourceString;

public class StandaloneAya {
/**
* A Bare-bones aya entry point that does not provide interactivity or preserve state
*/

public static void main(String[] args) {
StaticData.IO = new AyaStdIO(System.out, System.err, System.in, new ScannerInputWrapper(System.in));
Expand Down
2 changes: 0 additions & 2 deletions src/aya/StaticData.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class StaticData {
//
private static StaticData _instance;



//
// Data loaded in the parser
//
Expand Down
65 changes: 18 additions & 47 deletions src/web/AyaWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.teavm.jso.JSBody;
import org.teavm.jso.JSFunctor;
import org.teavm.jso.JSObject;
//import org.teavm.jso.dom.html.HTMLDocument;

import aya.AyaStdIO;
import aya.StandaloneAya;
Expand All @@ -25,6 +24,10 @@ public class AyaWeb {
private static StringOut output = new StringOut();

public static void main(String[] args) {

//
// Set up StaticData
//
StaticData sd = StaticData.getInstance();

StaticData.IO = new AyaStdIO(
Expand All @@ -35,35 +38,26 @@ public static void main(String[] args) {

WebFilesystemIO fs = new WebFilesystemIO();
StaticData.FILESYSTEM = fs;


//
// Named Instructions
// Web build only supports a limited set of named instructions
//
WebAvailableNamedInstructionStore wsi = new WebAvailableNamedInstructionStore();
sd.addNamedInstructionStore(wsi);

//sd.addNamedInstructionStore(new DebugInstructionStore());
sd.addNamedInstructionStore(new JSONInstructionStore());
//sd.addNamedInstructionStore(new ImageInstructionStore());
//sd.addNamedInstructionStore(new GraphicsInstructionStore());
//sd.addNamedInstructionStore(new FStreamInstructionStore());
//sd.addNamedInstructionStore(new SystemInstructionStore());
//sd.addNamedInstructionStore(new DialogInstructionStore());
//sd.addNamedInstructionStore(new PlotInstructionStore());
sd.addNamedInstructionStore(new DateInstructionStore());
//sd.addNamedInstructionStore(new SocketInstructionStore());
sd.addNamedInstructionStore(new ColorInstructionStore());
sd.addNamedInstructionStore(new LinearAlgebraInstructionStore());
//sd.addNamedInstructionStore(new ThreadInstructionStore());

exportSayHello(new ExportFunctionSayHello() {
@Override
public String call(String s) {
return sayHello(s);
}
});

//
// Exported Functions Implementation
//
exportRunIsolated(new ExportFunctionRunIsolated() {
@Override
public String call(String s) {
return runIsolated(s);
StandaloneAya.runIsolated(input, StaticData.IO);
Copy link
Contributor

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.

return output.flushOut() + output.flushErr();
}
});

Expand Down Expand Up @@ -103,27 +97,10 @@ public String call(String source) {

}

public static String runIsolated(String input) {
StandaloneAya.runIsolated(input, StaticData.IO);
return output.flushOut() + output.flushErr();
}

//public static void example() {
// String outstr = runIsolated("1 1 +");
// var document = HTMLDocument.current();
// var div = document.createElement("div");
// //div.appendChild(document.createTextNode("Hello world"));
// div.appendChild(document.createTextNode(outstr));
// document.getBody().appendChild(div);
//}

private static String sayHello(String s) {
return "Hello, " + s + "!";
}
//
// Exported Functions
//

@JSBody(params = "sayHello", script = "main.sayHello = sayHello;")
private static native void exportSayHello(ExportFunctionSayHello fn);

@JSBody(params = "runIsolated", script = "main.runIsolated = runIsolated;")
private static native void exportRunIsolated(ExportFunctionRunIsolated fn);

Expand All @@ -138,11 +115,6 @@ private static String sayHello(String s) {

}

@JSFunctor
interface ExportFunctionSayHello extends JSObject {
String call(String s);
}

@JSFunctor
interface ExportFunctionRunIsolated extends JSObject {
String call(String s);
Expand All @@ -161,5 +133,4 @@ interface ExportFunctionListFiles extends JSObject {
@JSFunctor
interface ExportFunctionLint extends JSObject {
String call(String source);
}

}
5 changes: 5 additions & 0 deletions src/web/WebAvailableNamedInstructionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import aya.obj.list.Str;

public class WebAvailableNamedInstructionStore extends NamedInstructionStore {
/**
* This class provides some overrides for aya instructions so they work in the web implementation
*
* Only a small subset of instructions are supported
*/

@Override
protected void init() {
Expand Down
6 changes: 6 additions & 0 deletions src/web/WebFilesystemIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import aya.io.fs.AbstractFilesystemIO;

public class WebFilesystemIO extends AbstractFilesystemIO {
/**
* A very basic virtual filesystem implementation
* This is primarily used to load the standard library in the web implementation
*
* Very few features outside of loading the standard library are supported
*/

private static class FileData {
public byte[] data;
Expand Down