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 19 commits
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
6 changes: 3 additions & 3 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Run install phase
Expand All @@ -30,4 +30,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: aya.zip
path: target/aya-*.zip
path: target/aya-*.zip
6 changes: 3 additions & 3 deletions .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Run test phase
run: mvn test --batch-mode
run: mvn test --batch-mode
75 changes: 75 additions & 0 deletions build-scripts/package-ayastdlib-js-build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="AyaPackageStdlibJS" basedir="." default="all">
<!-- verify that all parameters were passed -->
<fail unless="build-dir"/>

<!-- re-define the parameters, so that they can be used with autocompletion -->
<property name="build-dir" value="ALREADY_DEFINED"/>

<dirname property="build-script.dir" file="${ant.file.AyaPackageStdlibJS}"/>
<property name="root.dir" location="${build-script.dir}/.."/>

<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${build-script.dir}/libs/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<target name="all">
<property name="run.dir" location="${build-dir}/package-stdlib-js/"/>

<!-- delete data from previous tests -->
<delete dir="${run.dir}" failonerror="false"/>
<mkdir dir="${run.dir}"/>

<copy todir="${run.dir}">
<fileset dir="${build-dir}/classes" includes="**"/>
<fileset dir="${root.dir}">
<include name="ayarc.aya"/>
<include name="base/**"/>
<include name="std/**"/>
<include name="examples/package_aya_libs.aya"/>
</fileset>
</copy>

<!-- create a temporary working directory for aya -->
<run_aya run.dir="${run.dir}" run.aya="examples/package_aya_libs.aya"/>
</target>

<macrodef name="run_aya">
<attribute name="run.dir"/>
<attribute name="run.aya"/>
<sequential>
<!-- since this is a macro, make sure properties are cleared on every call -->
<property name="error.log.str" value=""/>
<var name="error.log.str" unset="true"/>

<trycatch>
<try>
<java
fork="true"
dir="@{run.dir}"
classname="ui.AyaIDE"
failonerror="true"
errorproperty="error.log.str"
>
<classpath>
<fileset dir="${build-dir}/libs" includes="**/*.jar"/>
<file file="@{run.dir}"/>
</classpath>

<arg value="@{run.dir}"/>
<arg value="@{run.dir}/@{run.aya}"/>
</java>
<!-- if the test did not fail, repeat the error logs to the console -->
<echo level="error" message="${error.log.str}"/>
</try>
<catch>
<!-- if the test failed, use the error log as the failure message -->
<fail message="${error.log.str}"/>
</catch>
</trycatch>
</sequential>
</macrodef>
</project>
29 changes: 29 additions & 0 deletions examples/package_aya_libs.aya
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ::json
import ::sys
import ::io

.# All files in base/ and std/
[
"base" path! $ sys.readdir + ~
"std" path! $ sys.readdir + ~
] :files;

.# Convert to strings
files #P :files;

{,} :data;

files :# {file,
file G data.:[file];
};

data json.dumps :json_data;

"aya-stdlib.js" :outfile;

"const AYA_STDLIB = $json_data;" outfile 0 .G

"Created file $outfile" :P



58 changes: 58 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>TeaVM example</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<!--<script type="text/javascript" charset="utf-8" src="./build/generated/teavm/js/aya.js"></script>-->
<script type="text/javascript" charset="utf-8" src="./target/javascript/aya.js"></script>
<script type="text/javascript" charset="utf-8" src="./target/package-stdlib-js/aya-stdlib.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js" integrity="sha512-8RnEqURPUc5aqFEN04aQEiPlSAdE0jlFS/9iGgUyNtwFnSKCXhmB6ZTNl7LnDtDWKabJIASzXrzD0K+LYexU9g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.css" integrity="sha512-uf06llspW44/LZpHzHT6qBOIVODjWtv4MxCricRxkzvopAlSWnTf6hpZTFxuuZcuNE9CBQhqE0Seu1CoRk84nQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script type="text/javascript">
var aya = {};
var editor = null;

function run() {
var input = "\"base/__aya__.aya\" :F ";
var out = aya.runIsolated(input + editor.getValue());
document.getElementById('out').innerHTML = out;
}

function setup() {
main();
// Exported functions
aya.runIsolated = main.runIsolated;
aya.addFile = main.addFile;
aya.listFiles = main.listFiles;

editor = CodeMirror(document.getElementById("code"), {
mode: "text/html",
theme: "neonsyntax",
lineWrapping: true,
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
extraKeys: {
"Ctrl-Enter": (cm) => {
run();
}
},

});

for (const path of Object.keys(AYA_STDLIB)) {
aya.addFile(path, AYA_STDLIB[path]);
}
console.log(aya.listFiles());

run();
}

</script>
</head>
<body onload="setup()">
<i>Press Shift+Enter to run</i>
<div id="code" style="border: solid 1px;"></div>
<pre id="out"></pre>
</body>
</html>
159 changes: 134 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<version>4.0.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>



<repositories>
<repository>
<id>local-libs</id>
Expand All @@ -23,7 +25,9 @@

<build>
<sourceDirectory>src</sourceDirectory>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down Expand Up @@ -77,32 +81,11 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ui.AyaIDE</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>ch.obermuhlner</groupId>
<artifactId>big-math</artifactId>
Expand Down Expand Up @@ -130,4 +113,130 @@
</dependency>
</dependencies>

</project>

<profiles>

<!-- Build a fat JAR for Running in a desktop enviornment -->
<profile>
<id>desktop</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>

<!-- Exclude web specific files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<excludes>
<exclude>web/**</exclude>
</excludes>
</configuration>
</plugin>

<!-- Build fat JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>

<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>ui.AyaIDE</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</profile>

<!-- Build .js files for running in a web enviornment -->
<profile>
<id>web</id>
<build>
<plugins>

<!-- Build JS runtime using TeaVM -->
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>0.10.2</version>
<dependencies>
<!-- This dependency is required by TeaVM to emulate subset of Java class library -->
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>0.10.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<mainClass>web.AyaWeb</mainClass>
<mainPageIncluded>true</mainPageIncluded>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<targetFileName>aya.js</targetFileName>
</configuration>
</execution>
</executions>
</plugin>

<!-- Build a js file containing the aya standard library -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>package-ayastdlib-js</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="build-dir" value="${project.build.directory}"/>
<ant antfile="${project.basedir}/build-scripts/package-ayastdlib-js-build.xml"/>
</target>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso</artifactId>
<version>0.10.2</version>
</dependency>
</dependencies>

</profile>
</profiles>


</project>
Loading