Compare commits
23 Commits
v0.10.0-be
...
6c1666392e
| Author | SHA1 | Date | |
|---|---|---|---|
|
6c1666392e
|
|||
|
3623842827
|
|||
|
24d0cb73b6
|
|||
|
7a13b032f8
|
|||
|
5a154c8a69
|
|||
|
ae77e3b55e
|
|||
|
c8a89849ee
|
|||
|
d563fc4919
|
|||
|
9668bccef1
|
|||
|
1d50ff14c5
|
|||
|
a6c458cb23
|
|||
|
31e2e95bc8
|
|||
|
98dde69751
|
|||
|
ec1edb981e
|
|||
|
36f9839485
|
|||
|
22f36267c0
|
|||
|
f8b9776f28
|
|||
|
12cff84666
|
|||
|
7058a689a2
|
|||
|
fde8b42e36
|
|||
|
4ea14ca1f5
|
|||
|
f6ce261485
|
|||
|
51b347e0d7
|
40
.gitignore
vendored
40
.gitignore
vendored
@@ -1,6 +1,40 @@
|
||||
/*
|
||||
|
||||
!/src
|
||||
/buildSrc/*
|
||||
!/buildSrc
|
||||
!/buildSrc
|
||||
!/buildSrc/src
|
||||
!/buildSrc/build.gradle.kts
|
||||
|
||||
/common/*
|
||||
!/common
|
||||
!/common/src
|
||||
!/common/build.gradle.kts
|
||||
|
||||
/runtime/*
|
||||
!/runtime
|
||||
!/runtime/src
|
||||
!/runtime/build.gradle.kts
|
||||
|
||||
/compilation/*
|
||||
!/compilation
|
||||
!/compilation/src
|
||||
!/compilation/build.gradle.kts
|
||||
|
||||
/repl/*
|
||||
!/repl
|
||||
!/repl/src
|
||||
!/repl/build.gradle.kts
|
||||
|
||||
/lib/*
|
||||
!/lib
|
||||
!/lib/src
|
||||
!/lib/build.gradle.kts
|
||||
!/lib/package.json
|
||||
!/lib/tsconfig.json
|
||||
!/lib/rollup.config.js
|
||||
|
||||
# !/src
|
||||
!/doc
|
||||
!/tests
|
||||
!/.github
|
||||
@@ -10,8 +44,8 @@
|
||||
!/LICENSE
|
||||
!/README.md
|
||||
|
||||
!/settings.gradle
|
||||
!/build.gradle
|
||||
!/settings.gradle.kts
|
||||
!/build.gradle.kts
|
||||
!/gradle.properties
|
||||
|
||||
!/package.json
|
||||
|
||||
84
README.md
84
README.md
@@ -1,25 +1,77 @@
|
||||
# JScript
|
||||
|
||||
**NOTE: This had nothing to do with Microsoft's dialect of EcmaScript**
|
||||
# J2S (Java-JavaScript or Java to JavaScript)
|
||||
|
||||
**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. 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.
|
||||
J2S 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. A small REPL (`me.topchetoeu.j2s.repl.SimpleRepl`) library with an included simple debugger (`me.topchetoeu.j2s.repl.debug.SimpleDebugger`). These are more or less reference implementations. In the future, most of the primordials logic of `SimpleRepl` will be moved in the "lib" project, but for now, it will stay there.
|
||||
|
||||
## Example
|
||||
## How to use?
|
||||
|
||||
The following is going to execute a simple javascript statement:
|
||||
Since this is mostly targeted for integration into other applications, here, examples for invoking JS code from Java will be shown. In the future, a more comprehensive wiki will be made.
|
||||
|
||||
### Setting up an event loop
|
||||
|
||||
First of all, you will want to create an event loop. While not required, 99% of the times you will want to have one.
|
||||
|
||||
```java
|
||||
var engine = new Engine();
|
||||
// Initialize a standard environment, with implementations of most basic standard libraries (Object, Array, Symbol, etc.)
|
||||
var env = Internals.apply(new Environment());
|
||||
|
||||
// Queue code to load internal libraries and start engine
|
||||
var awaitable = engine.pushMsg(false, env, new Filename("tmp", "eval"), "10 + Math.sqrt(5 / 3)", null);
|
||||
// Run the engine on the same thread, until the event loop runs empty
|
||||
engine.run(true);
|
||||
|
||||
// Get our result
|
||||
System.out.println(awaitable.await());
|
||||
var thread = engine.start();
|
||||
```
|
||||
|
||||
Hooray! Now you have an event loop. The thread that was automatically created is a daemon thread, so it will harakiri when the rest of the application ends. If you don't want to use the built-in thread, you can instead run it with `engine.run(untilEmpty)`. If you pass true (which you most likely need), the event loop will be run blocking-ly until it is empty. Otherwise, it will be run forever.
|
||||
|
||||
### Creating the execution environment
|
||||
|
||||
This is one of the other crucial parts of J2S's architecture - the environment. It contains the global scope, a reference to the event loop, the global scope, the debugger, source mappings and a lot more. To run JS code, you must create an environment:
|
||||
|
||||
```java
|
||||
var env = Environment.empty();
|
||||
env.add(EventLoop.KEY, engine); // Gives
|
||||
env.add(DebugContext.KEY, new DebugContext()); // For source mappings
|
||||
```
|
||||
|
||||
As you can see, the environment is nothing more than a simple map of objects that may be of interest to the JS code. Although you can do much more with the environment, we will leave it at that.
|
||||
|
||||
### Registering the compiler
|
||||
|
||||
Since the compiler is a part of the runtime, you need to register it in the environment. You can use the following boilerplate, although a nicer API will be exposed later on:
|
||||
|
||||
```java
|
||||
env.add(Compiler.KEY, (_env, filename, raw, mapper) -> {
|
||||
try {
|
||||
// Invokes the compiler. Will return a CompilerResult, which, along other things,
|
||||
// gives us all the compiled function bodies (aka function scaffoldings, that can be used to construct a function value)
|
||||
var res = JavaScript.compile(env, filename, raw, true);
|
||||
var body = res.body();
|
||||
|
||||
// We'll register the source and function source mappings for debugging
|
||||
DebugContext.get(env).onSource(filename, raw);
|
||||
for (var el : res.bodies()) {
|
||||
DebugContext.get(env).onFunctionLoad(el, res.map(mapper));
|
||||
}
|
||||
|
||||
// Finally, we will construct the function
|
||||
// Few things to note: we need to pass the environment, the name of the function (the filename),
|
||||
// and the last thing: the captures. Since we are compiling the main function, we don't have
|
||||
// any captures, so we pass an empty array
|
||||
return new CodeFunction(env, filename.toString(), body, new Value[0][]);
|
||||
}
|
||||
catch (SyntaxException e) {
|
||||
// Convert the exception to an engine exception
|
||||
var res = EngineException.ofSyntax(e.msg);
|
||||
// Add the location of the error to its stack trace
|
||||
res.add(env, e.loc.filename() + "", e.loc);
|
||||
throw res;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Evaluating a piece of code on the event loop
|
||||
|
||||
This is what you really want to do: run code! You can do that in the following way:
|
||||
|
||||
```java
|
||||
var result = engine.pushMsg(false, env, Filename.parse("my-app://test.js"), "return 10 + 5 / 3;", Value.UNDEFINED).get();
|
||||
System.out.println(result.toReadable(env));
|
||||
```
|
||||
|
||||
If all goes well, we will get "11.666..." as a result.
|
||||
|
||||
128
build.gradle
128
build.gradle
@@ -1,128 +0,0 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
plugins {
|
||||
id 'application';
|
||||
id 'com.github.node-gradle.node' version '5.0.0';
|
||||
id 'net.nemerosa.versioning' version '2.15.0';
|
||||
id 'org.ajoberstar.grgit' version '5.0.0-rc.3'; // required by gradle
|
||||
|
||||
// TODO: figure out how to integrate proguard
|
||||
// id "com.github.xaverkapeller.proguard-annotations"
|
||||
}
|
||||
|
||||
base.archivesName = project.project_name;
|
||||
version = project.project_version;
|
||||
group = project.project_group;
|
||||
description = 'ES5-compliant JavaScript interpreter';
|
||||
|
||||
node {
|
||||
version = '20.0.0';
|
||||
npmVersion = '8.0.0';
|
||||
download = true;
|
||||
}
|
||||
|
||||
task compileEnv(type: NpmTask) {
|
||||
dependsOn npmInstall;
|
||||
|
||||
inputs.files('rollup.config.js');
|
||||
inputs.dir('src/lib/libs');
|
||||
outputs.files("build/js/env.js");
|
||||
|
||||
// group = 'build'
|
||||
args = ['run', 'build-env'];
|
||||
}
|
||||
task compileTypescript(type: NpmTask) {
|
||||
dependsOn npmInstall;
|
||||
|
||||
inputs.files('rollup.config.js');
|
||||
inputs.dir('src/lib/transpiler');
|
||||
outputs.files("build/js/ts.js");
|
||||
// nom nom tasty ram
|
||||
environment.put("NODE_OPTIONS", "--max-old-space-size=4096");
|
||||
|
||||
// group = 'build'
|
||||
args = ['run', 'build-ts'];
|
||||
}
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral();
|
||||
}
|
||||
|
||||
dependencies {
|
||||
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2';
|
||||
compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2';
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2';
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher';
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17;
|
||||
targetCompatibility = JavaVersion.VERSION_17;
|
||||
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17);
|
||||
}
|
||||
}
|
||||
|
||||
configure([tasks.compileJava]) {
|
||||
options.release = 8;
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Main-Class': project.main_class,
|
||||
'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
|
||||
'Build-Branch': versioning.info.branch,
|
||||
'Build-Revision': versioning.info.commit,
|
||||
'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
|
||||
'Build-Author': 'TopchetoEU',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = project.main_class;
|
||||
applicationDefaultJvmArgs = ['-Xmx2G', '-Xms2G', '-server', '-Dfile.encoding=UTF-8'];
|
||||
}
|
||||
|
||||
distZip {
|
||||
eachFile { file ->
|
||||
if (file.path.contains('bin')) {
|
||||
file.exclude();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
distTar {
|
||||
eachFile { file ->
|
||||
if (file.path.contains('bin')) {
|
||||
file.exclude();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
dependsOn compileEnv;
|
||||
dependsOn compileTypescript;
|
||||
|
||||
from("build/js") {
|
||||
into "lib";
|
||||
}
|
||||
|
||||
filesMatching "metadata.json", {
|
||||
expand(
|
||||
version: project.project_version,
|
||||
name: project.project_name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform();
|
||||
}
|
||||
|
||||
wrapper {
|
||||
gradleVersion = '8.10';
|
||||
}
|
||||
23
build.gradle.kts
Normal file
23
build.gradle.kts
Normal file
@@ -0,0 +1,23 @@
|
||||
plugins {
|
||||
id("base");
|
||||
}
|
||||
|
||||
version = properties["project_version"].toString();
|
||||
group = properties["project_group"].toString();
|
||||
description = "ES5-compliant JavaScript interpreter";
|
||||
|
||||
tasks.wrapper {
|
||||
gradleVersion = "8.10";
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
subprojects.forEach { proj ->
|
||||
dependsOn(proj.tasks.named("build"));
|
||||
doLast {
|
||||
copy {
|
||||
from(proj.buildDir.resolve("libs"));
|
||||
into("$buildDir/libs");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
buildSrc/build.gradle.kts
Normal file
7
buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
repositories {
|
||||
mavenCentral();
|
||||
}
|
||||
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
12
buildSrc/src/main/kotlin/common-java.gradle.kts
Normal file
12
buildSrc/src/main/kotlin/common-java.gradle.kts
Normal file
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
id("common");
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17;
|
||||
targetCompatibility = JavaVersion.VERSION_17;
|
||||
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17);
|
||||
}
|
||||
}
|
||||
22
buildSrc/src/main/kotlin/common.gradle.kts
Normal file
22
buildSrc/src/main/kotlin/common.gradle.kts
Normal file
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id("java");
|
||||
}
|
||||
|
||||
version = rootProject.version;
|
||||
group = rootProject.group;
|
||||
base.archivesName = "${properties["project_name"]}-${project.name}";
|
||||
|
||||
tasks.named<JavaCompile>("compileJava") {
|
||||
options.release.set(8);
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral();
|
||||
}
|
||||
|
||||
dependencies {
|
||||
annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2");
|
||||
compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2");
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2");
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher");
|
||||
}
|
||||
18
common/build.gradle.kts
Normal file
18
common/build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("common-java");
|
||||
}
|
||||
|
||||
description = "A collection of utils and structures for the rest of the project";
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching("metadata", {
|
||||
expand(
|
||||
"version" to properties["project_version"],
|
||||
"name" to properties["project_name"],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
public class FunctionBody {
|
||||
public final FunctionBody[] children;
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public class Instruction {
|
||||
public static enum Type {
|
||||
58
common/src/main/java/me/topchetoeu/j2s/common/Metadata.java
Normal file
58
common/src/main/java/me/topchetoeu/j2s/common/Metadata.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
public class Metadata {
|
||||
private static String VERSION;
|
||||
private static String AUTHOR;
|
||||
private static String NAME;
|
||||
|
||||
static {
|
||||
var raw = Reading.resourceToString("metadata").split("\n");
|
||||
var line = 0;
|
||||
var file = "internal://metadata";
|
||||
|
||||
for (var el : raw) {
|
||||
line++;
|
||||
|
||||
el = el.trim();
|
||||
if (el.startsWith("#")) continue;
|
||||
if (el.isEmpty()) continue;
|
||||
|
||||
var i = el.indexOf(":");
|
||||
if (i < 0) throw new RuntimeException(String.format("%s:%s: Expected colon on line", file, line));
|
||||
|
||||
var name = el.substring(0, i).trim();
|
||||
var value = el.substring(i + 1).trim();
|
||||
|
||||
switch (name) {
|
||||
case "version":
|
||||
VERSION = value;
|
||||
break;
|
||||
case "author":
|
||||
AUTHOR = value;
|
||||
break;
|
||||
case "name":
|
||||
NAME = name;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("%s:%s: Unexpected metadata key '%s'", file, line, name));
|
||||
}
|
||||
}
|
||||
|
||||
if (VERSION == null) throw new RuntimeException(String.format("%s:%s: No version specified", file, line));
|
||||
if (AUTHOR == null) throw new RuntimeException(String.format("%s:%s: No author specified", file, line));
|
||||
if (NAME == null) throw new RuntimeException(String.format("%s:%s: No name specified", file, line));
|
||||
}
|
||||
|
||||
public static String version() {
|
||||
if (VERSION.equals("$" + "{VERSION}")) return "1337-devel";
|
||||
else return VERSION;
|
||||
}
|
||||
public static String author() {
|
||||
if (AUTHOR.equals("$" + "{AUTHOR}")) return "anonymous";
|
||||
else return AUTHOR;
|
||||
}
|
||||
public static String name() {
|
||||
if (NAME.equals("$" + "{NAME}")) return "some-product";
|
||||
else return NAME;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.topchetoeu.jscript.common;
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public class SyntaxException extends RuntimeException {
|
||||
public final Location loc;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.environment;
|
||||
package me.topchetoeu.j2s.common.environment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -63,8 +63,11 @@ public class Environment {
|
||||
}
|
||||
|
||||
public <T> T init(Key<T> key, T val) {
|
||||
if (!has(key)) this.add(key, val);
|
||||
return val;
|
||||
if (!has(key)) {
|
||||
this.add(key, val);
|
||||
return val;
|
||||
}
|
||||
else return get(key);
|
||||
}
|
||||
public <T> T initFrom(Key<T> key, Supplier<T> val) {
|
||||
if (!has(key)) {
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.topchetoeu.j2s.common.environment;
|
||||
|
||||
public final class Key<T> { }
|
||||
@@ -1,15 +1,16 @@
|
||||
package me.topchetoeu.jscript.common.json;
|
||||
package me.topchetoeu.j2s.common.json;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.parsing.Filename;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.common.Metadata;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
|
||||
public class JSON {
|
||||
public static ParseRes<JSONElement> parseString(Source src, int i) {
|
||||
@@ -100,7 +101,7 @@ public class JSON {
|
||||
return ParseRes.res(JSONElement.list(values), n);
|
||||
}
|
||||
public static JSONElement parse(Filename filename, String raw) {
|
||||
if (filename == null) filename = new Filename("jscript", "json");
|
||||
if (filename == null) filename = new Filename(Metadata.name(), "json");
|
||||
|
||||
var res = parseValue(new Source(null, filename, raw), 0);
|
||||
if (res.isFailed()) throw new SyntaxException(Location.of(filename, 0, 0), "Invalid JSON given");
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.json;
|
||||
package me.topchetoeu.j2s.common.json;
|
||||
|
||||
public class JSONElement {
|
||||
public static enum Type {
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.json;
|
||||
package me.topchetoeu.j2s.common.json;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.json;
|
||||
package me.topchetoeu.j2s.common.json;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.mapping;
|
||||
package me.topchetoeu.j2s.common.mapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -13,9 +13,9 @@ import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Filename;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public class FunctionMap {
|
||||
public static class FunctionMapBuilder {
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import me.topchetoeu.j2s.common.Metadata;
|
||||
|
||||
public abstract class Location implements Comparable<Location> {
|
||||
public static final Location INTERNAL = Location.of(new Filename("jscript", "native"), -1, -1);
|
||||
public static final Location INTERNAL = Location.of(new Filename(Metadata.name(), "native"), -1, -1);
|
||||
|
||||
public abstract int line();
|
||||
public abstract int start();
|
||||
@@ -30,9 +32,9 @@ public abstract class Location implements Comparable<Location> {
|
||||
};
|
||||
}
|
||||
public final Location nextLine() {
|
||||
return changeLine(1);
|
||||
return nextLine(1);
|
||||
}
|
||||
public final Location changeLine(int offset) {
|
||||
public final Location nextLine(int offset) {
|
||||
var self = this;
|
||||
|
||||
return new Location() {
|
||||
@@ -58,7 +60,14 @@ public abstract class Location implements Comparable<Location> {
|
||||
}
|
||||
|
||||
@Override public int compareTo(Location other) {
|
||||
int a = filename().toString().compareTo(other.filename().toString());
|
||||
int a;
|
||||
var filenameA = filename();
|
||||
var filenameB = other.filename();
|
||||
if (filenameB == null && filenameA == null) a = 0;
|
||||
else if (filenameA == null) a = -1;
|
||||
else if (filenameB == null) a = 1;
|
||||
else a = filenameA.toString().compareTo(filenameB.toString());
|
||||
|
||||
int b = Integer.compare(line(), other.line());
|
||||
int c = Integer.compare(start(), other.start());
|
||||
|
||||
@@ -77,21 +86,27 @@ public abstract class Location implements Comparable<Location> {
|
||||
}
|
||||
|
||||
public static Location of(String raw) {
|
||||
var i0 = raw.lastIndexOf(':');
|
||||
if (i0 < 0) return Location.of(Filename.parse(raw), -1, -1);
|
||||
var i1 = raw.lastIndexOf(':');
|
||||
if (i1 < 0) return Location.of(Filename.parse(raw), -1, -1);
|
||||
|
||||
var i1 = raw.lastIndexOf(':', i0);
|
||||
var i0 = raw.substring(0, i1).lastIndexOf(':', i1);
|
||||
if (i0 < 0) {
|
||||
try {
|
||||
return Location.of(Filename.parse(raw.substring(0, i0)), Integer.parseInt(raw.substring(i0 + 1)), -1);
|
||||
return Location.of(null, Integer.parseInt(raw.substring(0, i1)) - 1, Integer.parseInt(raw.substring(i1 + 1)) - 1);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return Location.of(Filename.parse(raw), -1, -1);
|
||||
catch (NumberFormatException e) {}
|
||||
|
||||
try {
|
||||
return Location.of(Filename.parse(raw.substring(0, i1)), Integer.parseInt(raw.substring(i1 + 1)) - 1, -1);
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
|
||||
return Location.of(Filename.parse(raw), -1, -1);
|
||||
}
|
||||
|
||||
int start, line;
|
||||
|
||||
|
||||
try {
|
||||
start = Integer.parseInt(raw.substring(i1 + 1));
|
||||
}
|
||||
@@ -103,9 +118,9 @@ public abstract class Location implements Comparable<Location> {
|
||||
line = Integer.parseInt(raw.substring(i0 + 1, i1));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return Location.of(Filename.parse(raw.substring(i1 + 1)), start, -1);
|
||||
return Location.of(Filename.parse(raw.substring(0, i1)), start - 1, -1);
|
||||
}
|
||||
|
||||
return Location.of(Filename.parse(raw.substring(0, i0)), start, line);
|
||||
return Location.of(Filename.parse(raw.substring(0, i0)), line - 1, start - 1);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
public class ParseRes<T> {
|
||||
public static enum State {
|
||||
@@ -33,19 +33,20 @@ public class ParseRes<T> {
|
||||
if (!state.isSuccess()) return this;
|
||||
return new ParseRes<>(state, null, null, result, this.n + n);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T2> ParseRes<T2> chainError() {
|
||||
if (isSuccess()) throw new RuntimeException("Can't transform a ParseRes that hasn't failed");
|
||||
return new ParseRes<>(state, errorLocation, error, null, 0);
|
||||
return (ParseRes<T2>)this;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T2> ParseRes<T2> chainError(ParseRes<?> other) {
|
||||
if (!this.isError()) return other.chainError();
|
||||
return (ParseRes<T2>) this;
|
||||
if (this.isError()) return other.chainError();
|
||||
return (ParseRes<T2>)this;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T2> ParseRes<T2> chainError(Location loc, String error) {
|
||||
if (!this.isError()) return new ParseRes<>(State.ERROR, loc, error, null, 0);
|
||||
return (ParseRes<T2>) this;
|
||||
return (ParseRes<T2>)this;
|
||||
}
|
||||
|
||||
public boolean isSuccess() { return state.isSuccess(); }
|
||||
@@ -63,7 +64,6 @@ public class ParseRes<T> {
|
||||
return new ParseRes<>(State.SUCCESS, null, null, val, i);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("all")
|
||||
public static <T> ParseRes<T> first(Source src, int i, Parser ...parsers) {
|
||||
int n = Parsing.skipEmpty(src, i);
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
public interface Parser<T> {
|
||||
public ParseRes<T> parse(Source src, int i);
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
|
||||
public class Parsing {
|
||||
public static boolean isDigit(Character c) {
|
||||
@@ -346,8 +345,8 @@ public class Parsing {
|
||||
if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus");
|
||||
return ParseRes.failed();
|
||||
}
|
||||
else if (negative) return ParseRes.res(-(whole + fract) * NumberNode.power(10, exponent), n);
|
||||
else return ParseRes.res((whole + fract) * NumberNode.power(10, exponent), n);
|
||||
else if (negative) return ParseRes.res(-(whole + fract) * power(10, exponent), n);
|
||||
else return ParseRes.res((whole + fract) * power(10, exponent), n);
|
||||
}
|
||||
public static ParseRes<Double> parseFloat(Source src, int i, boolean withMinus) {
|
||||
var n = skipEmpty(src, i);
|
||||
@@ -406,9 +405,10 @@ public class Parsing {
|
||||
if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus");
|
||||
return ParseRes.failed();
|
||||
}
|
||||
else if (negative) return ParseRes.res(-(whole + fract) * NumberNode.power(10, exponent), n);
|
||||
else return ParseRes.res((whole + fract) * NumberNode.power(10, exponent), n);
|
||||
else if (negative) return ParseRes.res(-(whole + fract) * power(10, exponent), n);
|
||||
else return ParseRes.res((whole + fract) * power(10, exponent), n);
|
||||
}
|
||||
|
||||
public static ParseRes<Double> parseInt(Source src, int i, String alphabet, boolean withMinus) {
|
||||
var n = skipEmpty(src, i);
|
||||
|
||||
@@ -425,16 +425,20 @@ public class Parsing {
|
||||
n += 2;
|
||||
|
||||
var res = parseHex(src, i);
|
||||
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Incomplete hexadecimal literal");
|
||||
if (!res.isSuccess())
|
||||
return res.chainError(src.loc(i + n), "Incomplete hexadecimal literal");
|
||||
n += res.n;
|
||||
|
||||
if (negative) return ParseRes.res(-res.result, n);
|
||||
else return ParseRes.res(res.result, n);
|
||||
if (negative)
|
||||
return ParseRes.res(-res.result, n);
|
||||
else
|
||||
return ParseRes.res(res.result, n);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var digit = alphabet.indexOf(Character.toLowerCase(src.at(i + n, '\0')));
|
||||
if (digit < 0) break;
|
||||
if (digit < 0)
|
||||
break;
|
||||
|
||||
parsedAny = true;
|
||||
result *= alphabet.length();
|
||||
@@ -443,10 +447,21 @@ public class Parsing {
|
||||
}
|
||||
|
||||
if (!parsedAny) {
|
||||
if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus");
|
||||
if (negative)
|
||||
return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus");
|
||||
return ParseRes.failed();
|
||||
}
|
||||
else if (negative) return ParseRes.res(-result, n);
|
||||
else return ParseRes.res(result, n);
|
||||
} else if (negative)
|
||||
return ParseRes.res(-result, n);
|
||||
else
|
||||
return ParseRes.res(result, n);
|
||||
}
|
||||
|
||||
private static double power(double a, long b) {
|
||||
if (b == 0) return 1;
|
||||
if (b == 1) return a;
|
||||
if (b < 0) return 1 / power(a, -b);
|
||||
|
||||
if ((b & 1) == 0) return power(a * a, b / 2);
|
||||
else return a * power(a * a, b / 2);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import me.topchetoeu.jscript.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
|
||||
public class Source {
|
||||
public final Environment env;
|
||||
@@ -12,6 +12,8 @@ public class Source {
|
||||
private int[] lineStarts;
|
||||
|
||||
public Location loc(int offset) {
|
||||
if (offset < 0) offset = 0;
|
||||
if (offset > src.length()) offset = src.length();
|
||||
return new SourceLocation(filename, lineStarts, offset);
|
||||
}
|
||||
public boolean is(int i, char c) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.common.parsing;
|
||||
package me.topchetoeu.j2s.common.parsing;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
3
common/src/main/resources/metadata
Normal file
3
common/src/main/resources/metadata
Normal file
@@ -0,0 +1,3 @@
|
||||
version: ${version}
|
||||
name: ${name}
|
||||
author: TopchetoEU
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript;
|
||||
package me.topchetoeu.j2s;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.environment.Key;
|
||||
|
||||
public class TestEnvironment {
|
||||
private final Key<String> FOO = new Key<>();
|
||||
private final Key<Void> MARKER = new Key<>();
|
||||
|
||||
@Test public void testShouldCreate() {
|
||||
new Environment();
|
||||
Environment.empty();
|
||||
}
|
||||
@Test public void testShouldNotExist() {
|
||||
var env = new Environment();
|
||||
assertEquals(null, env.get(FOO));
|
||||
assertEquals(false, env.has(FOO));
|
||||
}
|
||||
|
||||
@Test public void testShouldAdd() {
|
||||
var env = new Environment();
|
||||
env.add(FOO, "test");
|
||||
assertEquals("test", env.get(FOO));
|
||||
}
|
||||
|
||||
@Test public void testShouldGetFromParent() {
|
||||
var parent = new Environment();
|
||||
parent.add(FOO, "test");
|
||||
var child = parent.child();
|
||||
assertEquals("test", child.get(FOO));
|
||||
assertEquals(true, child.has(FOO));
|
||||
}
|
||||
@Test public void testShouldHideParent() {
|
||||
var parent = new Environment();
|
||||
parent.add(FOO, "test");
|
||||
var child = parent.child();
|
||||
child.remove(FOO);
|
||||
assertEquals(null, child.get(FOO));
|
||||
assertEquals(false, child.has(FOO));
|
||||
}
|
||||
|
||||
@Test public void testShouldAddMarker() {
|
||||
var env = new Environment();
|
||||
env.add(MARKER);
|
||||
assertEquals(true, env.has(MARKER));
|
||||
assertEquals(false, env.hasNotNull(MARKER));
|
||||
}
|
||||
|
||||
@Test public void testShouldInitOnce() {
|
||||
var env = new Environment();
|
||||
assertEquals("a", env.init(FOO, "a"));
|
||||
assertEquals("a", env.init(FOO, "b"));
|
||||
assertEquals("a", env.get(FOO));
|
||||
}
|
||||
@Test public void testShouldInitOnceFrom() {
|
||||
var env = new Environment();
|
||||
assertEquals("a", env.initFrom(FOO, () -> "a"));
|
||||
assertEquals("a", env.initFrom(FOO, () -> "b"));
|
||||
assertEquals("a", env.get(FOO));
|
||||
}
|
||||
|
||||
@Test public void testShouldWrap() {
|
||||
var env = new Environment();
|
||||
assertEquals(env, Environment.wrap(env));
|
||||
assertInstanceOf(Environment.class, Environment.wrap(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestFilename {
|
||||
@Test public void testShouldParseFilePath() {
|
||||
var filename = Filename.parse("file://hello.world");
|
||||
assertEquals("file", filename.protocol);
|
||||
assertEquals("hello.world", filename.path);
|
||||
}
|
||||
@Test public void testShouldParseNoProtocolFilename() {
|
||||
var filename = Filename.parse("hello.world");
|
||||
assertEquals("file", filename.protocol);
|
||||
assertEquals("hello.world", filename.path);
|
||||
}
|
||||
@Test public void testShouldParseAdditionalSlashFilename() {
|
||||
var filename = Filename.parse("test:///hello.world");
|
||||
assertEquals("test", filename.protocol);
|
||||
assertEquals("/hello.world", filename.path);
|
||||
}
|
||||
@Test public void testShouldParseOneSlashFilename() {
|
||||
var filename = Filename.parse("test:/hello.world");
|
||||
assertEquals("file", filename.protocol);
|
||||
assertEquals("test:/hello.world", filename.path);
|
||||
}
|
||||
@Test public void testShouldParseMatroshkaFilename() {
|
||||
var a = Filename.parse("a://b://hello.world");
|
||||
assertEquals("a", a.protocol);
|
||||
assertEquals("b://hello.world", a.path);
|
||||
|
||||
var b = Filename.parse(a.path);
|
||||
assertEquals("b", b.protocol);
|
||||
assertEquals("hello.world", b.path);
|
||||
}
|
||||
}
|
||||
162
common/src/test/java/me/topchetoeu/j2s/common/TestLocation.java
Normal file
162
common/src/test/java/me/topchetoeu/j2s/common/TestLocation.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestLocation {
|
||||
@Test public void testShouldCreateLocation() {
|
||||
var loc = Location.of(new Filename("file", "test.txt"), 10, 5);
|
||||
assertEquals("test.txt", loc.filename().path);
|
||||
assertEquals(10, loc.line());
|
||||
assertEquals(5, loc.start());
|
||||
}
|
||||
|
||||
@Test public void testShouldGetNextLineLocation() {
|
||||
var loc = Location.of("test.txt:10:5");
|
||||
var next = loc.nextLine();
|
||||
assertEquals(new Filename("file", "test.txt"), next.filename());
|
||||
assertEquals(10, next.line());
|
||||
assertEquals(0, next.start());
|
||||
assertEquals(new Filename("file", "test.txt"), loc.filename());
|
||||
assertEquals(9, loc.line());
|
||||
assertEquals(4, loc.start());
|
||||
}
|
||||
@Test public void testShouldGetNextNthLineLocation() {
|
||||
var loc = Location.of(new Filename("file", "test.txt"), 10, 5);
|
||||
var next = loc.nextLine(5);
|
||||
assertEquals(15, next.line());
|
||||
assertEquals(0, next.start());
|
||||
assertEquals(10, loc.line());
|
||||
assertEquals(5, loc.start());
|
||||
}
|
||||
|
||||
@Test public void testShouldGetNextLocation() {
|
||||
var loc = Location.of("test:10:5");
|
||||
var next = loc.add(10);
|
||||
assertEquals(new Filename("file", "test"), next.filename());
|
||||
assertEquals(9, next.line());
|
||||
assertEquals(14, next.start());
|
||||
assertEquals(new Filename("file", "test"), loc.filename());
|
||||
assertEquals(9, loc.line());
|
||||
assertEquals(4, loc.start());
|
||||
}
|
||||
|
||||
@Test public void testShouldParseLocation() {
|
||||
var loc = Location.of("test.txt:10:5");
|
||||
assertEquals(new Filename("file", "test.txt"), loc.filename());
|
||||
assertEquals(9, loc.line());
|
||||
assertEquals(4, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseComplexFilenameLocation() {
|
||||
var loc = Location.of("testificate://test.txt:10:5");
|
||||
assertEquals(new Filename("testificate", "test.txt"), loc.filename());
|
||||
assertEquals(9, loc.line());
|
||||
assertEquals(4, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseNoFilenameLocation() {
|
||||
var loc = Location.of("10:5");
|
||||
assertEquals(null, loc.filename());
|
||||
assertEquals(9, loc.line());
|
||||
assertEquals(4, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseNoStartLocationA() {
|
||||
var loc = Location.of("file://10:5");
|
||||
assertEquals(new Filename("file", "10"), loc.filename());
|
||||
assertEquals(4, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseNoStartLocationB() {
|
||||
var loc = Location.of("file:5");
|
||||
assertEquals(new Filename("file", "file"), loc.filename());
|
||||
assertEquals(4, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseOnlyFilenameLocationA() {
|
||||
var loc = Location.of("http://example.org/test.txt");
|
||||
assertEquals(new Filename("http", "example.org/test.txt"), loc.filename());
|
||||
assertEquals(-1, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseOnlyFilenameLocationB() {
|
||||
var loc = Location.of("test.txt");
|
||||
assertEquals(new Filename("file", "test.txt"), loc.filename());
|
||||
assertEquals(-1, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseOnlyFilenameWithColonLocation() {
|
||||
var loc = Location.of("my-file:bad-file");
|
||||
assertEquals(new Filename("file", "my-file:bad-file"), loc.filename());
|
||||
assertEquals(-1, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
@Test public void testShouldParseOnlyFilenameWithTripleColonLocation() {
|
||||
var loc = Location.of("a:my-file:bad-file");
|
||||
assertEquals(new Filename("file", "a:my-file:bad-file"), loc.filename());
|
||||
assertEquals(-1, loc.line());
|
||||
assertEquals(-1, loc.start());
|
||||
}
|
||||
|
||||
@Test public void testCompareEqualLoc() {
|
||||
var locA = Location.of("test:10:5");
|
||||
var locB = Location.of("test:10:5");
|
||||
|
||||
assertEquals(0, locA.compareTo(locB));
|
||||
assertEquals(0, locB.compareTo(locA));
|
||||
}
|
||||
@Test public void testCompareNoFileLoc() {
|
||||
var locA = Location.of("10:5");
|
||||
var locB = Location.of("11:5");
|
||||
|
||||
assertEquals(-1, locA.compareTo(locB));
|
||||
assertEquals(1, locB.compareTo(locA));
|
||||
}
|
||||
@Test public void testCompareOneNoFileLoc() {
|
||||
var locA = Location.of("10:5");
|
||||
var locB = Location.of("test:10:5");
|
||||
|
||||
assertEquals(-1, locA.compareTo(locB));
|
||||
assertEquals(1, locB.compareTo(locA));
|
||||
}
|
||||
@Test public void testCompareDiffFileLoc() {
|
||||
var locA = Location.of("a:10:5");
|
||||
var locB = Location.of("b:10:5");
|
||||
|
||||
assertEquals(-1, locA.compareTo(locB));
|
||||
assertEquals(1, locB.compareTo(locA));
|
||||
}
|
||||
@Test public void testCompareDiffLineLoc() {
|
||||
var locA = Location.of("test:10:5");
|
||||
var locB = Location.of("test:11:5");
|
||||
|
||||
assertEquals(-1, locA.compareTo(locB));
|
||||
assertEquals(1, locB.compareTo(locA));
|
||||
}
|
||||
@Test public void testCompareDiffStartLoc() {
|
||||
var locA = Location.of("test:10:5");
|
||||
var locB = Location.of("test:10:10");
|
||||
|
||||
assertEquals(-1, locA.compareTo(locB));
|
||||
assertEquals(1, locB.compareTo(locA));
|
||||
}
|
||||
|
||||
@Test public void testToStringAll() {
|
||||
var locA = Location.of("test:10:5");
|
||||
assertEquals("file://test:10:5", locA.toString());
|
||||
}
|
||||
@Test public void testToStringNoFilename() {
|
||||
var locA = Location.of("10:5");
|
||||
assertEquals("10:5", locA.toString());
|
||||
}
|
||||
@Test public void testToStringNoStart() {
|
||||
var locA = Location.of("file:5");
|
||||
assertEquals("file://file:5", locA.toString());
|
||||
}
|
||||
@Test public void testToStringNoLoc() {
|
||||
var locA = Location.of("file");
|
||||
assertEquals("file://file", locA.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
|
||||
public class TestParseRes {
|
||||
@Test public void testCreateFailed() {
|
||||
var res = ParseRes.failed();
|
||||
assertEquals(false, res.isSuccess());
|
||||
assertEquals(true, res.isFailed());
|
||||
assertEquals(false, res.isError());
|
||||
assertEquals(0, res.n);
|
||||
assertEquals(null, res.result);
|
||||
assertEquals(null, res.errorLocation);
|
||||
assertEquals(null, res.error);
|
||||
}
|
||||
@Test public void testCreateError() {
|
||||
var res = ParseRes.error(Location.of("test:10:5"), "test");
|
||||
assertEquals(false, res.isSuccess());
|
||||
assertEquals(false, res.isFailed());
|
||||
assertEquals(true, res.isError());
|
||||
assertEquals(0, res.n);
|
||||
assertEquals(null, res.result);
|
||||
assertEquals(Location.of("test:10:5"), res.errorLocation);
|
||||
assertEquals("test", res.error);
|
||||
}
|
||||
@Test public void testCreateResult() {
|
||||
var res = ParseRes.res("test", 10);
|
||||
assertEquals(true, res.isSuccess());
|
||||
assertEquals(false, res.isFailed());
|
||||
assertEquals(false, res.isError());
|
||||
assertEquals(10, res.n);
|
||||
assertEquals("test", res.result);
|
||||
assertEquals(null, res.errorLocation);
|
||||
assertEquals(null, res.error);
|
||||
}
|
||||
|
||||
@Test public void testChainFailed() {
|
||||
var a = ParseRes.<Integer>failed();
|
||||
|
||||
var b1 = a.<String>chainError();
|
||||
assertEquals(a, b1);
|
||||
|
||||
var b2 = a.<String>chainError(Location.of("test:1:2"), "test");
|
||||
assertEquals(true, b2.isError());
|
||||
assertEquals("test", b2.error);
|
||||
}
|
||||
@Test public void testChainError() {
|
||||
var a = ParseRes.<Integer>error(Location.of("test:1:2"), "test");
|
||||
|
||||
var b1 = a.<String>chainError();
|
||||
assertEquals(a, b1);
|
||||
|
||||
var b2 = a.<String>chainError(Location.of("test:1:2"), "test");
|
||||
assertEquals(a, b2);
|
||||
}
|
||||
@Test public void testChainResult() {
|
||||
var a = ParseRes.<Integer>res(10, 6);
|
||||
|
||||
assertThrows(RuntimeException.class, () -> a.<String>chainError());
|
||||
|
||||
var b1 = a.<String>chainError(Location.of("test:1:2"), "test");
|
||||
assertEquals(true, b1.isError());
|
||||
assertEquals("test", b1.error);
|
||||
}
|
||||
|
||||
|
||||
@Test public void testShouldAdd5() {
|
||||
var a = ParseRes.res("test", 6);
|
||||
var b = a.addN(5);
|
||||
|
||||
assertEquals(11, b.n);
|
||||
}
|
||||
@Test public void testShouldSet5() {
|
||||
var a = ParseRes.res("test", 6);
|
||||
var b = a.setN(5);
|
||||
|
||||
assertEquals(5, b.n);
|
||||
}
|
||||
|
||||
@Test public void testShouldNotAdd() {
|
||||
var a = ParseRes.failed();
|
||||
var b = a.addN(5);
|
||||
|
||||
assertEquals(0, b.n);
|
||||
}
|
||||
@Test public void testShouldNotSet() {
|
||||
var a = ParseRes.failed();
|
||||
var b = a.setN(5);
|
||||
|
||||
assertEquals(0, b.n);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.topchetoeu.j2s.common;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
|
||||
public class TestSource {
|
||||
private Source mkSource(String src) {
|
||||
return new Source(new Environment(), Filename.parse("test"), src);
|
||||
}
|
||||
|
||||
@Test public void testShouldCreate() {
|
||||
new Source(new Environment(), Filename.parse("test"), "my little source :)");
|
||||
new Source(null, Filename.parse("test"), "my little source :)");
|
||||
}
|
||||
|
||||
@Test public void testShouldGet() {
|
||||
var src = mkSource("1234567890");
|
||||
assertEquals('1', src.at(0));
|
||||
assertEquals('6', src.at(5));
|
||||
}
|
||||
@Test public void testShouldThrowOutOfRange() {
|
||||
var src = mkSource("1234567890");
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> src.at(-1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> src.at(10));
|
||||
}
|
||||
@Test public void testImmutableSrcLoc() {
|
||||
var src = mkSource("1234567890");
|
||||
var loc = src.loc(5);
|
||||
// kinda stupid
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
assertEquals(5, loc.start());
|
||||
assertEquals(0, loc.line());
|
||||
assertEquals(Filename.parse("test"), loc.filename());
|
||||
}
|
||||
}
|
||||
@Test public void testSingleLineSourceLocation() {
|
||||
var src = mkSource("1234567890");
|
||||
assertEquals(Location.of("test:1:1"), src.loc(-5));
|
||||
assertEquals(Location.of("test:1:1"), src.loc(0));
|
||||
assertEquals(Location.of("test:1:10"), src.loc(9));
|
||||
assertEquals(Location.of("test:1:11"), src.loc(14));
|
||||
}
|
||||
@Test public void testMultilineSourceLocation() {
|
||||
var src = mkSource("123\n456\n\n789\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
||||
assertEquals(Location.of("test:1:1"), src.loc(-5));
|
||||
assertEquals(Location.of("test:1:1"), src.loc(0));
|
||||
assertEquals(Location.of("test:1:4"), src.loc(3));
|
||||
assertEquals(Location.of("test:2:1"), src.loc(4));
|
||||
assertEquals(Location.of("test:2:4"), src.loc(7));
|
||||
assertEquals(Location.of("test:3:1"), src.loc(8));
|
||||
assertEquals(Location.of("test:4:1"), src.loc(9));
|
||||
assertEquals(Location.of("test:4:2"), src.loc(10));
|
||||
assertEquals(Location.of("test:4:4"), src.loc(12));
|
||||
assertEquals(Location.of("test:5:1"), src.loc(13));
|
||||
assertEquals(Location.of("test:19:1"), src.loc(50));
|
||||
}
|
||||
}
|
||||
22
compilation/build.gradle.kts
Normal file
22
compilation/build.gradle.kts
Normal file
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id("common-java");
|
||||
}
|
||||
|
||||
description = "A compiler of EcmaScript 5 code to J2S bytecode";
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching("metadata.json", {
|
||||
expand(
|
||||
"version" to properties["project_version"],
|
||||
"name" to properties["project_name"],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform();
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":common"));
|
||||
}
|
||||
@@ -1,24 +1,27 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.function.Function;
|
||||
|
||||
import me.topchetoeu.j2s.common.FunctionBody;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.environment.Key;
|
||||
import me.topchetoeu.j2s.common.mapping.FunctionMap;
|
||||
import me.topchetoeu.j2s.common.mapping.FunctionMap.FunctionMapBuilder;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.control.TryNode;
|
||||
import me.topchetoeu.j2s.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.j2s.compilation.scope.Variable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import me.topchetoeu.jscript.common.FunctionBody;
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.environment.Environment;
|
||||
import me.topchetoeu.jscript.common.environment.Key;
|
||||
import me.topchetoeu.jscript.common.mapping.FunctionMap;
|
||||
import me.topchetoeu.jscript.common.mapping.FunctionMap.FunctionMapBuilder;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.control.TryNode;
|
||||
import me.topchetoeu.jscript.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.jscript.compilation.scope.Variable;
|
||||
|
||||
public final class CompileResult {
|
||||
public static final Key<Void> DEBUG_LOG = new Key<>();
|
||||
|
||||
@@ -63,9 +66,31 @@ public final class CompileResult {
|
||||
public void setLocation(Location type) {
|
||||
setLocation(instructions.size() - 1, type);
|
||||
}
|
||||
|
||||
public void setLocationAndDebug(Location loc, BreakpointType type) {
|
||||
setLocationAndDebug(instructions.size() - 1, loc, type);
|
||||
}
|
||||
|
||||
public Iterable<FunctionBody> bodies() {
|
||||
var stack = new Stack<FunctionBody>();
|
||||
stack.push(body());
|
||||
|
||||
return () -> new Iterator<FunctionBody>() {
|
||||
@Override public FunctionBody next() {
|
||||
if (stack.empty()) return null;
|
||||
else {
|
||||
var res = stack.pop();
|
||||
for (var el : res.children) {
|
||||
stack.push(el);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@Override public boolean hasNext() {
|
||||
return !stack.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public CompileResult addChild(FunctionNode node, CompileResult res) {
|
||||
this.children.add(res);
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
|
||||
|
||||
public class CompoundNode extends Node {
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.environment.Environment;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public abstract class FunctionNode extends Node {
|
||||
public final CompoundNode body;
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.scope.Variable;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.scope.Variable;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class FunctionStatementNode extends FunctionNode {
|
||||
public final String name;
|
||||
@@ -1,11 +1,11 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class FunctionValueNode extends FunctionNode {
|
||||
public final String name;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -6,45 +6,45 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.environment.Environment;
|
||||
import me.topchetoeu.jscript.common.environment.Key;
|
||||
import me.topchetoeu.jscript.common.parsing.Filename;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.control.BreakNode;
|
||||
import me.topchetoeu.jscript.compilation.control.ContinueNode;
|
||||
import me.topchetoeu.jscript.compilation.control.DebugNode;
|
||||
import me.topchetoeu.jscript.compilation.control.DeleteNode;
|
||||
import me.topchetoeu.jscript.compilation.control.DoWhileNode;
|
||||
import me.topchetoeu.jscript.compilation.control.ForInNode;
|
||||
import me.topchetoeu.jscript.compilation.control.ForNode;
|
||||
import me.topchetoeu.jscript.compilation.control.IfNode;
|
||||
import me.topchetoeu.jscript.compilation.control.ReturnNode;
|
||||
import me.topchetoeu.jscript.compilation.control.SwitchNode;
|
||||
import me.topchetoeu.jscript.compilation.control.ThrowNode;
|
||||
import me.topchetoeu.jscript.compilation.control.TryNode;
|
||||
import me.topchetoeu.jscript.compilation.control.WhileNode;
|
||||
import me.topchetoeu.jscript.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.jscript.compilation.values.ArgumentsNode;
|
||||
import me.topchetoeu.jscript.compilation.values.ArrayNode;
|
||||
import me.topchetoeu.jscript.compilation.values.GlobalThisNode;
|
||||
import me.topchetoeu.jscript.compilation.values.ObjectNode;
|
||||
import me.topchetoeu.jscript.compilation.values.RegexNode;
|
||||
import me.topchetoeu.jscript.compilation.values.ThisNode;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.BoolNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NullNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.CallNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.ChangeNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.DiscardNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.IndexNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.OperationNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.PostfixNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.TypeofNode;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.environment.Key;
|
||||
import me.topchetoeu.j2s.common.parsing.Filename;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.control.BreakNode;
|
||||
import me.topchetoeu.j2s.compilation.control.ContinueNode;
|
||||
import me.topchetoeu.j2s.compilation.control.DebugNode;
|
||||
import me.topchetoeu.j2s.compilation.control.DeleteNode;
|
||||
import me.topchetoeu.j2s.compilation.control.DoWhileNode;
|
||||
import me.topchetoeu.j2s.compilation.control.ForInNode;
|
||||
import me.topchetoeu.j2s.compilation.control.ForNode;
|
||||
import me.topchetoeu.j2s.compilation.control.IfNode;
|
||||
import me.topchetoeu.j2s.compilation.control.ReturnNode;
|
||||
import me.topchetoeu.j2s.compilation.control.SwitchNode;
|
||||
import me.topchetoeu.j2s.compilation.control.ThrowNode;
|
||||
import me.topchetoeu.j2s.compilation.control.TryNode;
|
||||
import me.topchetoeu.j2s.compilation.control.WhileNode;
|
||||
import me.topchetoeu.j2s.compilation.scope.FunctionScope;
|
||||
import me.topchetoeu.j2s.compilation.values.ArgumentsNode;
|
||||
import me.topchetoeu.j2s.compilation.values.ArrayNode;
|
||||
import me.topchetoeu.j2s.compilation.values.GlobalThisNode;
|
||||
import me.topchetoeu.j2s.compilation.values.ObjectNode;
|
||||
import me.topchetoeu.j2s.compilation.values.RegexNode;
|
||||
import me.topchetoeu.j2s.compilation.values.ThisNode;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.BoolNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NullNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.StringNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.CallNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.ChangeNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.DiscardNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.IndexNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.OperationNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.PostfixNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.TypeofNode;
|
||||
|
||||
public final class JavaScript {
|
||||
public static enum DeclarationType {
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.environment.Environment;
|
||||
import me.topchetoeu.jscript.common.environment.Key;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.environment.Environment;
|
||||
import me.topchetoeu.j2s.common.environment.Key;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public class LabelContext {
|
||||
public static final Key<LabelContext> BREAK_CTX = new Key<>();
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public abstract class Node {
|
||||
private Location loc;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
|
||||
public final class Parameter {
|
||||
public final Location loc;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation;
|
||||
package me.topchetoeu.j2s.compilation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class VariableDeclareNode extends Node {
|
||||
@Desugar
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class BreakNode extends Node {
|
||||
public final String label;
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class ContinueNode extends Node {
|
||||
public final String label;
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class DebugNode extends Node {
|
||||
@Override public void compileFunctions(CompileResult target) {
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.BoolNode;
|
||||
import me.topchetoeu.jscript.compilation.values.operations.IndexNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.BoolNode;
|
||||
import me.topchetoeu.j2s.compilation.values.operations.IndexNode;
|
||||
|
||||
public class DeleteNode extends Node {
|
||||
public final Node key;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class DoWhileNode extends Node {
|
||||
public final Node condition, body;
|
||||
@@ -1,17 +1,17 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class ForInNode extends Node {
|
||||
public final boolean isDecl;
|
||||
@@ -21,7 +21,9 @@ public class ForInNode extends Node {
|
||||
|
||||
@Override public void resolve(CompileResult target) {
|
||||
body.resolve(target);
|
||||
binding.resolve(target);
|
||||
if (isDecl) {
|
||||
target.scope.define(binding.name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void compileFunctions(CompileResult target) {
|
||||
@@ -1,17 +1,17 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.VariableDeclareNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.VariableDeclareNode;
|
||||
|
||||
public class ForNode extends Node {
|
||||
public final Node declaration, assignment, condition, body;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class IfNode extends Node {
|
||||
public final Node condition, body, elseBody;
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class ReturnNode extends Node {
|
||||
public final Node value;
|
||||
@@ -1,20 +1,20 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class SwitchNode extends Node {
|
||||
public static class SwitchCase {
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class ThrowNode extends Node {
|
||||
public final Node value;
|
||||
@@ -1,17 +1,17 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.CompoundNode;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.CompoundNode;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class TryNode extends Node {
|
||||
public final CompoundNode tryBody;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.control;
|
||||
package me.topchetoeu.j2s.compilation.control;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.LabelContext;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.DeferredIntSupplier;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.LabelContext;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class WhileNode extends Node {
|
||||
public final Node condition, body;
|
||||
@@ -1,14 +1,14 @@
|
||||
package me.topchetoeu.jscript.compilation.members;
|
||||
package me.topchetoeu.j2s.compilation.members;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.ObjectNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.ObjectNode;
|
||||
|
||||
public class FieldMemberNode implements Member {
|
||||
public final Location loc;
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.topchetoeu.j2s.compilation.members;
|
||||
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
|
||||
public interface Member {
|
||||
Location loc();
|
||||
|
||||
void compileFunctions(CompileResult target);
|
||||
void compile(CompileResult target, boolean pollute);
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package me.topchetoeu.jscript.compilation.members;
|
||||
package me.topchetoeu.j2s.compilation.members;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.CompoundNode;
|
||||
import me.topchetoeu.jscript.compilation.FunctionNode;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.ObjectNode;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.CompoundNode;
|
||||
import me.topchetoeu.j2s.compilation.FunctionNode;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.ObjectNode;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.StringNode;
|
||||
|
||||
public final class PropertyMemberNode extends FunctionNode implements Member {
|
||||
public final Node key;
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.topchetoeu.jscript.compilation.patterns;
|
||||
package me.topchetoeu.j2s.compilation.patterns;
|
||||
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
|
||||
/**
|
||||
* Represents all nodes that can be assign targets
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation.patterns;
|
||||
package me.topchetoeu.j2s.compilation.patterns;
|
||||
|
||||
/**
|
||||
* Represents all nodes that can be converted to assign targets
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.topchetoeu.j2s.compilation.patterns;
|
||||
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
|
||||
public interface ChangeTarget extends AssignTarget {
|
||||
void beforeChange(CompileResult target);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
package me.topchetoeu.j2s.compilation.scope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
package me.topchetoeu.j2s.compilation.scope;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
package me.topchetoeu.j2s.compilation.scope;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
|
||||
public final class VariableIndex {
|
||||
public static enum IndexType {
|
||||
@@ -1,11 +1,11 @@
|
||||
package me.topchetoeu.jscript.compilation.scope;
|
||||
package me.topchetoeu.j2s.compilation.scope;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import me.topchetoeu.jscript.compilation.scope.VariableIndex.IndexType;
|
||||
import me.topchetoeu.j2s.compilation.scope.VariableIndex.IndexType;
|
||||
|
||||
public final class VariableList implements Iterable<Variable> {
|
||||
private final class VariableNode implements Supplier<VariableIndex> {
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class ArgumentsNode extends Node {
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class ArrayNode extends Node {
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class GlobalThisNode extends Node {
|
||||
@@ -1,21 +1,21 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.members.FieldMemberNode;
|
||||
import me.topchetoeu.jscript.compilation.members.Member;
|
||||
import me.topchetoeu.jscript.compilation.members.PropertyMemberNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.members.FieldMemberNode;
|
||||
import me.topchetoeu.j2s.compilation.members.Member;
|
||||
import me.topchetoeu.j2s.compilation.members.PropertyMemberNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.StringNode;
|
||||
|
||||
public class ObjectNode extends Node {
|
||||
public final List<Member> members;
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class RegexNode extends Node {
|
||||
public final String pattern, flags;
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class ThisNode extends Node {
|
||||
@@ -1,14 +1,14 @@
|
||||
package me.topchetoeu.jscript.compilation.values;
|
||||
package me.topchetoeu.j2s.compilation.values;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.ChangeTarget;
|
||||
|
||||
public class VariableNode extends Node implements ChangeTarget {
|
||||
public final String name;
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.topchetoeu.jscript.compilation.values.constants;
|
||||
package me.topchetoeu.j2s.compilation.values.constants;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class BoolNode extends Node {
|
||||
public final boolean value;
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.topchetoeu.jscript.compilation.values.constants;
|
||||
package me.topchetoeu.j2s.compilation.values.constants;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class NullNode extends Node {
|
||||
@Override public void compileFunctions(CompileResult target) {
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation.values.constants;
|
||||
package me.topchetoeu.j2s.compilation.values.constants;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class NumberNode extends Node {
|
||||
public final double value;
|
||||
@@ -23,15 +23,6 @@ public class NumberNode extends Node {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static double power(double a, long b) {
|
||||
if (b == 0) return 1;
|
||||
if (b == 1) return a;
|
||||
if (b < 0) return 1 / power(a, -b);
|
||||
|
||||
if ((b & 1) == 0) return power(a * a, b / 2);
|
||||
else return a * power(a * a, b / 2);
|
||||
}
|
||||
|
||||
public static ParseRes<NumberNode> parse(Source src, int i) {
|
||||
var n = Parsing.skipEmpty(src, i);
|
||||
var loc = src.loc(i + n);
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation.values.constants;
|
||||
package me.topchetoeu.j2s.compilation.values.constants;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class StringNode extends Node {
|
||||
public final String value;
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.SyntaxException;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.AssignTarget;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.SyntaxException;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.AssignTarget;
|
||||
|
||||
public class AssignNode extends Node implements AssignTarget {
|
||||
public final AssignTarget assignable;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class CallNode extends Node {
|
||||
public final Node func;
|
||||
@@ -1,16 +1,16 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
|
||||
|
||||
public class ChangeNode extends Node {
|
||||
public final ChangeTarget changable;
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class DiscardNode extends Node {
|
||||
@@ -1,17 +1,17 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.StringNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Instruction.BreakpointType;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.StringNode;
|
||||
|
||||
public class IndexNode extends Node implements ChangeTarget {
|
||||
public final Node object;
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
public class LazyAndNode extends Node {
|
||||
public final Node first, second;
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
|
||||
|
||||
public class LazyOrNode extends Node {
|
||||
@@ -1,21 +1,21 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.AssignTargetLike;
|
||||
import me.topchetoeu.jscript.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.AssignTargetLike;
|
||||
import me.topchetoeu.j2s.compilation.patterns.ChangeTarget;
|
||||
|
||||
public class OperationNode extends Node {
|
||||
private static interface OperatorFactory {
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.jscript.compilation.values.constants.NumberNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.patterns.ChangeTarget;
|
||||
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
|
||||
|
||||
public class PostfixNode extends ChangeNode {
|
||||
@Override public void compileFunctions(CompileResult target) {
|
||||
@@ -1,15 +1,14 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.common.parsing.ParseRes;
|
||||
import me.topchetoeu.jscript.common.parsing.Parsing;
|
||||
import me.topchetoeu.jscript.common.parsing.Source;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.JavaScript;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.common.parsing.ParseRes;
|
||||
import me.topchetoeu.j2s.common.parsing.Parsing;
|
||||
import me.topchetoeu.j2s.common.parsing.Source;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class TypeofNode extends Node {
|
||||
public final Node value;
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.topchetoeu.jscript.compilation.values.operations;
|
||||
package me.topchetoeu.j2s.compilation.values.operations;
|
||||
|
||||
import me.topchetoeu.jscript.common.Instruction;
|
||||
import me.topchetoeu.jscript.common.Operation;
|
||||
import me.topchetoeu.jscript.common.parsing.Location;
|
||||
import me.topchetoeu.jscript.compilation.CompileResult;
|
||||
import me.topchetoeu.jscript.compilation.FunctionNode;
|
||||
import me.topchetoeu.jscript.compilation.Node;
|
||||
import me.topchetoeu.jscript.compilation.values.VariableNode;
|
||||
import me.topchetoeu.j2s.common.Instruction;
|
||||
import me.topchetoeu.j2s.common.Operation;
|
||||
import me.topchetoeu.j2s.common.parsing.Location;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.FunctionNode;
|
||||
import me.topchetoeu.j2s.compilation.Node;
|
||||
import me.topchetoeu.j2s.compilation.values.VariableNode;
|
||||
|
||||
public class VariableAssignNode extends Node {
|
||||
public final String name;
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.topchetoeu.j2s;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestHelloWorld {
|
||||
|
||||
@Test
|
||||
public void testHelloWorld() {
|
||||
final String message = "Hello World!";
|
||||
assertEquals("Hello World!", message);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
project_group = me.topchetoeu
|
||||
project_name = jscript
|
||||
project_version = 0.10.0-beta
|
||||
main_class = me.topchetoeu.jscript.repl.SimpleRepl
|
||||
project_name = j2s
|
||||
project_version = 0.10.4-beta
|
||||
main_class = me.topchetoeu.j2s.repl.SimpleRepl
|
||||
|
||||
68
lib/build.gradle.kts
Normal file
68
lib/build.gradle.kts
Normal file
@@ -0,0 +1,68 @@
|
||||
import com.github.gradle.node.npm.task.NpmTask;
|
||||
|
||||
plugins {
|
||||
id("common");
|
||||
id("com.github.node-gradle.node") version "5.0.0";
|
||||
}
|
||||
|
||||
tasks.compileJava {
|
||||
enabled = false;
|
||||
}
|
||||
tasks.classes {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
node {
|
||||
version = "20.0.0";
|
||||
npmVersion = "8.0.0";
|
||||
download = true;
|
||||
}
|
||||
|
||||
tasks.register<NpmTask>("compileStdlib") {
|
||||
dependsOn("npmInstall");
|
||||
|
||||
inputs.files("rollup.config.js");
|
||||
inputs.dir("src/stdlib");
|
||||
outputs.files("build/js/stdlib.js");
|
||||
|
||||
args.set(listOf("run", "build-env"));
|
||||
}
|
||||
tasks.register<NpmTask>("compileTranspiler") {
|
||||
dependsOn("npmInstall");
|
||||
|
||||
inputs.files("rollup.config.js");
|
||||
inputs.dir("src/transpiler");
|
||||
outputs.files("build/js/transpiler.js");
|
||||
// nom nom tasty ram
|
||||
environment.put("NODE_OPTIONS", "--max-old-space-size=4096");
|
||||
|
||||
args.set(listOf("run", "build-ts"));
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Main-Class" to properties["main_class"].toString(),
|
||||
"Build-Author" to "TopchetoEU",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
dependsOn("compileStdlib");
|
||||
dependsOn("compileTranspiler");
|
||||
|
||||
from("build/js") {
|
||||
into("lib");
|
||||
}
|
||||
from("src/lib") {
|
||||
into("lib");
|
||||
}
|
||||
|
||||
filesMatching("metadata.json", {
|
||||
expand(
|
||||
"version" to properties["project_version"].toString(),
|
||||
"name" to properties["project_name"].toString(),
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build-env": "rollup -c --environment INPUT:src/lib/libs/_entry.ts,OUTPUT:build/js/index.js,POLYFILLS:src/lib/libs/polyfills",
|
||||
"build-ts": "rollup -c --environment INPUT:src/lib/transpiler/_entry.ts,OUTPUT:build/js/ts.js"
|
||||
"build-env": "rollup -c --environment INPUT:src/stdlib/_entry.ts,OUTPUT:build/js/stdlib.js,POLYFILLS:src/polyfills",
|
||||
"build-ts": "rollup -c --environment INPUT:src/transpiler/_entry.ts,OUTPUT:build/js/transpiler.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.26.0",
|
||||
@@ -7,7 +7,7 @@ const nodeResolve = require("@rollup/plugin-node-resolve");
|
||||
const json = require("@rollup/plugin-json");
|
||||
const { resolve } = require("path");
|
||||
|
||||
const shouldMinify = () => false;
|
||||
const shouldMinify = () => true;
|
||||
const shouldEmitSourcemaps = () => true;
|
||||
const shouldPolyfill = () => !!process.env.POLYFILLS;
|
||||
|
||||
@@ -99,6 +99,7 @@ const construct = (input, output) => defineConfig({
|
||||
shouldMinify() && terser({
|
||||
sourceMap: shouldEmitSourcemaps(),
|
||||
keep_classnames: true,
|
||||
keep_fnames: true,
|
||||
}),
|
||||
],
|
||||
output: {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user