build: split up into multiple projects, use kotlin DLS
All checks were successful
tagged-release / Tagged Release (push) Successful in 5m23s

This commit is contained in:
TopchetoEU 2025-01-10 04:05:17 +02:00
parent 9668bccef1
commit d563fc4919
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
209 changed files with 459 additions and 266 deletions

40
.gitignore vendored
View File

@ -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

View File

@ -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
View 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");
}
}
}
}

View File

@ -0,0 +1,7 @@
repositories {
mavenCentral();
}
plugins {
`kotlin-dsl`
}

View File

@ -0,0 +1,12 @@
plugins {
id("common");
}
java {
sourceCompatibility = JavaVersion.VERSION_17;
targetCompatibility = JavaVersion.VERSION_17;
toolchain {
languageVersion = JavaLanguageVersion.of(17);
}
}

View 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
View 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.json", {
expand(
"version" to properties["project_version"],
"name" to properties["project_name"],
);
});
}
tasks.test {
useJUnitPlatform();
}

View File

@ -1,7 +1,6 @@
package me.topchetoeu.j2s.common.parsing;
import me.topchetoeu.j2s.common.SyntaxException;
import me.topchetoeu.j2s.compilation.values.constants.NumberNode;
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);
}
}

View 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"));
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
project_group = me.topchetoeu
project_name = j2s
project_version = 0.10.3-beta
project_version = 0.10.4-beta
main_class = me.topchetoeu.j2s.repl.SimpleRepl

68
lib/build.gradle.kts Normal file
View 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(),
);
})
}

View File

@ -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",

Some files were not shown because too many files have changed in this diff Show More