Skip to content

Commit

Permalink
Merge pull request #112 from aya-lang/aya-js
Browse files Browse the repository at this point in the history
Aya JavaScript Runtime
  • Loading branch information
nick-paul authored Dec 5, 2024
2 parents d081d59 + f2f7c41 commit 1bde0bf
Show file tree
Hide file tree
Showing 34 changed files with 1,025 additions and 136 deletions.
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>
Loading

0 comments on commit 1bde0bf

Please sign in to comment.