Skip to content

Commit 1bde0bf

Browse files
authored
Merge pull request #112 from aya-lang/aya-js
Aya JavaScript Runtime
2 parents d081d59 + f2f7c41 commit 1bde0bf

34 files changed

+1025
-136
lines changed

.github/workflows/maven-publish.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
contents: read
1919
steps:
2020
- uses: actions/checkout@v3
21-
- name: Set up JDK 8
21+
- name: Set up JDK 11
2222
uses: actions/setup-java@v3
2323
with:
24-
java-version: '8'
24+
java-version: '11'
2525
distribution: 'temurin'
2626
cache: maven
2727
- name: Run install phase
@@ -30,4 +30,4 @@ jobs:
3030
uses: actions/upload-artifact@v4
3131
with:
3232
name: aya.zip
33-
path: target/aya-*.zip
33+
path: target/aya-*.zip

.github/workflows/maven-test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
contents: read
2020
steps:
2121
- uses: actions/checkout@v3
22-
- name: Set up JDK 8
22+
- name: Set up JDK 11
2323
uses: actions/setup-java@v3
2424
with:
25-
java-version: '8'
25+
java-version: '11'
2626
distribution: 'temurin'
2727
cache: maven
2828
- name: Run test phase
29-
run: mvn test --batch-mode
29+
run: mvn test --batch-mode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="AyaPackageStdlibJS" basedir="." default="all">
4+
<!-- verify that all parameters were passed -->
5+
<fail unless="build-dir"/>
6+
7+
<!-- re-define the parameters, so that they can be used with autocompletion -->
8+
<property name="build-dir" value="ALREADY_DEFINED"/>
9+
10+
<dirname property="build-script.dir" file="${ant.file.AyaPackageStdlibJS}"/>
11+
<property name="root.dir" location="${build-script.dir}/.."/>
12+
13+
<taskdef resource="net/sf/antcontrib/antlib.xml">
14+
<classpath>
15+
<pathelement location="${build-script.dir}/libs/ant-contrib-1.0b3.jar"/>
16+
</classpath>
17+
</taskdef>
18+
19+
<target name="all">
20+
<property name="run.dir" location="${build-dir}/package-stdlib-js/"/>
21+
22+
<!-- delete data from previous tests -->
23+
<delete dir="${run.dir}" failonerror="false"/>
24+
<mkdir dir="${run.dir}"/>
25+
26+
<copy todir="${run.dir}">
27+
<fileset dir="${build-dir}/classes" includes="**"/>
28+
<fileset dir="${root.dir}">
29+
<include name="ayarc.aya"/>
30+
<include name="base/**"/>
31+
<include name="std/**"/>
32+
<include name="examples/package_aya_libs.aya"/>
33+
</fileset>
34+
</copy>
35+
36+
<!-- create a temporary working directory for aya -->
37+
<run_aya run.dir="${run.dir}" run.aya="examples/package_aya_libs.aya"/>
38+
</target>
39+
40+
<macrodef name="run_aya">
41+
<attribute name="run.dir"/>
42+
<attribute name="run.aya"/>
43+
<sequential>
44+
<!-- since this is a macro, make sure properties are cleared on every call -->
45+
<property name="error.log.str" value=""/>
46+
<var name="error.log.str" unset="true"/>
47+
48+
<trycatch>
49+
<try>
50+
<java
51+
fork="true"
52+
dir="@{run.dir}"
53+
classname="ui.AyaIDE"
54+
failonerror="true"
55+
errorproperty="error.log.str"
56+
>
57+
<classpath>
58+
<fileset dir="${build-dir}/libs" includes="**/*.jar"/>
59+
<file file="@{run.dir}"/>
60+
</classpath>
61+
62+
<arg value="@{run.dir}"/>
63+
<arg value="@{run.dir}/@{run.aya}"/>
64+
</java>
65+
<!-- if the test did not fail, repeat the error logs to the console -->
66+
<echo level="error" message="${error.log.str}"/>
67+
</try>
68+
<catch>
69+
<!-- if the test failed, use the error log as the failure message -->
70+
<fail message="${error.log.str}"/>
71+
</catch>
72+
</trycatch>
73+
</sequential>
74+
</macrodef>
75+
</project>

examples/package_aya_libs.aya

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import ::json
2+
import ::sys
3+
import ::io
4+
5+
.# All files in base/ and std/
6+
[
7+
"base" path! $ sys.readdir + ~
8+
"std" path! $ sys.readdir + ~
9+
] :files;
10+
11+
.# Convert to strings
12+
files #P :files;
13+
14+
{,} :data;
15+
16+
files :# {file,
17+
file G data.:[file];
18+
};
19+
20+
data json.dumps :json_data;
21+
22+
"aya-stdlib.js" :outfile;
23+
24+
"const AYA_STDLIB = $json_data;" outfile 0 .G
25+
26+
"Created file $outfile" :P
27+
28+
29+

index.html

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>TeaVM example</title>
5+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
6+
<!--<script type="text/javascript" charset="utf-8" src="./build/generated/teavm/js/aya.js"></script>-->
7+
<script type="text/javascript" charset="utf-8" src="./target/javascript/aya.js"></script>
8+
<script type="text/javascript" charset="utf-8" src="./target/package-stdlib-js/aya-stdlib.js"></script>
9+
<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>
10+
<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" />
11+
<script type="text/javascript">
12+
var aya = {};
13+
var editor = null;
14+
15+
function run() {
16+
var input = "\"base/__aya__.aya\" :F ";
17+
var out = aya.runIsolated(input + editor.getValue());
18+
document.getElementById('out').innerHTML = out;
19+
}
20+
21+
function setup() {
22+
main();
23+
// Exported functions
24+
aya.runIsolated = main.runIsolated;
25+
aya.addFile = main.addFile;
26+
aya.listFiles = main.listFiles;
27+
28+
editor = CodeMirror(document.getElementById("code"), {
29+
mode: "text/html",
30+
theme: "neonsyntax",
31+
lineWrapping: true,
32+
lineNumbers: true,
33+
styleActiveLine: true,
34+
matchBrackets: true,
35+
extraKeys: {
36+
"Ctrl-Enter": (cm) => {
37+
run();
38+
}
39+
},
40+
41+
});
42+
43+
for (const path of Object.keys(AYA_STDLIB)) {
44+
aya.addFile(path, AYA_STDLIB[path]);
45+
}
46+
console.log(aya.listFiles());
47+
48+
run();
49+
}
50+
51+
</script>
52+
</head>
53+
<body onload="setup()">
54+
<i>Press Shift+Enter to run</i>
55+
<div id="code" style="border: solid 1px;"></div>
56+
<pre id="out"></pre>
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)