Compare commits
204 Commits
v0.3.0-alp
...
0.9.27-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
5fc5eb08f8
|
|||
|
8acbc003c4
|
|||
|
fda33112a7
|
|||
|
67b2413d7c
|
|||
|
3a05416510
|
|||
|
c291328cc3
|
|||
|
7cb267b0d9
|
|||
|
4e31766665
|
|||
|
b5b63c4342
|
|||
|
18f70a0d58
|
|||
|
d38b600366
|
|||
|
0ac7af2ea3
|
|||
|
5185c93663
|
|||
|
510422cab7
|
|||
|
79e1d1cfaf
|
|||
|
e0f3274a95
|
|||
| ef5d29105f | |||
|
d8ea6557df
|
|||
|
5ba858545a
|
|||
|
446ecd8f2b
|
|||
|
fbf103439a
|
|||
|
b30f94de8f
|
|||
|
47b4dd3c15
|
|||
|
0fb336373a
|
|||
|
b33325a98d
|
|||
|
ccf75d6066
|
|||
|
662dcc1ac1
|
|||
|
3e6214659b
|
|||
|
7c6622c53d
|
|||
|
70d5871091
|
|||
|
7b9bbe576b
|
|||
|
e6399c1546
|
|||
|
c8253795b2
|
|||
|
49dd725669
|
|||
|
52489ad3a8
|
|||
|
c4d44547c8
|
|||
|
c6dc031cfd
|
|||
|
285960bdd6
|
|||
|
cf99845f6b
|
|||
|
48bd1e2015
|
|||
|
304665904f
|
|||
|
56ae3a85a6
|
|||
|
0178cb2194
|
|||
|
a2cb5cd473
|
|||
|
c123427e77
|
|||
|
7ac5ded185
|
|||
|
769d6ae8fc
|
|||
|
afb99ffc70
|
|||
|
46136e77e2
|
|||
|
b460b87318
|
|||
|
e772f0b50d
|
|||
|
187ad55291
|
|||
|
8156a1733f
|
|||
|
d1937fdb63
|
|||
|
3f826cc85d
|
|||
|
af35d7f20b
|
|||
|
cfa0e001b9
|
|||
|
c10d071346
|
|||
|
89eea7d62b
|
|||
| 18d22a1282 | |||
|
72a0d39d0b
|
|||
|
d8585a20bf
|
|||
|
e4c9a8756e
|
|||
|
c6e6425c7e
|
|||
|
292ca64cb9
|
|||
|
4572db5c46
|
|||
|
0251c4689d
|
|||
|
3173919b49
|
|||
|
45f133c6b0
|
|||
|
34276d720c
|
|||
|
2c634778c3
|
|||
|
4aa757e625
|
|||
|
918f2623cd
|
|||
|
a321fc14bc
|
|||
|
07a6f18b16
|
|||
|
5f4011aa0c
|
|||
|
71f735b812
|
|||
|
e575b3287e
|
|||
|
4fa5f5a815
|
|||
|
a61c6a494e
|
|||
|
978ee8db79
|
|||
|
e372941e99
|
|||
|
c36a0db860
|
|||
|
d6ee59363f
|
|||
|
d5fd6e650e
|
|||
|
c0b895e00a
|
|||
|
9ea5cd9277
|
|||
|
aaf9a6fa45
|
|||
|
579f09c837
|
|||
|
3343262e72
|
|||
|
153a1a9a49
|
|||
|
bf38587271
|
|||
|
21534efd60
|
|||
|
802f2f3f52
|
|||
|
38acc20a6f
|
|||
|
d7f6010319
|
|||
|
87f8975275
|
|||
| 09eb6507dc | |||
|
2f58f6b245
|
|||
|
4bc363485f
|
|||
|
8e01db637b
|
|||
|
1c64912786
|
|||
|
28265a8f44
|
|||
|
e9e020512e
|
|||
|
4b0bbf5190
|
|||
|
031f78ebf1
|
|||
|
562f1f9425
|
|||
|
82a09e8865
|
|||
|
90da2db1fb
|
|||
|
3d275c52c0
|
|||
|
797585f539
|
|||
|
7a301eba8f
|
|||
|
1b2068a274
|
|||
|
078d7ed95f
|
|||
|
93973c12b1
|
|||
|
cad4f34b51
|
|||
|
d3571d6ee2
|
|||
|
caf9131cde
|
|||
| 8c6379eb24 | |||
|
380a5c720a
|
|||
|
76c3d377af
|
|||
|
42f443572a
|
|||
|
773bc72f3e
|
|||
|
0b5178e9fd
|
|||
|
8cffcff7db
|
|||
|
60bbaaccd4
|
|||
|
60b1762462
|
|||
|
34434965d2
|
|||
|
fe86123f0f
|
|||
|
d5e6edfa8b
|
|||
|
73345062ca
|
|||
|
124341969c
|
|||
|
8defd93855
|
|||
|
6c57e0e9f2
|
|||
|
f1932914ee
|
|||
|
977701e601
|
|||
|
e8a7ac8da8
|
|||
|
6b1cb852c2
|
|||
|
b59a003086
|
|||
|
1902e41f61
|
|||
|
27162ef8ac
|
|||
|
4f22e76d2b
|
|||
|
8924e7aadc
|
|||
| 1d0e31a423 | |||
|
ab56908171
|
|||
|
eb14bb080c
|
|||
|
f52f47cdb4
|
|||
|
567eaa8514
|
|||
|
2cfdd8e335
|
|||
|
4b1ec671e2
|
|||
|
b127aadcf6
|
|||
|
b6eaff65ca
|
|||
|
443dc0ffa1
|
|||
|
e107dd3507
|
|||
|
6af3c70fce
|
|||
|
8b743f49d1
|
|||
|
e1ce384815
|
|||
|
86d205e521
|
|||
|
f0ad936e5b
|
|||
|
4a1473c5be
|
|||
|
4111dbf5c4
|
|||
|
1666682dc2
|
|||
|
f2b33d0233
|
|||
|
f5a0b6eaf7
|
|||
|
829bea755d
|
|||
|
4b0dcffd13
|
|||
|
987f8b8f00
|
|||
|
55e3d46bc2
|
|||
|
3e25068219
|
|||
|
7ecb8bfabb
|
|||
|
488deea164
|
|||
|
ed08041335
|
|||
|
0a4149ba81
|
|||
|
30f5d619c3
|
|||
|
e7dbe91374
|
|||
|
455f5a613e
|
|||
|
1eeac3ae97
|
|||
|
1acd78e119
|
|||
|
df9932874d
|
|||
|
b47d1a7576
|
|||
|
fdfa8d7713
|
|||
|
f5d1287948
|
|||
|
15f4278cb1
|
|||
| df8465cb49 | |||
|
e3104c223c
|
|||
|
1d0bae3de8
|
|||
|
b66acd3089
|
|||
|
e326847287
|
|||
|
26591d6631
|
|||
|
af31b1ab79
|
|||
|
f885d4349f
|
|||
|
d57044acb7
|
|||
|
7df4e3b03f
|
|||
|
ed1009ab69
|
|||
|
f856cdf37e
|
|||
|
4f82574b8c
|
|||
|
0ae24148d8
|
|||
|
ac128d17f4
|
|||
|
6508f15bb0
|
|||
|
69f93b4f87
|
|||
|
b675411925
|
|||
|
d1e93c2088
|
|||
|
942db54546
|
|||
|
d20df66982
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* -text
|
||||||
17
.github/workflows/tagged-release.yml
vendored
17
.github/workflows/tagged-release.yml
vendored
@@ -3,7 +3,7 @@ name: "tagged-release"
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tagged-release:
|
tagged-release:
|
||||||
@@ -11,15 +11,22 @@ jobs:
|
|||||||
runs-on: "ubuntu-latest"
|
runs-on: "ubuntu-latest"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'adopt'
|
||||||
|
java-version: '11'
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: gradle/gradle-build-action@v2
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: GuillaumeFalourd/clone-github-repo-action@main
|
uses: GuillaumeFalourd/clone-github-repo-action@main
|
||||||
with:
|
with:
|
||||||
branch: 'master' # fuck this political bullshitshit, took me an hour to fix this
|
branch: 'master'
|
||||||
owner: 'TopchetoEU'
|
owner: 'TopchetoEU'
|
||||||
repository: 'java-jscript'
|
repository: 'java-jscript'
|
||||||
- name: "Build"
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd java-jscript; node ./build.js release ${{ github.ref }}
|
cd java-jscript; gradle build
|
||||||
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
with:
|
with:
|
||||||
@@ -27,4 +34,4 @@ jobs:
|
|||||||
prerelease: false
|
prerelease: false
|
||||||
files: |
|
files: |
|
||||||
java-jscript/LICENSE
|
java-jscript/LICENSE
|
||||||
java-jscript/dst/*.jar
|
java-jscript/build/libs/*.jar
|
||||||
35
.gitignore
vendored
35
.gitignore
vendored
@@ -1,11 +1,24 @@
|
|||||||
.vscode
|
*
|
||||||
.gradle
|
|
||||||
.ignore
|
!/src
|
||||||
/out
|
!/src/**/*
|
||||||
/build
|
|
||||||
/bin
|
!/doc
|
||||||
/dst
|
!/doc/**/*
|
||||||
/*.js
|
|
||||||
!/build.js
|
!/tests
|
||||||
/dead-code
|
!/tests/**/*
|
||||||
/Metadata.java
|
|
||||||
|
!/.github
|
||||||
|
!/.github/**/*
|
||||||
|
|
||||||
|
!/.gitignore
|
||||||
|
!/.gitattributes
|
||||||
|
!/LICENSE
|
||||||
|
!/README.md
|
||||||
|
!/settings.gradle
|
||||||
|
!/build.gradle
|
||||||
|
!/gradle.properties
|
||||||
|
!/gradle
|
||||||
|
!/gradle/wrapper
|
||||||
|
!/gradle/wrapper/gradle-wrapper.properties
|
||||||
33
README.md
33
README.md
@@ -2,33 +2,24 @@
|
|||||||
|
|
||||||
**NOTE: This had nothing to do with Microsoft's dialect of EcmaScript**
|
**NOTE: This had nothing to do with Microsoft's dialect of EcmaScript**
|
||||||
|
|
||||||
**WARNING: Currently, this code is mostly undocumented. Proceed with caution and a psychiatrist.**
|
**WARNING: Currently, this code is undocumented. Proceed with caution and a psychiatrist.**
|
||||||
|
|
||||||
JScript is an engine, capable of running EcmaScript 5, written entirely in Java. This engine has been developed with the goal of being easy to integrate with your preexisting codebase, **THE GOAL OF THIS ENGINE IS NOT PERFORMANCE**. My crude experiments show that this engine is 50x-100x slower than V8, which, although bad, is acceptable for most simple scripting purposes.
|
JScript is an engine, capable of running EcmaScript 5, written entirely in Java. This engine has been developed with the goal of being easy to integrate with your preexisting codebase, **THE GOAL OF THIS ENGINE IS NOT PERFORMANCE**. My crude experiments show that this engine is 50x-100x slower than V8, which, although bad, is acceptable for most simple scripting purposes. Note that although the codebase has a Main class, this isn't meant to be a standalone program, but instead a library for running JavaScript code.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
The following will create a REPL using the engine as a backend. Not that this won't properly log errors. I recommend checking out the implementation in `Main.main`:
|
The following is going to execute a simple javascript statement:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
var engine = new PolyfillEngine(new File("."));
|
var engine = new Engine();
|
||||||
var in = new BufferedReader(new InputStreamReader(System.in));
|
// Initialize a standard environment, with implementations of most basic standard libraries (Object, Array, Symbol, etc.)
|
||||||
engine.start();
|
var env = Internals.apply(new Environment());
|
||||||
|
|
||||||
while (true) {
|
// Queue code to load internal libraries and start engine
|
||||||
try {
|
var awaitable = engine.pushMsg(false, env, new Filename("tmp", "eval"), "10 + Math.sqrt(5 / 3)", null);
|
||||||
var raw = in.readLine();
|
// Run the engine on the same thread, until the event loop runs empty
|
||||||
|
engine.run(true);
|
||||||
|
|
||||||
var res = engine.pushMsg(false, engine.global(), Map.of(), "<stdio>", raw, null).await();
|
// Get our result
|
||||||
Values.printValue(engine.context(), res);
|
System.out.println(awaitable.await());
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
catch (EngineException e) {
|
|
||||||
try {
|
|
||||||
System.out.println("Uncaught " + e.toString(engine.context()));
|
|
||||||
}
|
|
||||||
catch (InterruptedException _e) { return; }
|
|
||||||
}
|
|
||||||
catch (IOException | InterruptedException e) { return; }
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|||||||
32
build.gradle
Normal file
32
build.gradle
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
plugins {
|
||||||
|
id "application"
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(11)
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest.attributes["Main-class"] = project.main_class
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs = [ "src/java" ]
|
||||||
|
main.resources.srcDirs = [ "src/assets" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
filesMatching "metadata.json", {
|
||||||
|
expand(
|
||||||
|
version: project.project_version,
|
||||||
|
name: project.project_name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
base.archivesName = project.project_name
|
||||||
|
version = project.project_version
|
||||||
|
group = project.project_group
|
||||||
81
build.js
81
build.js
@@ -1,81 +0,0 @@
|
|||||||
const { spawn } = require('child_process');
|
|
||||||
const fs = require('fs/promises');
|
|
||||||
const pt = require('path');
|
|
||||||
const { argv } = require('process');
|
|
||||||
|
|
||||||
const conf = {
|
|
||||||
name: "java-jscript",
|
|
||||||
author: "TopchetoEU",
|
|
||||||
javahome: "",
|
|
||||||
version: argv[3]
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log(conf)
|
|
||||||
|
|
||||||
if (conf.version.startsWith('refs/tags/')) conf.version = conf.version.substring(10);
|
|
||||||
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
|
||||||
|
|
||||||
async function* find(src, dst, wildcard) {
|
|
||||||
const stat = await fs.stat(src);
|
|
||||||
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
for (const el of await fs.readdir(src)) {
|
|
||||||
for await (const res of find(pt.join(src, el), dst ? pt.join(dst, el) : undefined, wildcard)) yield res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (stat.isFile() && wildcard(src)) yield dst ? { src, dst } : src;
|
|
||||||
}
|
|
||||||
async function copy(src, dst, wildcard) {
|
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
for await (const el of find(src, dst, wildcard)) {
|
|
||||||
promises.push((async () => {
|
|
||||||
await fs.mkdir(pt.dirname(el.dst), { recursive: true });
|
|
||||||
await fs.copyFile(el.src, el.dst);
|
|
||||||
})());
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run(cmd, ...args) {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
const proc = spawn(cmd, args, { stdio: 'inherit' });
|
|
||||||
proc.once('exit', code => {
|
|
||||||
if (code === 0) res(code);
|
|
||||||
else rej(new Error(`Process ${cmd} exited with code ${code}.`));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function compileJava() {
|
|
||||||
try {
|
|
||||||
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/Metadata.java')).toString()
|
|
||||||
.replace('${VERSION}', conf.version)
|
|
||||||
.replace('${NAME}', conf.name)
|
|
||||||
.replace('${AUTHOR}', conf.author)
|
|
||||||
);
|
|
||||||
const args = ['--release', '11', ];
|
|
||||||
if (argv[2] === 'debug') args.push('-g');
|
|
||||||
args.push('-d', 'dst/classes', 'Metadata.java');
|
|
||||||
|
|
||||||
for await (const path of find('src', undefined, v => v.endsWith('.java') && !v.endsWith('Metadata.java'))) args.push(path);
|
|
||||||
await run(conf.javahome + 'javac', ...args);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
await fs.rm('Metadata.java');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
try { await fs.rm('dst', { recursive: true }); } catch {}
|
|
||||||
await copy('src', 'dst/classes', v => !v.endsWith('.java'));
|
|
||||||
await compileJava();
|
|
||||||
await run('jar', '-c', '-f', 'dst/jscript.jar', '-e', 'me.topchetoeu.jscript.Main', '-C', 'dst/classes', '.');
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (argv[2] === 'debug') throw e;
|
|
||||||
else console.log(e.toString());
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
4
gradle.properties
Normal file
4
gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
project_group = me.topchetoeu
|
||||||
|
project_name = jscript
|
||||||
|
project_version = 0.9.27-beta
|
||||||
|
main_class = me.topchetoeu.jscript.utils.JScriptRepl
|
||||||
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
5
settings.gradle
Normal file
5
settings.gradle
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = properties.project_name
|
||||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
1004
src/assets/debugger/protocol.json
Normal file
1004
src/assets/debugger/protocol.json
Normal file
File diff suppressed because it is too large
Load Diff
5
src/assets/metadata.json
Normal file
5
src/assets/metadata.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "${name}",
|
||||||
|
"author": "TopchetoEU"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
58
src/java/me/topchetoeu/jscript/common/Buffer.java
Normal file
58
src/java/me/topchetoeu/jscript/common/Buffer.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package me.topchetoeu.jscript.common;
|
||||||
|
|
||||||
|
public class Buffer {
|
||||||
|
private byte[] data;
|
||||||
|
private int length;
|
||||||
|
|
||||||
|
public void write(int i, byte[] val) {
|
||||||
|
if (i + val.length > data.length) {
|
||||||
|
var newCap = i + val.length + 1;
|
||||||
|
if (newCap < data.length * 2) newCap = data.length * 2;
|
||||||
|
|
||||||
|
var tmp = new byte[newCap];
|
||||||
|
System.arraycopy(this.data, 0, tmp, 0, length);
|
||||||
|
this.data = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.arraycopy(val, 0, data, i, val.length);
|
||||||
|
if (i + val.length > length) length = i + val.length;
|
||||||
|
}
|
||||||
|
public int read(int i, byte[] buff) {
|
||||||
|
int n = buff.length;
|
||||||
|
if (i + n > length) n = length - i;
|
||||||
|
System.arraycopy(data, i, buff, 0, n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
data = new byte[128];
|
||||||
|
length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void append(byte b) {
|
||||||
|
write(length, new byte[] { b });
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] data() {
|
||||||
|
var res = new byte[length];
|
||||||
|
System.arraycopy(this.data, 0, res, 0, length);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public int length() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Buffer(byte[] data) {
|
||||||
|
this.data = new byte[data.length];
|
||||||
|
this.length = data.length;
|
||||||
|
System.arraycopy(data, 0, this.data, 0, data.length);
|
||||||
|
}
|
||||||
|
public Buffer(int capacity) {
|
||||||
|
this.data = new byte[capacity];
|
||||||
|
this.length = 0;
|
||||||
|
}
|
||||||
|
public Buffer() {
|
||||||
|
this.data = new byte[128];
|
||||||
|
this.length = 0;
|
||||||