moved more things to config, fixed package name typo

This commit is contained in:
Parker TenBroeck 2025-05-05 12:38:11 -04:00
parent a577a825f8
commit 817004672d
18 changed files with 44 additions and 33 deletions

View file

@ -1,12 +1,12 @@
package lexer; package lexer;
import com.parkertenbroeck.generator.Gen; import com.parkertenbroeck.generator.Gen;
import com.parkertenbroeck.bcms.RT; import com.parkertenbroeck.bcsm.RT;
import com.parkertenbroeck.bcms.loadtime.StateMachineClassLoader; import com.parkertenbroeck.bcsm.loadtime.StateMachineClassLoader;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
RT.runWithStateMachines(StateMachineClassLoader.Config.builtin(), (Object) args); RT.runWithStateMachines(StateMachineClassLoader.Config.builtin().write_classes("build/modified/generators/"), (Object) args);
lexer(); lexer();
} }

View file

@ -1,12 +1,12 @@
package sockets; package sockets;
import com.parkertenbroeck.async_runtime.Jokio; import com.parkertenbroeck.async_runtime.Jokio;
import com.parkertenbroeck.bcms.RT; import com.parkertenbroeck.bcsm.RT;
import com.parkertenbroeck.bcms.loadtime.StateMachineClassLoader; import com.parkertenbroeck.bcsm.loadtime.StateMachineClassLoader;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
RT.runWithStateMachines(StateMachineClassLoader.Config.builtin(), (Object) args); RT.runWithStateMachines(StateMachineClassLoader.Config.builtin().write_classes("build/modified/generators/"), (Object) args);
await(); await();
} }

View file

@ -5,7 +5,7 @@ import com.parkertenbroeck.async_runtime.Jokio;
import com.parkertenbroeck.async_runtime.io.net.ServerSocket; import com.parkertenbroeck.async_runtime.io.net.ServerSocket;
import com.parkertenbroeck.async_runtime.io.net.Socket; import com.parkertenbroeck.async_runtime.io.net.Socket;
import com.parkertenbroeck.future.Future; import com.parkertenbroeck.future.Future;
import com.parkertenbroeck.bcms.loadtime.future.Cancellation; import com.parkertenbroeck.bcsm.loadtime.future.Cancellation;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View file

