NX01: Cleanup kode gen a little bit of byte rot

This commit is contained in:
Willem Cazander 2026-01-23 11:11:15 +01:00
parent babb2cf188
commit 4af51ad9ae
6 changed files with 191 additions and 136 deletions

View file

@ -0,0 +1,84 @@
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package love.distributedrebirth.nx01.kode.generator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlassWriter;
/// Runs the different kode generators provided for the NX01.
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天
public class KodeGen {
private final static String SERIAL_VERSON_ID = "13";
public static void main(String[] args) throws IOException {
if (skipCommand()) {
System.out.println("SKIPPED: Generated source are up to date");
return;
}
List<String> argu = Arrays.asList(args);
boolean writeToFile = argu.contains("generate");
String commandDesc = null;
KodeGenModel commandKode = null;
if (argu.contains("tones")) {
commandDesc = "nether tones";
commandKode = new ModelNetherTones();
} else {
System.err.println("No command given.");
System.exit(1);
return;
}
// write all sources to files or stdout
System.out.println("Generating " + commandDesc);
ModelKlassWriter writer = new ModelKlassWriter("target/generated-sources");
writer.setProlog(new File("../licence.txt"));
commandKode.buildModels(writer);
writer.printModels(writeToFile);
System.out.println("Done " + commandDesc);
}
private static boolean skipCommand() throws IOException {
Path hashFile = new File("target/generated-sources.hash").toPath();
if (hashFile.toFile().exists()) {
String hash = Files.readString(hashFile);
if (SERIAL_VERSON_ID.equals(hash)) {
return true;
}
}
Files.writeString(hashFile, SERIAL_VERSON_ID);
return false;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package love.distributedrebirth.nx01.kode.generator;
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlassWriter;
/// Configure the model for the writer.
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天
public interface KodeGenModel {
void buildModels(ModelKlassWriter writer);
}

View file

@ -27,13 +27,7 @@
package love.distributedrebirth.nx01.kode.generator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlass;
@ -43,35 +37,10 @@ import love.distributedrebirth.nx01.kode.generator.klass.ModelKlassWriter;
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天
public class GenerateNetherTone {
public class ModelNetherTones implements KodeGenModel {
private final static String SERIAL_VERSON_ID = "11";
public static void main(String[] args) throws IOException {
List<String> argu = Arrays.asList(args);
GenerateNetherTone gen = new GenerateNetherTone();
boolean writeToFile = argu.contains("generate");
if (argu.contains("based")) {
gen.updateBased(writeToFile);
} else {
System.err.println("No command given.");
}
}
private void updateBased(boolean writeToFile) throws IOException {
Path hashFile = new File("target/generated-sources.hash").toPath();
if (hashFile.toFile().exists()) {
String hash = Files.readString(hashFile);
if (SERIAL_VERSON_ID.equals(hash)) {
System.out.println("SKIPPED: Generated source are up to date");
return;
}
}
Files.writeString(hashFile, SERIAL_VERSON_ID);
ModelKlassWriter writer = new ModelKlassWriter("target/generated-sources");
writer.setProlog(new File("../licence.txt"));
@Override
public void buildModels(ModelKlassWriter writer) {
buildQuadrants(writer, 1, "ᐧᐧᐧ");
buildQuadrants(writer, 2, "ᐧᐧᣟ");
buildQuadrants(writer, 3, "ᐧᣟᐧ");
@ -81,59 +50,32 @@ public class GenerateNetherTone {
buildQuadrants(writer, 7, "ᣟᣟᐧ");
buildQuadrants(writer, 8, "ᣟᣟᣟ");
createNetherQuadrant(writer, "NetherTone", "NetherToneQ", false);
// write all sources to files or stdout
writer.write(writeToFile);
buildNetherQuadrant(writer, "NetherTone", "NetherToneQ", false);
}
private void buildQuadrants(ModelKlassWriter writer, int quadrant, String s) {
String q = "ᐊQ" + quadrant;
String e = "NetherToneQ" + quadrant;
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG1", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG1"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG2", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG2"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "AG3", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "AG3"));
buildNetherTreeSlug(writer, s, q + "AG1", 64, e);
buildNetherTreeSlug(writer, s, q + "AG2", 64, e);
buildNetherTreeSlug(writer, s, q + "AG3", 64, e);
buildNetherTreeSlug(writer, s, q + "BL0W", 512, e);
buildNetherTreeSlug(writer, s, q + "CR1", 64, e);
buildNetherTreeSlug(writer, s, q + "CR2", 64, e);
buildNetherTreeSlug(writer, s, q + "CR3", 64, e);
buildNetherTreeSlug(writer, s, q + "DB1", 64, e);
buildNetherTreeSlug(writer, s, q + "DB2", 64, e);
buildNetherTreeSlug(writer, s, q + "DB3", 64, e);
buildNetherTreeSlug(writer, s, q + "ER0W", 512, e);
writer.addModelKlass(buildNetherTreeSlug(s, q + "BL0W", "", 512, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "BL0W"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR1", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR1"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR2", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR2"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "CR3", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "CR3"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB1", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB1"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB2", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB2"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "DB3", "", 64, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "DB3"));
writer.addModelKlass(buildNetherTreeSlug(s, q + "ER0W", "", 512, e));
writer.addModelKlass(buildNetherTreeMutex(s, q + "ER0W"));
createNetherQuadrant(writer, e, q, true); // permits all above
buildNetherQuadrant(writer, e, q, true); // permits all above
}
private ModelKlass buildNetherTreeMutex(String subPackage, String javaName) {
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + subPackage, javaName + "Mutex");
StringBuilder buf = klass.getBody();
buf.append("interface ");
buf.append(klass.getJavaName());
buf.append("<T> {\n");
buf.append("}\n");
return klass;
}
private ModelKlass buildNetherTreeSlug(String subPackage, String javaName, String slugName, int slugSize, String quadrant) {
private void buildNetherTreeSlug(ModelKlassWriter writer, String subPackage, String javaName, int slugSize, String quadrant) {
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + subPackage, javaName);
klass.addJavaImport("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ."+quadrant);
klass.addJavaImport("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + quadrant);
writer.addModelKlass(klass);
StringBuilder buf = klass.getBody();
buf.append("public sealed interface ");
buf.append(klass.getJavaName());
@ -141,16 +83,23 @@ public class GenerateNetherTone {
buf.append(quadrant);
buf.append(" {\n");
for (int i = 1 ; i <= slugSize; i++) {
String partCode = String.format("%03d", i);
String clsBase = slugName + partCode + " extends " + klass.getJavaName();
String clsMutexExt = ", " + javaName + "Mutex<" + slugName + partCode + ">";
buf.append("\tnon-sealed interface "+clsBase+clsMutexExt+" {}\n");
String partCode = "" + String.format("%03d", i);
String clsBase = partCode + " extends " + klass.getJavaName();
String clsMutexExt = ", " + javaName + "Mutex<" + partCode + ">";
buf.append("\tnon-sealed interface " + clsBase + clsMutexExt + " {}\n");
}
buf.append("}\n");
return klass;
ModelKlass klassMutex = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ." + subPackage, javaName + "Mutex");
writer.addModelKlass(klassMutex);
StringBuilder bufMutex = klassMutex.getBody();
bufMutex.append("interface ");
bufMutex.append(klassMutex.getJavaName());
bufMutex.append("<T> {\n");
bufMutex.append("}\n");
}
private void createNetherQuadrant(ModelKlassWriter writer, String javaName, String javaSearch, boolean child) {
private void buildNetherQuadrant(ModelKlassWriter writer, String javaName, String javaSearch, boolean child) {
ModelKlass klass = new ModelKlass("ᒢᐩᐩ.ᑊᑉᒻᣔᔆᔆ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ", javaName);
StringBuilder buf = klass.getBody();
buf.append("public sealed interface ");

View file

@ -63,14 +63,14 @@ public class ModelKlassWriter {
klasses.add(Objects.requireNonNull(klass));
}
public void write(boolean writeFile) throws IOException {
public void printModels(boolean writeFile) throws IOException {
if (writeFile) {
if (!outputPath.toFile().exists()) {
outputPath.toFile().mkdirs();
}
}
for (ModelKlass klass : klasses) {
String content = writeKlass(klass);
String content = printKlass(klass);
if (writeFile) {
Path outFile = outputPath.resolve(klass.getJavaFile().toPath());
outFile.toFile().getParentFile().mkdirs();
@ -84,15 +84,15 @@ public class ModelKlassWriter {
}
}
private String writeKlass(ModelKlass klass) throws IOException {
private String printKlass(ModelKlass klass) throws IOException {
StringBuilder buf = new StringBuilder();
writeKlassProlog(buf);
writeKlassHeader(buf, klass);
printKlassProlog(buf);
printKlassHeader(buf, klass);
buf.append(klass.getBody());
return buf.toString();
}
private void writeKlassProlog(StringBuilder buf) throws IOException {
private void printKlassProlog(StringBuilder buf) throws IOException {
if (prolog == null) {
return;
}
@ -110,7 +110,7 @@ public class ModelKlassWriter {
buf.append("\n");
}
private void writeKlassHeader(StringBuilder buf, ModelKlass klass) throws IOException {
private void printKlassHeader(StringBuilder buf, ModelKlass klass) throws IOException {
buf.append("package ");
buf.append(klass.getJavaPackage());
buf.append(";\n");