-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from aya-lang/aya-js
Aya JavaScript Runtime
- Loading branch information
Showing
34 changed files
with
1,025 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.