@ -1,7 +1,7 @@
package com.parkertenbroeck.bcms; package com.parkertenbroeck.bcsm;
import com.parkertenbroeck.bcms.loadtime.StateMachineClassLoader; import com.parkertenbroeck.bcsm.loadtime.StateMachineClassLoader;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Set; import java.util.Set;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeBuilder;
import java.lang.classfile.instruction.LineNumber; import java.lang.classfile.instruction.LineNumber;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.*; import java.lang.classfile.*;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.constant.ClassDesc; import java.lang.constant.ClassDesc;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
public enum ReplacementKind { public enum ReplacementKind {
ImmediateReplacingPop, ImmediateReplacingPop,

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeBuilder;
import java.lang.classfile.TypeKind; import java.lang.classfile.TypeKind;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.constant.ClassDesc; import java.lang.constant.ClassDesc;
import java.lang.constant.MethodTypeDesc; import java.lang.constant.MethodTypeDesc;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeBuilder;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeBuilder;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.CodeBuilder; import java.lang.classfile.CodeBuilder;
import java.lang.classfile.Label; import java.lang.classfile.Label;

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import java.lang.classfile.*; import java.lang.classfile.*;
import java.lang.classfile.attribute.InnerClassInfo; import java.lang.classfile.attribute.InnerClassInfo;

View file

@ -1,9 +1,9 @@
package com.parkertenbroeck.bcms.loadtime; package com.parkertenbroeck.bcsm.loadtime;
import com.parkertenbroeck.future.Future; import com.parkertenbroeck.future.Future;
import com.parkertenbroeck.generator.Gen; import com.parkertenbroeck.generator.Gen;
import com.parkertenbroeck.bcms.loadtime.future.FutureSMBuilder; import com.parkertenbroeck.bcsm.loadtime.future.FutureSMBuilder;
import com.parkertenbroeck.bcms.loadtime.gen.GenSMBuilder; import com.parkertenbroeck.bcsm.loadtime.gen.GenSMBuilder;
import java.io.IOException; import java.io.IOException;
import java.lang.classfile.*; import java.lang.classfile.*;
@ -18,6 +18,7 @@ public class StateMachineClassLoader extends ClassLoader {
private final HashMap<String, Class<?>> customClazzMap = new HashMap<>(); private final HashMap<String, Class<?>> customClazzMap = new HashMap<>();
private final List<String> skip; private final List<String> skip;
private final HashMap<ClassDesc, SMBB> builders; private final HashMap<ClassDesc, SMBB> builders;
private final String write_classes_path;
public interface SMBB{ public interface SMBB{
StateMachineBuilder<?> build(ClassModel src_clm, MethodModel src_mem, CodeModel src_com); StateMachineBuilder<?> build(ClassModel src_clm, MethodModel src_mem, CodeModel src_com);
@ -25,13 +26,14 @@ public class StateMachineClassLoader extends ClassLoader {
public static class Config{ public static class Config{
HashSet<String> skip = new HashSet<>(); HashSet<String> skip = new HashSet<>();
HashMap<ClassDesc, SMBB> builders = new HashMap<>(); HashMap<ClassDesc, SMBB> builders = new HashMap<>();
String write_classes;
public static Config empty(){ public static Config empty(){
return new Config(); return new Config();
} }
public static Config builtin(){ public static Config builtin(){
return empty() return empty()
.skip("java", "jdk", "jre", "com.parkertenbroeck.generators.loadtime") .skip("java", "jdk", "jre", "com.parkertenbroeck.bcsm.loadtime")
.with(Future.class, FutureSMBuilder::new) .with(Future.class, FutureSMBuilder::new)
.with(Gen.class, GenSMBuilder::new); .with(Gen.class, GenSMBuilder::new);
} }
@ -50,6 +52,11 @@ public class StateMachineClassLoader extends ClassLoader {
builders.put(ret, builder); builders.put(ret, builder);
return this; return this;
} }
public Config write_classes(String path){
write_classes = path;
return this;
}
} }
public StateMachineClassLoader(ClassLoader parent) { public StateMachineClassLoader(ClassLoader parent) {
@ -60,15 +67,19 @@ public class StateMachineClassLoader extends ClassLoader {
super(parent); super(parent);
skip = config.skip.stream().toList(); skip = config.skip.stream().toList();
builders = new HashMap<>(config.builders); builders = new HashMap<>(config.builders);
write_classes_path = config.write_classes;
} }
void add(String name, byte[] def){ void add(String name, byte[] def){
if(write_classes_path!=null){
try { try {
Files.createDirectories(Path.of("build/modified/generators/" + name.replace(".", "/")).getParent()); Files.createDirectories(Path.of(write_classes_path + name.replace(".", "/")).getParent());
Files.write(Path.of("build/modified/generators/" + name.replace(".", "/") + ".class"), def); Files.write(Path.of(write_classes_path + name.replace(".", "/") + ".class"), def);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}
customClazzMap.put(name, defineClass(name, def, 0, def.length)); customClazzMap.put(name, defineClass(name, def, 0, def.length));
} }

View file

@ -1,4 +1,4 @@
package com.parkertenbroeck.bcms.loadtime.future; package com.parkertenbroeck.bcsm.loadtime.future;
import java.lang.annotation.*; import java.lang.annotation.*;

View file

@ -1,8 +1,8 @@
package com.parkertenbroeck.bcms.loadtime.future; package com.parkertenbroeck.bcsm.loadtime.future;
import com.parkertenbroeck.future.Future; import com.parkertenbroeck.future.Future;
import com.parkertenbroeck.future.Waker; import com.parkertenbroeck.future.Waker;
import com.parkertenbroeck.bcms.loadtime.*; import com.parkertenbroeck.bcsm.loadtime.*;
import java.lang.classfile.*; import java.lang.classfile.*;
import java.lang.classfile.instruction.SwitchCase; import java.lang.classfile.instruction.SwitchCase;

View file

@ -1,7 +1,7 @@
package com.parkertenbroeck.bcms.loadtime.gen; package com.parkertenbroeck.bcsm.loadtime.gen;
import com.parkertenbroeck.generator.Gen; import com.parkertenbroeck.generator.Gen;
import com.parkertenbroeck.bcms.loadtime.*; import com.parkertenbroeck.bcsm.loadtime.*;
import java.lang.classfile.*; import java.lang.classfile.*;
import java.lang.constant.ClassDesc; import java.lang.constant.ClassDesc;